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

View File

@ -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})

View File

@ -1,10 +1,17 @@
[
{
"id": "1",
"location": [16.315283, 48.190331]
"location": [16.0, 48.0],
"range": 2000
},
{
"id": "2",
"location": [16.316331, 48.192382]
"location": [16.0, 48.1],
"range": 800
},
{
"id": "3",
"location": [16.0, 48.2],
"range": 1000
}
]