test resets the db

This commit is contained in:
rgarcia-herrera 2020-09-14 14:20:56 -05:00
parent 0b99982c49
commit 2c0d29f154
2 changed files with 33 additions and 22 deletions

View File

@ -24,11 +24,13 @@ class Flock:
n = 0
for b in bikes:
# next point is determined by the distance travelled since the last update
dt = datetime.datetime.now() - b['last_update']
progress = (b['speed'] * dt.seconds) / 1000 # in km
point = LatLon(b['point'][1], b['point'][0])
next_point = point.offset(b['bearing'], progress)
# collect all speeds, bearings and next points, to find centroid and average speed
speeds.append(b['speed'])
bearings.append(b.get('bearing', 0))
lats.append(float(next_point.lat))
@ -44,7 +46,6 @@ class Flock:
self.size = n
self.mean_speed = sum(speeds) / float(len(speeds))
self.centroid = LatLon(Latitude(sum(lats) / len(lats)),
Longitude(sum(lons) / len(lons)))

View File

@ -15,6 +15,15 @@ points = [
bikes = []
from pymongo import MongoClient
client = MongoClient()
db = client.test
col = db["bike"]
d = col.delete_many({})
print(d)
def flip(coord):
return (coord[1], coord[0])
@ -96,32 +105,33 @@ def test_update():
# def test_flock_forward():
# """
# Bike 1 is closely followed by 2. Bike 1 updates at t=0, bike 2
# twenty seconds later.
def test_flock_forward():
"""
Bike 1 is closely followed by 2. Bike 1 updates at t=0, bike 2
twenty seconds later.
# test for proper distances, flock heading, dest heading, etc.
# """
# global b1, b2
test for proper distances, flock heading, dest heading, etc.
"""
global bikes
# #
# t0 = LatLon(*a)
# t1 = t0.offset(90, 1)
#
t0 = LatLon(*points[0])
t1 = t0.offset(45, 1)
# b1.update(
# {'speed': 3,
# 'bearing': t0.heading_initial(t1),
# 'lat': t1.lat,
# 'lon': t1.lon,
# })
bikes[0].update(
{'speed': 3,
'bearing': t0.heading_initial(t1),
'lat': t1.lat,
'lon': t1.lon,
})
# b1.server_update()
bikes[0].server_update()
# print(b1)
# #b2.server_update(lat, lon, speed, bearing)
print(bikes)
# assert True
#b2.server_update(lat, lon, speed, bearing)
assert True