This commit is contained in:
2026-06-16 10:36:18 +03:00
parent c5805eaa5c
commit 0571291b69
15 changed files with 447 additions and 105 deletions
+23 -9
View File
@@ -88,14 +88,27 @@ def record_telemetry(data: TelemetryIn) -> dict[str, Any]:
ts = data.ts if data.ts is not None else time.time()
lat, lon = _sanitize_coords(data.lat, data.lon)
with _db() as conn:
conn.execute(
"""
INSERT INTO devices (device_id, label, last_seen)
VALUES (?, ?, ?)
ON CONFLICT(device_id) DO UPDATE SET last_seen = excluded.last_seen
""",
(data.device_id, data.device_id, ts),
)
phone_label = (data.device_label or "").strip()
if phone_label:
conn.execute(
"""
INSERT INTO devices (device_id, label, last_seen)
VALUES (?, ?, ?)
ON CONFLICT(device_id) DO UPDATE SET
last_seen = excluded.last_seen,
label = excluded.label
""",
(data.device_id, phone_label, ts),
)
else:
conn.execute(
"""
INSERT INTO devices (device_id, label, last_seen)
VALUES (?, ?, ?)
ON CONFLICT(device_id) DO UPDATE SET last_seen = excluded.last_seen
""",
(data.device_id, data.device_id, ts),
)
conn.execute(
"""
INSERT INTO telemetry
@@ -138,7 +151,7 @@ def list_devices() -> list[dict[str, Any]]:
with _db() as conn:
rows = conn.execute(
"""
SELECT d.device_id, d.last_seen,
SELECT d.device_id, d.label, d.last_seen,
t.lat, t.lon, t.rssi, t.range_m, t.raw_frame, t.meta, t.role, t.ts, t.source
FROM devices d
INNER JOIN telemetry t ON t.id = (
@@ -164,6 +177,7 @@ def _is_null_island(device: dict[str, Any]) -> bool:
def _row_to_device(row: sqlite3.Row) -> dict[str, Any]:
return {
"device_id": row["device_id"],
"label": row["label"] if "label" in row.keys() else None,
"last_seen": row["last_seen"],
"lat": row["lat"],
"lon": row["lon"],