-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunctions.py
More file actions
34 lines (28 loc) · 952 Bytes
/
functions.py
File metadata and controls
34 lines (28 loc) · 952 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import simplejson as json
import numpy as np
def get_demand_types(dfile = 'demand_types.json'):
with open(dfile) as df:
dt = json.loads(df.read())
return dt
def get_business_types(bfile = 'business_types.json'):
with open(bfile) as bf:
bt = json.loads(bf.read())
return bt
def generate_person_name():
# Returns a random name for a person
return "Dmo"
def generate_business_name():
# Returns a random name for a business
return "Dmo's Chicken and Waffles"
def distance(loc1, loc2):
# returns distance between two location tuples
return np.sqrt((loc1[0] - loc2[0]) ** 2 + (loc1[1] - loc2[1]) ** 2)
def inside(loc1, loc2, radius):
# returns boolean: is loc2 within radius distance of loc1?
if loc2[0] - loc1[0] > radius or loc2[0] - loc1[0] < -radius:
return False
if loc2[1] - loc1[1] > radius or loc2[1] - loc1[1] < -radius:
return False
if distance(loc1, loc2) < radius:
return True
return False