@@ -6,6 +6,7 @@
import numpy as np
import googlemaps
from datetime import datetime
from scipy import spatial
class Node :
def __init__ (self , location , does_exist ):
@@ -34,33 +35,22 @@ def calculate_desireability(self):
# self.feature_average_rack_distance = self.get_average_rack_distance()
def get_nearby_accidents (self ):
# """Gets nearby accidents"""
# """Earth Radius 6371 km"""
# xcord_self = (6371*1000)*math.cos((self.location[0]*2*math.pi)/float(360))
# ycord_self = (6371*1000)*math.sin((self.location[1]*2*math.pi)/float(360))
# threshold = 256 # the size of a block in manhattan
# """ stored as (long,lat,injured,killed) """
#
# accident_points = []
# #accident_results = []
# accident_points = util.get_AccidentCords() if (len(util.get_AccidentCords())!=0) else util.set_Accidents()
# #accident_results = util.AccidentResults
#
# cords_self = np.array([xcord_self,ycord_self])
#
# result = 0
# dist = 0
# for i in range(0,len(accident_points)):
# dist = np.linalg.norm(cords_self-accident_points[i])
# print dist
# if dist<-2343250:
#
# result = result + accident_results[i]
#
# return result
pass
"""Gets nearby accidents"""
threshold = 0.000042 # the size of a 2block in manhattan in change of degrees
if (len (util .Util ().AccidentResults ) == 0 ):
util .Util ().set_Accidents ()
accident_points = util .Util ().AccidentCords
accident_results = util .Util ().AccidentResults
result = 0
point = (self .location [0 ],self .location [1 ])
hits = accident_points .query_ball_point (point , 0.000042 , 2 )
for val in hits :
result += int (accident_results [val ])
return result
def get_nearby_venues (self ):
"""Gets nearby venues within a 100 meter radius"""
@@ -87,37 +77,43 @@ def get_biking_popularity(self):
def get_nearby_transportation (self ):
"""Gets the nearby transportation (bus stop, subway, etc.)"""
if len (util .Util ().Subways ) == 0 :
"""Gets the nearby transportation (bus stop, subway, etc.)
Note that i am using 0.0042 intead of 0.000042
"""
if not isinstance (util .Util ().Subways , spatial .ckdtree .cKDTree ):
util .Util ().set_Subways ()
print util .Util ().Subways is util .Util ().Subways
# subways = util.Subways if (len(util.Subways) != 0) else util.set_Subways()
# print subways
# xcord_self = (6371*1000)*math.cos((self.location[0]*2*math.pi)/float(360))
# ycord_self = (6371*1000)*math.sin((self.location[1]*2*math.pi)/float(360))
# pt = np.array([xcord_self, ycord_self])
#
# def distances(a):
# return np.linalg.norm(a-pt)
#
# vfunc = np.vectorize(distances)
# # print(distances(subways[0], np.array([xcord_self, ycord_self])))
# data = np.array([np.linalg.norm(a-pt) for a in subways])
# print(data[:10])
# ans = np.where( data < 100 )
# print(len(data))
# return 1
pass
if not isinstance (util .Util ().Busses , spatial .ckdtree .cKDTree ):
util .Util ().set_Busses ()
pt = [self .location [0 ], self .location [1 ]]
subways = util .Util ().Subways
transit = len (subways .query_ball_point (pt , 0.0042 , 2 ))
busses = util .Util ().Busses
transit += len (busses .query_ball_point (pt , 0.0042 , 2 ))
return transit
def get_average_rack_distance (self ):
"""Gets the average distance to closest 4 racks"""
if not isinstance (util .Util ().Existing_Nodes , spatial .ckdtree .cKDTree ):
util .Util ().set_Exisiting_Nodes ()
pt = [self .location [0 ], self .location [1 ]]
existing_nodes = util .Util ().Existing_Nodes
neightboring_nodes = existing_nodes .query (pt , k = 4 )
return sum (neightboring_nodes [0 ])
if __name__ == '__main__' :
n = Node ((- 73.9808623 , 40.7587442 ), True )
print n .get_nearby_accidents ()
print n .get_nearby_venues ()
print n .get_pedestrian_flow ()
print n .get_nearby_transportation ()
print n .get_biking_popularity ()
print n .get_average_rack_distance ()
# if __name__ == '__main__':
# n = Node((-73.9808623, 40.7587442), True)
# print n.get_nearby_accidents()
# print n.get_nearby_venues()
# print n.get_pedestrian_flow()
# print n.get_nearby_transportation()
# print n.get_biking_popularity()
# print n.get_average_rack_distance()