test resets the db
This commit is contained in:
parent
0b99982c49
commit
2c0d29f154
5
model.py
5
model.py
@ -24,11 +24,13 @@ class Flock:
|
|||||||
n = 0
|
n = 0
|
||||||
for b in bikes:
|
for b in bikes:
|
||||||
|
|
||||||
|
# next point is determined by the distance travelled since the last update
|
||||||
dt = datetime.datetime.now() - b['last_update']
|
dt = datetime.datetime.now() - b['last_update']
|
||||||
progress = (b['speed'] * dt.seconds) / 1000 # in km
|
progress = (b['speed'] * dt.seconds) / 1000 # in km
|
||||||
point = LatLon(b['point'][1], b['point'][0])
|
point = LatLon(b['point'][1], b['point'][0])
|
||||||
next_point = point.offset(b['bearing'], progress)
|
next_point = point.offset(b['bearing'], progress)
|
||||||
|
|
||||||
|
# collect all speeds, bearings and next points, to find centroid and average speed
|
||||||
speeds.append(b['speed'])
|
speeds.append(b['speed'])
|
||||||
bearings.append(b.get('bearing', 0))
|
bearings.append(b.get('bearing', 0))
|
||||||
lats.append(float(next_point.lat))
|
lats.append(float(next_point.lat))
|
||||||
@ -43,7 +45,6 @@ class Flock:
|
|||||||
if n > 0:
|
if n > 0:
|
||||||
self.size = n
|
self.size = n
|
||||||
self.mean_speed = sum(speeds) / float(len(speeds))
|
self.mean_speed = sum(speeds) / float(len(speeds))
|
||||||
|
|
||||||
|
|
||||||
self.centroid = LatLon(Latitude(sum(lats) / len(lats)),
|
self.centroid = LatLon(Latitude(sum(lats) / len(lats)),
|
||||||
Longitude(sum(lons) / len(lons)))
|
Longitude(sum(lons) / len(lons)))
|
||||||
|
|||||||
@ -15,6 +15,15 @@ points = [
|
|||||||
|
|
||||||
bikes = []
|
bikes = []
|
||||||
|
|
||||||
|
from pymongo import MongoClient
|
||||||
|
|
||||||
|
client = MongoClient()
|
||||||
|
db = client.test
|
||||||
|
col = db["bike"]
|
||||||
|
d = col.delete_many({})
|
||||||
|
print(d)
|
||||||
|
|
||||||
|
|
||||||
def flip(coord):
|
def flip(coord):
|
||||||
return (coord[1], coord[0])
|
return (coord[1], coord[0])
|
||||||
|
|
||||||
@ -96,32 +105,33 @@ def test_update():
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
# def test_flock_forward():
|
def test_flock_forward():
|
||||||
# """
|
"""
|
||||||
# Bike 1 is closely followed by 2. Bike 1 updates at t=0, bike 2
|
Bike 1 is closely followed by 2. Bike 1 updates at t=0, bike 2
|
||||||
# twenty seconds later.
|
twenty seconds later.
|
||||||
|
|
||||||
# test for proper distances, flock heading, dest heading, etc.
|
test for proper distances, flock heading, dest heading, etc.
|
||||||
# """
|
"""
|
||||||
# global b1, b2
|
global bikes
|
||||||
|
|
||||||
# #
|
#
|
||||||
# t0 = LatLon(*a)
|
t0 = LatLon(*points[0])
|
||||||
# t1 = t0.offset(90, 1)
|
t1 = t0.offset(45, 1)
|
||||||
|
|
||||||
# b1.update(
|
bikes[0].update(
|
||||||
# {'speed': 3,
|
{'speed': 3,
|
||||||
# 'bearing': t0.heading_initial(t1),
|
'bearing': t0.heading_initial(t1),
|
||||||
# 'lat': t1.lat,
|
'lat': t1.lat,
|
||||||
# 'lon': t1.lon,
|
'lon': t1.lon,
|
||||||
# })
|
})
|
||||||
|
|
||||||
# b1.server_update()
|
bikes[0].server_update()
|
||||||
|
|
||||||
# print(b1)
|
print(bikes)
|
||||||
# #b2.server_update(lat, lon, speed, bearing)
|
|
||||||
|
#b2.server_update(lat, lon, speed, bearing)
|
||||||
|
|
||||||
# assert True
|
assert True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user