Compare commits
5 Commits
92c91c2594
...
project/sh
| Author | SHA1 | Date | |
|---|---|---|---|
| 119547d288 | |||
| b58167f0de | |||
| 121bd007b3 | |||
| db63eb6d79 | |||
| 77d6968297 |
@@ -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')
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
@@ -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,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 == config.TRACK_ID:
|
||||
self.mapview.center_on(lat, lon)
|
||||
|
||||
def set_pothole_marker(self, point):
|
||||
if isinstance(point, dict):
|
||||
|
||||
@@ -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,13 +31,14 @@ 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
|
||||
|
||||
@@ -45,7 +45,7 @@ async def websocket_endpoint(websocket: WebSocket, user_id: int):
|
||||
|
||||
try:
|
||||
# send already available data
|
||||
r = processed_agent_data.select()
|
||||
r = processed_agent_data.select().order_by(processed_agent_data.c.timestamp)
|
||||
stored_data = SessionLocal().execute(r).fetchall()
|
||||
|
||||
jsonable_data = [{c.name: getattr(i, c.name) for c in processed_agent_data.columns} for i in stored_data]
|
||||
@@ -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:
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import sys
|
||||
import os
|
||||
|
||||
print("Checking for dead containers...")
|
||||
|
||||
@@ -14,6 +15,9 @@ for i in statuses:
|
||||
if not i[status_index:].startswith("Up "):
|
||||
service_name = i[name_index:]
|
||||
print(f"Crash detected in {service_name}")
|
||||
print(f"docker logs for the container:\n")
|
||||
os.system(f"docker logs {i.split(' ')[0]}")
|
||||
print()
|
||||
exit_code = 1
|
||||
|
||||
sys.exit(exit_code)
|
||||
|
||||
Reference in New Issue
Block a user