Compare commits
1 Commits
92c91c2594
...
project/sh
| Author | SHA1 | Date | |
|---|---|---|---|
| 77d6968297 |
@@ -72,8 +72,8 @@ class Datasource:
|
||||
)
|
||||
new_points = [
|
||||
(
|
||||
processed_agent_data.latitude,
|
||||
processed_agent_data.longitude,
|
||||
processed_agent_data.latitude,
|
||||
processed_agent_data.road_state,
|
||||
processed_agent_data.user_id
|
||||
)
|
||||
|
||||
@@ -87,7 +87,8 @@ class MapViewApp(App):
|
||||
self.car_markers[user_id].lat = lat
|
||||
self.car_markers[user_id].lon = lon
|
||||
|
||||
self.mapview.center_on(lat, lon)
|
||||
if user_id == 1:
|
||||
self.mapview.center_on(lat, lon)
|
||||
|
||||
def set_pothole_marker(self, point):
|
||||
if isinstance(point, dict):
|
||||
|
||||
@@ -7,6 +7,5 @@ CREATE TABLE processed_agent_data (
|
||||
z FLOAT,
|
||||
latitude FLOAT,
|
||||
longitude FLOAT,
|
||||
timestamp TIMESTAMP,
|
||||
visible BOOLEAN
|
||||
);
|
||||
timestamp TIMESTAMP
|
||||
);
|
||||
@@ -8,13 +8,12 @@ from sqlalchemy import (
|
||||
Integer,
|
||||
String,
|
||||
Float,
|
||||
Boolean,
|
||||
DateTime,
|
||||
)
|
||||
from sqlalchemy.sql import select
|
||||
|
||||
from database import metadata, SessionLocal
|
||||
from schemas import ProcessedAgentData, ProcessedAgentDataInDB, WebSocketData
|
||||
from schemas import ProcessedAgentData, ProcessedAgentDataInDB
|
||||
|
||||
# FastAPI app setup
|
||||
app = FastAPI()
|
||||
@@ -31,7 +30,6 @@ processed_agent_data = Table(
|
||||
Column("latitude", Float),
|
||||
Column("longitude", Float),
|
||||
Column("timestamp", DateTime),
|
||||
Column("visible", Boolean),
|
||||
)
|
||||
|
||||
# WebSocket subscriptions
|
||||
@@ -59,24 +57,7 @@ async def websocket_endpoint(websocket: WebSocket, user_id: int):
|
||||
|
||||
# receive forever
|
||||
while True:
|
||||
data = 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()
|
||||
|
||||
await websocket.receive_text()
|
||||
except WebSocketDisconnect:
|
||||
subscriptions.remove(websocket)
|
||||
|
||||
@@ -100,7 +81,6 @@ def ProcessedAgentData_to_td(data: List[ProcessedAgentData]):
|
||||
"latitude": item.agent_data.gps.latitude,
|
||||
"longitude": item.agent_data.gps.longitude,
|
||||
"timestamp": item.agent_data.timestamp,
|
||||
"visible": True,
|
||||
}
|
||||
for item in data
|
||||
]
|
||||
|
||||
@@ -49,7 +49,3 @@ class AgentData(BaseModel):
|
||||
class ProcessedAgentData(BaseModel):
|
||||
road_state: str
|
||||
agent_data: AgentData
|
||||
|
||||
class WebSocketData(BaseModel):
|
||||
id: int
|
||||
|
||||
|
||||
Reference in New Issue
Block a user