Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ae69bd601e | |||
| 2b8d042306 | |||
| 5ab16fec72 | |||
| d633926a1a |
@@ -1,13 +0,0 @@
|
|||||||
print('lat,lon')
|
|
||||||
|
|
||||||
try:
|
|
||||||
while True:
|
|
||||||
i = input()
|
|
||||||
|
|
||||||
if '<trkpt' not in i:
|
|
||||||
continue
|
|
||||||
|
|
||||||
si = i.split('"')[1::2]
|
|
||||||
print(f"{si[0]},{si[1]}")
|
|
||||||
except EOFError:
|
|
||||||
pass
|
|
||||||
+1
-1
@@ -148,7 +148,7 @@ services:
|
|||||||
MQTT_BROKER_HOST: "mqtt"
|
MQTT_BROKER_HOST: "mqtt"
|
||||||
MQTT_BROKER_PORT: 1883
|
MQTT_BROKER_PORT: 1883
|
||||||
MQTT_TOPIC: "processed_data_topic"
|
MQTT_TOPIC: "processed_data_topic"
|
||||||
BATCH_SIZE: 4
|
BATCH_SIZE: 20
|
||||||
ports:
|
ports:
|
||||||
- "9000:8000"
|
- "9000:8000"
|
||||||
networks:
|
networks:
|
||||||
|
|||||||
@@ -7,6 +7,5 @@ CREATE TABLE processed_agent_data (
|
|||||||
z FLOAT,
|
z FLOAT,
|
||||||
latitude FLOAT,
|
latitude FLOAT,
|
||||||
longitude FLOAT,
|
longitude FLOAT,
|
||||||
timestamp TIMESTAMP,
|
timestamp TIMESTAMP
|
||||||
visible BOOLEAN
|
);
|
||||||
);
|
|
||||||
+3
-23
@@ -8,13 +8,12 @@ from sqlalchemy import (
|
|||||||
Integer,
|
Integer,
|
||||||
String,
|
String,
|
||||||
Float,
|
Float,
|
||||||
Boolean,
|
|
||||||
DateTime,
|
DateTime,
|
||||||
)
|
)
|
||||||
from sqlalchemy.sql import select
|
from sqlalchemy.sql import select
|
||||||
|
|
||||||
from database import metadata, SessionLocal
|
from database import metadata, SessionLocal
|
||||||
from schemas import ProcessedAgentData, ProcessedAgentDataInDB, WebSocketData
|
from schemas import ProcessedAgentData, ProcessedAgentDataInDB
|
||||||
|
|
||||||
# FastAPI app setup
|
# FastAPI app setup
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
@@ -31,7 +30,6 @@ processed_agent_data = Table(
|
|||||||
Column("latitude", Float),
|
Column("latitude", Float),
|
||||||
Column("longitude", Float),
|
Column("longitude", Float),
|
||||||
Column("timestamp", DateTime),
|
Column("timestamp", DateTime),
|
||||||
Column("visible", Boolean),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# WebSocket subscriptions
|
# WebSocket subscriptions
|
||||||
@@ -47,7 +45,7 @@ async def websocket_endpoint(websocket: WebSocket, user_id: int):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
# send already available data
|
# send already available data
|
||||||
r = processed_agent_data.select().order_by(processed_agent_data.c.timestamp)
|
r = processed_agent_data.select()
|
||||||
stored_data = SessionLocal().execute(r).fetchall()
|
stored_data = SessionLocal().execute(r).fetchall()
|
||||||
|
|
||||||
jsonable_data = [{c.name: getattr(i, c.name) for c in processed_agent_data.columns} for i in stored_data]
|
jsonable_data = [{c.name: getattr(i, c.name) for c in processed_agent_data.columns} for i in stored_data]
|
||||||
@@ -59,24 +57,7 @@ async def websocket_endpoint(websocket: WebSocket, user_id: int):
|
|||||||
|
|
||||||
# receive forever
|
# receive forever
|
||||||
while True:
|
while True:
|
||||||
data = await websocket.receive_text()
|
await websocket.receive_text()
|
||||||
try:
|
|
||||||
if (data):
|
|
||||||
ws_data = WebSocketData.model_validate(json.loads(data))
|
|
||||||
session = SessionLocal()
|
|
||||||
update_query = (
|
|
||||||
processed_agent_data.update()
|
|
||||||
.where(processed_agent_data.c.id == ws_data.id)
|
|
||||||
.values(visible=False)
|
|
||||||
).returning(processed_agent_data)
|
|
||||||
res = session.execute(update_query).fetchone()
|
|
||||||
if (not res):
|
|
||||||
session.rollback()
|
|
||||||
raise Exception("Error while websocket PUT")
|
|
||||||
session.commit()
|
|
||||||
finally:
|
|
||||||
session.close()
|
|
||||||
|
|
||||||
except WebSocketDisconnect:
|
except WebSocketDisconnect:
|
||||||
subscriptions.remove(websocket)
|
subscriptions.remove(websocket)
|
||||||
|
|
||||||
@@ -100,7 +81,6 @@ def ProcessedAgentData_to_td(data: List[ProcessedAgentData]):
|
|||||||
"latitude": item.agent_data.gps.latitude,
|
"latitude": item.agent_data.gps.latitude,
|
||||||
"longitude": item.agent_data.gps.longitude,
|
"longitude": item.agent_data.gps.longitude,
|
||||||
"timestamp": item.agent_data.timestamp,
|
"timestamp": item.agent_data.timestamp,
|
||||||
"visible": True,
|
|
||||||
}
|
}
|
||||||
for item in data
|
for item in data
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -49,7 +49,3 @@ class AgentData(BaseModel):
|
|||||||
class ProcessedAgentData(BaseModel):
|
class ProcessedAgentData(BaseModel):
|
||||||
road_state: str
|
road_state: str
|
||||||
agent_data: AgentData
|
agent_data: AgentData
|
||||||
|
|
||||||
class WebSocketData(BaseModel):
|
|
||||||
id: int
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user