Skip to content

Very Late #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions analytics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import math
import sys
import os


from .. import point
from .. import utils

def find_largest_city(gj):
city = None
max_population = 0

for i in gj['features']:
if i['properties']['pop_max'] > max_population:
max_population = i['properties']['pop_max']
city = i['properties']['name']

return city, max_population


def mean_center(points):
x = 0
y = 0

for i in points:
x += i[0]
y += i[1]

x /= len(points)
y /= len(points)

return x, y


def average_nearest_neighbor_distance(points):

mean_d = 0
nearest_neighbor = math.inf

for p in points:
for otherPoint in points:
if point.check_coincident(p, otherPoint):
continue
current_distance = utils.euclidean_distance(p, otherPoint)
if nearest_neighbor is None:
nearest_neighbor = current_distance
elif nearest_neighbor > current_distance:
nearest_neighbor = current_distance

mean_d += nearest_neighbor
nearest_neighbor = None

mean_d /= len(points)

return mean_d


def minimum_bounding_rectangle(points):

mbr = [0, 0, 0, 0]
x_min = 0
x_max = 0
y_min = 0
y_max = 0

for p in points:
if p[0] < x_min:
x_min = p[0]
if p[0] > x_max:
x_max = p[0]
if p[1] < y_min:
y_min = p[1]
if p[1] > y_max:
y_max = p[1]
mbr = [x_min, y_min, x_max, y_max]

return mbr


def mbr_area(mbr):

l = mbr[2] - mbr[0]
w = mbr[3] - mbr[1]
area = l * w

return area


def expected_distance(area, n):

expected = 0.5 * (math.sqrt(area / n))

return expected


def compute_critical(points):

lower = min(points)
upper = max(points)

return lower, upper


def check_significant(lower, upper, observed):

if (lower < observed) or (observed < upper):
result = True
else:
result = False

return result


def permutation(p=99, n=100):

perm = []
for x in range(p):
perm.append(average_nearest_neighbor_distance(utils.create_random_points(n)))

return perm
10 changes: 10 additions & 0 deletions io_geojson.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import json


def read_geojson(input_file):

with open(input_file, 'r') as f:
gj = json.load(f)

return gj

27 changes: 27 additions & 0 deletions point.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import utils
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a class, e.g.

class Point(object):
    def __init__(self,x,y):
        #Logic Here


sys.path.insert(0, os.path.abspath('..'))


def __init__(self, x, y, mark=[]):
self.x = x
self.y = y
self.mark = mark


def __str__(self):
return "[0], [1]".format(self.x, self.y)


def check_coincident(a, b):
return a == b


def shift_point(point, x_shift, y_shift):
x = utils.getx(point)
y = utils.gety(point)

x += x_shift
y += y_shift

return x, y
42 changes: 42 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import math
import random


def create_random_points(n):
rand = random.seed()
random_points = [(rand.randint(0, 100), rand.randint(0, 100))]
return random_points


def create_random_marked_points(n, marks=[]):
rand_mp = random.seed()
rand_pts = []
if marks is None:
for i in range(n):
rand_pts.append(rand_mp.randint(0, 100), rand_mp.randint(0,100), rand_mp.choice(marks))
else:
for i in range(n):
rand_pts.append(rand_mp.randint(0, 100), rand_mp.randint(0,100), rand_mp.choice(marks))
return rand_pts


def euclidean_distance(a, b):
distance = math.sqrt((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2)
return distance


def manhattan_distance(a, b):
distance = abs(a[0] - b[0]) + abs(a[1] - b[1])
return distance


def check_in(points, point_list):
return points in point_list


def getx(points):
return points[0]


def gety(points):
return points[1]