project/shved-SCRUM-110-hole-deleting #36
@@ -4,6 +4,8 @@ from datetime import datetime
|
||||
import websockets
|
||||
from kivy import Logger
|
||||
from pydantic import BaseModel, field_validator
|
||||
from websockets.asyncio.connection import Connection
|
||||
|
||||
from config import STORE_HOST, STORE_PORT
|
||||
|
||||
|
||||
@@ -33,6 +35,7 @@ class ProcessedAgentData(BaseModel):
|
||||
|
||||
class Datasource:
|
||||
def __init__(self, user_id: int):
|
||||
self.websocket: Connection | None = None
|
||||
self.index = 0
|
||||
self.user_id = user_id
|
||||
self.connection_status = None
|
||||
@@ -52,6 +55,7 @@ class Datasource:
|
||||
Logger.debug("CONNECT TO SERVER")
|
||||
async with websockets.connect(uri) as websocket:
|
||||
self.connection_status = "Connected"
|
||||
self.websocket = websocket
|
||||
try:
|
||||
while True:
|
||||
data = await websocket.recv()
|
||||
@@ -61,6 +65,11 @@ class Datasource:
|
||||
self.connection_status = "Disconnected"
|
||||
Logger.debug("SERVER DISCONNECT")
|
||||
|
||||
async def update_db_records(self):
|
||||
if self.websocket:
|
||||
data = json.dumps({"id": self.user_id})
|
||||
await self.websocket.send(data, True)
|
||||
|
||||
def map_lat_lon_to_processed_agent_data(self, lat: float, lon: float) -> ProcessedAgentData | None:
|
||||
distances = tuple((abs(lon - marker.latitude) ** 2 + abs(lat - marker.longitude) ** 2) ** 0.5 for marker in
|
||||
self._active_markers)
|
||||
|
||||
@@ -162,6 +162,8 @@ class MapViewApp(App):
|
||||
elif clicked_marker in self.bump_markers:
|
||||
self.bump_markers.pop(self.bump_markers.index(clicked_marker))
|
||||
|
||||
self.datasource.update_db_records()
|
||||
|
||||
def on_touch_down(self, widget, touch):
|
||||
if touch.button == "right":
|
||||
coordinate = self.mapview.get_latlon_at(touch.x, touch.y, self.mapview.zoom)
|
||||
|
||||
Reference in New Issue
Block a user