Compare commits
1 Commits
project/sh
...
805b2658d4
| Author | SHA1 | Date | |
|---|---|---|---|
| 805b2658d4 |
@@ -14,11 +14,24 @@ line_layer_colors = [
|
||||
[1, 0, 1, 1],
|
||||
]
|
||||
|
||||
|
||||
def get_lat_lon(point: dict[str, float] | list[float] | tuple[float, float]) -> tuple[float, float] | None:
|
||||
if isinstance(point, dict):
|
||||
lat = point.get("lat")
|
||||
lon = point.get("lon")
|
||||
else:
|
||||
lat, lon = point
|
||||
|
||||
if lat is None or lon is None:
|
||||
return None
|
||||
return lat, lon
|
||||
|
||||
|
||||
class MapViewApp(App):
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
|
||||
self.mapview = None
|
||||
self.mapview: MapView | None = None
|
||||
self.datasource = Datasource(user_id=1)
|
||||
self.line_layers = dict()
|
||||
self.car_markers = dict()
|
||||
@@ -110,24 +123,34 @@ class MapViewApp(App):
|
||||
self.pothole_markers.append(marker)
|
||||
|
||||
def set_bump_marker(self, point):
|
||||
if isinstance(point, dict):
|
||||
lat = point.get("lat")
|
||||
lon = point.get("lon")
|
||||
else:
|
||||
lat, lon = point
|
||||
|
||||
lat, lon = get_lat_lon(point)
|
||||
if lat is None or lon is None:
|
||||
return
|
||||
|
||||
|
||||
marker = MapMarker(
|
||||
lat=lat,
|
||||
lon=lon,
|
||||
source="images/bump.png"
|
||||
source="images/bump.png"
|
||||
)
|
||||
|
||||
self.mapview.add_marker(marker)
|
||||
self.bump_markers.append(marker)
|
||||
|
||||
def delete_bump_marker(self, point):
|
||||
lat, lon = get_lat_lon(point)
|
||||
if lat is None or lon is None:
|
||||
return
|
||||
|
||||
marker = MapMarker(
|
||||
lat=lat,
|
||||
lon=lon,
|
||||
source="images/bump.png"
|
||||
)
|
||||
|
||||
if marker in self.bump_markers:
|
||||
self.mapview.remove_marker(marker)
|
||||
self.bump_markers.pop(self.bump_markers.index(marker))
|
||||
|
||||
|
||||
def build(self):
|
||||
"""
|
||||
|
||||
@@ -16,8 +16,6 @@ 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)
|
||||
@@ -31,14 +29,13 @@ def publish(client, topic, datasource):
|
||||
data = datasource.read()
|
||||
msg = AggregatedDataSchema().dumps(data)
|
||||
result = client.publish(topic, msg)
|
||||
logging.debug(f"Published to {topic}: {msg[:50]}...")
|
||||
logging.info(f"Published to {topic}: {msg[:50]}...")
|
||||
status = result[0]
|
||||
if status != 0:
|
||||
logging.error(f"Failed to send message to topic {topic}")
|
||||
print(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
|
||||
|
||||
Reference in New Issue
Block a user