[P] Improve marker removal architecture to allow for future extensions

This commit is contained in:
2026-03-26 21:11:02 +02:00
committed by rhinemann
parent 79a58f1737
commit abbc703b1b
2 changed files with 40 additions and 12 deletions

View File

@@ -37,6 +37,7 @@ class Datasource:
self.user_id = user_id
self.connection_status = None
self._new_points = []
self._active_markers = []
asyncio.ensure_future(self.connect_to_server())
def get_new_points(self):
@@ -60,6 +61,20 @@ class Datasource:
self.connection_status = "Disconnected"
Logger.debug("SERVER DISCONNECT")
def map_lat_lon_to_ProcessedAgentData(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)
if len(distances) == 0:
return None
min_distance = min(distances)
marker = self._active_markers[distances.index(min_distance)]
if min_distance < 0.005:
return marker
else:
return None
def handle_received_data(self, data):
# Update your UI or perform actions with received data here
Logger.debug(f"Received data: {data}")
@@ -70,6 +85,9 @@ class Datasource:
],
key=lambda v: v.timestamp,
)
self._active_markers += [i for i in processed_agent_data_list if i.road_state != 'normal']
new_points = [
(
processed_agent_data.longitude,