returning flock centroid lat-lon, let client compute the rest
This commit is contained in:
parent
c56f6fe0a8
commit
c7ec3c7b3a
16
model.py
16
model.py
@ -41,11 +41,11 @@ class Flock:
|
||||
self.mean_speed = 0
|
||||
self.size = 0
|
||||
self.centroid = None
|
||||
|
||||
|
||||
if n > 0:
|
||||
self.size = n
|
||||
self.mean_speed = sum(speeds) / float(len(speeds))
|
||||
|
||||
|
||||
self.centroid = LatLon(Latitude(sum(lats) / len(lats)),
|
||||
Longitude(sum(lons) / len(lons)))
|
||||
|
||||
@ -67,7 +67,7 @@ class Bike(Document):
|
||||
self.bearing = bearing
|
||||
self.last_update = datetime.datetime.now()
|
||||
self.save()
|
||||
|
||||
|
||||
def heading_to(self, target):
|
||||
s = LatLon(Latitude(self.point[1]),
|
||||
Longitude(self.point[0]))
|
||||
@ -137,15 +137,11 @@ class Bike(Document):
|
||||
:return: heading from point to flock centroid, in degrees
|
||||
"""
|
||||
flock = Flock(self.find_flock())
|
||||
if flock.size > 0:
|
||||
flock_heading = self.heading_to(flock.centroid)
|
||||
if flock.size > 0:
|
||||
flock_lat = float(flock.centroid.lat)
|
||||
flock_lon = float(flock.centroid.lon)
|
||||
flock_distance = distance.geodesic((self.point[1],
|
||||
self.point[0]), (self.destination[1],
|
||||
self.destination[0])).meters
|
||||
return {'flock_heading': flock_heading,
|
||||
'flock_lat': flock_lat,
|
||||
|
||||
return {'flock_lat': flock_lat,
|
||||
'flock_lon': flock_lon,
|
||||
'flock_avg_speed': flock.mean_speed,
|
||||
'flock_size': flock.size}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user