use speed of agent to filter age of db records
This commit is contained in:
parent
c7ec3c7b3a
commit
9feeb9c3d4
@ -43,4 +43,9 @@ server, using the following commands:
|
|||||||
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
|
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
|
||||||
|
|
||||||
|
|
||||||
|
## Instance at LANCIS
|
||||||
|
|
||||||
|
We're hosting an instance of this server at
|
||||||
|
|
||||||
|
http://flock.apps.lancis.ecologia.unam.mx/
|
||||||
|
|
||||||
|
|||||||
24
model.py
24
model.py
@ -9,8 +9,6 @@ from LatLon23 import LatLon, Latitude, Longitude
|
|||||||
from geopy import distance
|
from geopy import distance
|
||||||
|
|
||||||
|
|
||||||
# TODO: instead of centroid use speed and bearing of flockers to create a vector, point rider towards it
|
|
||||||
# use time elapsed since last update, speed vector and current point to compute future location
|
|
||||||
class Flock:
|
class Flock:
|
||||||
"""
|
"""
|
||||||
Flock object is created from a list of agents
|
Flock object is created from a list of agents
|
||||||
@ -92,17 +90,28 @@ class Bike(Document):
|
|||||||
return (self.destination[1],
|
return (self.destination[1],
|
||||||
self.destination[0])
|
self.destination[0])
|
||||||
|
|
||||||
def find_flock(self, point_altruism=0.1, dest_altruism=0.2):
|
def find_flock(self,
|
||||||
|
point_altruism=0.1,
|
||||||
|
dest_altruism=0.2,
|
||||||
|
min_age=None):
|
||||||
"""
|
"""
|
||||||
|
min_age of agents in database, in seconds
|
||||||
:return: list of Bike objects
|
:return: list of Bike objects
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
if min_age is None:
|
||||||
|
min_step = 100 # update at least every 100 meters
|
||||||
|
if self.speed > 0:
|
||||||
|
min_age = min_step / self.speed
|
||||||
|
else:
|
||||||
|
min_age = 60
|
||||||
|
|
||||||
trip_len = distance.geodesic(self.get_point(), self.get_dest()).meters
|
trip_len = distance.geodesic(self.get_point(), self.get_dest()).meters
|
||||||
|
|
||||||
local_radius = trip_len * point_altruism
|
local_radius = trip_len * point_altruism
|
||||||
destination_radius = trip_len * dest_altruism
|
destination_radius = trip_len * dest_altruism
|
||||||
|
|
||||||
# these are bikes around me
|
# these are bikes recently known to be around me
|
||||||
local = [bike for bike in
|
local = [bike for bike in
|
||||||
self.db.bike.find(
|
self.db.bike.find(
|
||||||
{'point': {
|
{'point': {
|
||||||
@ -112,7 +121,7 @@ class Bike(Document):
|
|||||||
'coordinates': self.point},
|
'coordinates': self.point},
|
||||||
'$maxDistance': local_radius}},
|
'$maxDistance': local_radius}},
|
||||||
'last_update': {
|
'last_update': {
|
||||||
'$gte': datetime.datetime.now() - datetime.timedelta(minutes=15)}, # TODO: adjust this
|
'$gte': datetime.datetime.now() - datetime.timedelta(seconds=min_age)},
|
||||||
'_id': {'$ne': bson.objectid.ObjectId(self.id)}})]
|
'_id': {'$ne': bson.objectid.ObjectId(self.id)}})]
|
||||||
|
|
||||||
local_ids = set([bike['_id'] for bike in local])
|
local_ids = set([bike['_id'] for bike in local])
|
||||||
@ -124,7 +133,10 @@ class Bike(Document):
|
|||||||
{'$near':
|
{'$near':
|
||||||
{'$geometry': {'type': 'Point',
|
{'$geometry': {'type': 'Point',
|
||||||
'coordinates': self.destination},
|
'coordinates': self.destination},
|
||||||
'$maxDistance': destination_radius}}})]
|
'$maxDistance': destination_radius}},
|
||||||
|
'last_update': {
|
||||||
|
'$gte': datetime.datetime.now() - datetime.timedelta(seconds=min_age)}
|
||||||
|
})]
|
||||||
remote_ids = set([bike['_id'] for bike in remote])
|
remote_ids = set([bike['_id'] for bike in remote])
|
||||||
|
|
||||||
# intersect them!
|
# intersect them!
|
||||||
|
|||||||
@ -37,6 +37,10 @@ def update(bike_id):
|
|||||||
speed = float(request.args.get('speed', None))
|
speed = float(request.args.get('speed', None))
|
||||||
bearing = float(request.args.get('bearing', None))
|
bearing = float(request.args.get('bearing', None))
|
||||||
|
|
||||||
|
local_altruism = float(request.args.get('local_altruism', 0.1))
|
||||||
|
dest_altruism = float(request.args.get('dest_altruism', 0.2))
|
||||||
|
|
||||||
|
|
||||||
bike.update(lat, lon, speed, bearing)
|
bike.update(lat, lon, speed, bearing)
|
||||||
|
|
||||||
return jsonify(
|
return jsonify(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user