Compare commits

...

5 Commits

Author SHA1 Message Date
hasslesstech bc0977588e [P] Add second agent in docker-compose.yaml
Component testing / Hub testing (push) Successful in 21s
Component testing / Store testing (push) Successful in 22s
Component testing / Integration smoke testing (push) Has been cancelled
2026-03-25 22:34:50 +02:00
hasslesstech 3d2b02c0c6 [P] Add GPS file selection to agent 2026-03-25 22:34:50 +02:00
hasslesstech e3b27bbd4c [P] Add TRACK_ID selection in MapView
Component testing / Hub testing (push) Successful in 27s
Component testing / Store testing (push) Successful in 24s
Component testing / Integration smoke testing (push) Failing after 14s
2026-03-25 22:34:15 +02:00
hasslesstech 987e968dd4 [P] Fix wrong row sending order
Component testing / Hub testing (push) Successful in 27s
Component testing / Store testing (push) Successful in 29s
Component testing / Integration smoke testing (push) Successful in 2m33s
2026-03-25 22:27:40 +02:00
hasslesstech db63eb6d79 [P] Improve logging logic in agent
Component testing / Hub testing (push) Successful in 24s
Component testing / Store testing (push) Successful in 27s
Component testing / Integration smoke testing (push) Successful in 2m25s
2026-03-25 15:40:07 +02:00
6 changed files with 34 additions and 12 deletions
+2
View File
@@ -2,3 +2,5 @@ import os
STORE_HOST = os.environ.get("STORE_HOST") or "localhost"
STORE_PORT = os.environ.get("STORE_PORT") or 8000
TRACK_ID = int(os.environ.get("TID") or '1')
+2 -1
View File
@@ -4,6 +4,7 @@ from kivy_garden.mapview import MapMarker, MapView
from kivy.clock import Clock
from lineMapLayer import LineMapLayer
from datasource import Datasource
import config
line_layer_colors = [
[1, 0, 0, 1],
@@ -87,7 +88,7 @@ class MapViewApp(App):
self.car_markers[user_id].lat = lat
self.car_markers[user_id].lon = lon
if user_id == 1:
if user_id == config.TRACK_ID:
self.mapview.center_on(lat, lon)
def set_pothole_marker(self, point):
+3 -4
View File
@@ -1,18 +1,17 @@
import os
def try_parse(type, value: str):
try:
return type(value)
except Exception:
return None
USER_ID = try_parse(int, os.environ.get("USER_ID")) or 1
# MQTT config
MQTT_BROKER_HOST = os.environ.get("MQTT_BROKER_HOST") or "mqtt"
MQTT_BROKER_PORT = try_parse(int, os.environ.get("MQTT_BROKER_PORT")) or 1883
MQTT_TOPIC = os.environ.get("MQTT_TOPIC") or "agent"
# Delay for sending data to mqtt in seconds
# Data-related config
USER_ID = try_parse(int, os.environ.get("USER_ID")) or 1
DELAY = try_parse(float, os.environ.get("DELAY")) or 1
GPS_SOURCE = os.environ.get("GPS_SOURCE") or "data/gps.csv"
+6 -3
View File
@@ -16,6 +16,8 @@ def connect_mqtt(broker, port):
print("Failed to connect {broker}:{port}, return code %d\n", rc)
exit(rc) # Stop execution
logging.info(f"Acting as USER_ID = {config.USER_ID}")
client = mqtt_client.Client()
client.on_connect = on_connect
client.connect(broker, port)
@@ -29,17 +31,18 @@ def publish(client, topic, datasource):
data = datasource.read()
msg = AggregatedDataSchema().dumps(data)
result = client.publish(topic, msg)
logging.info(f"Published to {topic}: {msg[:50]}...")
logging.debug(f"Published to {topic}: {msg[:50]}...")
status = result[0]
if status != 0:
print(f"Failed to send message to topic {topic}")
logging.error(f"Failed to send message to topic {topic}")
def run():
logging.basicConfig(level = logging.INFO)
# Prepare mqtt client
client = connect_mqtt(config.MQTT_BROKER_HOST, config.MQTT_BROKER_PORT)
# Prepare datasource
datasource = FileDatasource(16384.0, "data/accelerometer.csv", "data/gps.csv", "data/parking.csv")
datasource = FileDatasource(16384.0, "data/accelerometer.csv", config.GPS_SOURCE, "data/parking.csv")
# Infinity publish data
publish(client, config.MQTT_TOPIC, datasource)
+20 -3
View File
@@ -14,8 +14,7 @@ services:
mqtt_network:
fake_agent:
container_name: agent
agent1:
build:
context: .
dockerfile: agent/Dockerfile
@@ -26,7 +25,25 @@ services:
MQTT_BROKER_HOST: "mqtt"
MQTT_BROKER_PORT: 1883
MQTT_TOPIC: "agent_data_topic"
DELAY: 0.1
DELAY: 1.2
USER_ID: 2
networks:
mqtt_network:
agent2:
build:
context: .
dockerfile: agent/Dockerfile
depends_on:
- mqtt
environment:
PYTHONUNBUFFERED: 1
MQTT_BROKER_HOST: "mqtt"
MQTT_BROKER_PORT: 1883
MQTT_TOPIC: "agent_data_topic"
GPS_SOURCE: "data/route2.csv"
DELAY: 1.0
USER_ID: 3
networks:
mqtt_network:
+1 -1
View File
@@ -96,7 +96,7 @@ async def create_processed_agent_data(data: List[ProcessedAgentData], user_id: i
created_records = [dict(row._mapping) for row in result.fetchall()]
session.commit()
for record in created_records:
for record in sorted(created_records, key = lambda x: x['timestamp']):
await send_data_to_subscribers(jsonable_encoder(record))
return created_records
except Exception as err: