Compare commits

...

8 Commits

Author SHA1 Message Date
2164003482 [P] Integrate additional store testing into CI pipeline
Some checks failed
Component testing / Hub testing (push) Successful in 25s
Component testing / Store testing (push) Successful in 45s
Component testing / Integration smoke testing (push) Failing after 11m40s
2026-03-27 20:19:34 +02:00
57a370ad69 [P] Remove trailing spaces
Some checks failed
Component testing / Hub testing (push) Successful in 22s
Component testing / Store testing (push) Successful in 24s
Component testing / Integration smoke testing (push) Has been cancelled
2026-03-27 19:51:27 +02:00
b2b8906478 [P] Remove uncessecary empty line 2026-03-27 19:49:18 +02:00
8a59f601c4 [P] Send only visible records from store on websocket connection 2026-03-27 19:49:18 +02:00
dc3e9b3e7a [P] Remove user_id from store <-> mapview interaction, fix update_db_record 2026-03-27 19:49:18 +02:00
0182d20348 [P] Sync the async function 2026-03-27 19:49:18 +02:00
adae93aba4 [P] Add database update after marker deletion. 2026-03-27 19:49:18 +02:00
2c4526d0ec [P] Code cleanup. 2026-03-27 19:49:18 +02:00
6 changed files with 39 additions and 16 deletions

View File

@@ -28,18 +28,27 @@ jobs:
- name: Clone repository
run: git clone --revision ${{ gitea.sha }} --depth 1 ${{ gitea.server_url }}/${{ gitea.repository }}
- name: Start postgres_db container for testing
working-directory: IoT-Systems
run: docker-compose up -d postgres_db
- name: Build Store testing container
working-directory: IoT-Systems
run: docker build -t local/store/${{gitea.sha}} -f store/Dockerfile-test .
- name: Run Store tests
working-directory: IoT-Systems
run: docker run --rm -it local/store/${{gitea.sha}}
run: docker run --network host --rm -it local/store/${{gitea.sha}}
- name: Clean up containers
if: ${{always()}}
run: docker image rm local/store/${{gitea.sha}}
- name: Clean up docker-compose
if: ${{always()}}
working-directory: IoT-Systems
run: docker-compose down -v --remove-orphans
integration-smoke-test:
name: Integration smoke testing
runs-on: host-arch-x86_64

View File

@@ -9,6 +9,7 @@ from config import STORE_HOST, STORE_PORT
# Pydantic models
class ProcessedAgentData(BaseModel):
id: int
road_state: str
user_id: int
x: float
@@ -32,9 +33,9 @@ class ProcessedAgentData(BaseModel):
class Datasource:
def __init__(self, user_id: int):
def __init__(self):
self.websocket: Connection | None = None
self.index = 0
self.user_id = user_id
self.connection_status = None
self._new_points = []
self._active_markers = []
@@ -47,11 +48,12 @@ class Datasource:
return points
async def connect_to_server(self):
uri = f"ws://{STORE_HOST}:{STORE_PORT}/ws/{self.user_id}"
uri = f"ws://{STORE_HOST}:{STORE_PORT}/ws"
while True:
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,8 +63,14 @@ 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)
def update_db_record_visibility(self, record_id):
if self.websocket:
data = json.dumps({"id": record_id})
asyncio.ensure_future(self.websocket.send(data))
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)
if len(distances) == 0:
return None

View File

@@ -33,7 +33,7 @@ class MapViewApp(App):
super().__init__(**kwargs)
self.mapview: MapView | None = None
self.datasource = Datasource(user_id=1)
self.datasource = Datasource()
self.line_layers = dict()
self.car_markers = dict()
@@ -109,7 +109,7 @@ class MapViewApp(App):
try:
return next(flt)
except StopIteration as e:
except StopIteration:
return None
def set_pothole_marker(self, point):
@@ -145,14 +145,14 @@ class MapViewApp(App):
if lat is None or lon is None:
return
clicked_marker_data = self.datasource.map_lat_lon_to_ProcessedAgentData(lat, lon)
clicked_marker_data = self.datasource.map_lat_lon_to_processed_agent_data(lat, lon)
if not clicked_marker_data:
return
clicked_marker = self.map_lat_lon_to_marker(clicked_marker_data.latitude, clicked_marker_data.longitude)
if clicked_marker == None:
if clicked_marker is None:
return
self.mapview.remove_marker(clicked_marker)
@@ -162,13 +162,14 @@ class MapViewApp(App):
elif clicked_marker in self.bump_markers:
self.bump_markers.pop(self.bump_markers.index(clicked_marker))
self.datasource.update_db_record_visibility(clicked_marker_data.id)
def on_touch_down(self, widget, touch):
if touch.button == "right":
coordinate = self.mapview.get_latlon_at(touch.x, touch.y, self.mapview.zoom)
self.delete_pothole_marker(coordinate)
return True
def build(self):
"""
Ініціалізує мапу MapView(zoom, lat, lon)

View File

@@ -6,6 +6,7 @@ WORKDIR /app
COPY store/requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
RUN pip install --root-user-action ignore --no-cache-dir pytest httpx
# Copy the entire application into the container
COPY store/. .
# Run the main.py script inside the container when it starts

View File

@@ -39,15 +39,18 @@ subscriptions: Set[WebSocket] = set()
# FastAPI WebSocket endpoint
@app.websocket("/ws/{user_id}")
async def websocket_endpoint(websocket: WebSocket, user_id: int):
@app.websocket("/ws")
async def websocket_endpoint(websocket: WebSocket):
await websocket.accept()
subscriptions.add(websocket)
try:
# send already available data
r = processed_agent_data.select().order_by(processed_agent_data.c.timestamp)
r = processed_agent_data.select() \
.where(processed_agent_data.c.visible == True) \
.order_by(processed_agent_data.c.timestamp)
session = SessionLocal()
stored_data = session.execute(r).fetchall()
session.close()

View File

@@ -1,3 +1,4 @@
#!/bin/sh
PYTHONPATH=$PWD python3 test/main_test.py
PYTHONPATH=$PWD python3 -m pytest test_db.py