Add traffic light range to entity

This commit is contained in:
David Eder
2021-05-25 19:38:59 +02:00
parent 2514ba60e8
commit c76bbdc42f
2 changed files with 26 additions and 11 deletions
@@ -40,19 +40,27 @@ def get_traffic_lights_geo():
lat = float(query_parameters.get('lat'))
lon = float(query_parameters.get('lon'))
distance = float(query_parameters.get('distance'))
traffic_lights = [
traffic_light for traffic_light in
mongo.db.trafficLights.find({'location': {
'$near': {
'$geometry': {
'type': "Point",
'coordinates': [lon, lat]
mongo.db.trafficLights.aggregate([
{"$geoNear": {
"near": {
"type": "Point",
"coordinates": [lon, lat]
},
'$maxDistance': distance
}
}})
"spherical": True,
"distanceField": "calculatedRange"
}},
{"$redact": {
"$cond": {
"if": {"$lte": ["$calculatedRange", "$range"]},
"then": "$$KEEP",
"else": "$$PRUNE"
}
}}
]
)
]
return json_util.dumps({'cursor': traffic_lights})