fix: use total trip distance as odometer fallback when PID 0xA6 unavailable

If no real odometer data exists (all NULL — expected on 2013 Yaris which
likely doesn't support PID 0xA6), fall back to SUM(distance_km) from the
computed trips table so the overview shows something meaningful.

Co-authored-by: Copilot <[email protected]>
This commit is contained in:
Mathieu Moran
2026-08-10 05:59:53 -04:00
co-authored by Copilot
parent 8f8c03a26a
commit 0cd798ee19
+5 -2
View File
@@ -379,9 +379,12 @@ def get_overview_stats(device_id):
(SELECT COALESCE(SUM(duration_s), 0) FROM trips WHERE device_id = %s) AS total_s, (SELECT COALESCE(SUM(duration_s), 0) FROM trips WHERE device_id = %s) AS total_s,
(SELECT COALESCE(MAX(max_speed_kmh), 0) FROM trips WHERE device_id = %s) AS top_speed, (SELECT COALESCE(MAX(max_speed_kmh), 0) FROM trips WHERE device_id = %s) AS top_speed,
(SELECT COUNT(*) FROM dashcam_files WHERE device_id = %s) AS video_count, (SELECT COUNT(*) FROM dashcam_files WHERE device_id = %s) AS video_count,
(SELECT MAX(odometer) FROM tracking_points WHERE device_id = %s AND odometer IS NOT NULL) AS odometer_km COALESCE(
(SELECT MAX(odometer) FROM tracking_points WHERE device_id = %s AND odometer IS NOT NULL),
(SELECT SUM(distance_km) FROM trips WHERE device_id = %s)
) AS odometer_km
""", """,
(device_id,) * 6, (device_id,) * 7,
) )
r = cur.fetchone() r = cur.fetchone()
return { return {