Skip to content

Commit

Permalink
fix getting data from es
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-f committed Sep 1, 2023
1 parent 8f0a044 commit 83daf2b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
17 changes: 14 additions & 3 deletions services/ansible_openvpn/docker/dashboard/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,23 @@

@app.get("/api/sensor_position")
async def get_sensor_position(request: Request):
post_data = templates.get_template("query_sensor_list.json").render()
resp = client.search(index="sensor_location_*", query=post_data)
return resp
post_data = json.loads(
templates.get_template("query_sensor_list.json").render())
resp = client.search(**post_data)
# reformat elastic search result
return [{"hwa": hit["fields"]["hwa"][0], "date": hit["fields"]["date"][0],
"lat": hit["fields"]["TPV.lat"][0],
"lon": hit["fields"]["TPV.lon"][0]}
for bucket in resp["aggregations"]["group"]["buckets"] for hit in
bucket["group_docs"]["hits"]["hits"]]


@app.get('/', response_class=HTMLResponse)
async def home(request: Request):
return templates.TemplateResponse("status.html",
context={"request": request})


if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000, reload=True)
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"index": "sensor_location_*",
"size": 0,
"fields": [
"TPV.lat",
Expand Down
2 changes: 2 additions & 0 deletions services/ansible_openvpn/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ services:
context: dashboard
ports:
- '8000:80'
environment:
WATCHFILES_FORCE_POLLING: true
volumes:
- dashboard_website:/home/dashboard:ro
autoconfig:
Expand Down

0 comments on commit 83daf2b

Please sign in to comment.