From 0cd798ee1931d3c07b6969dcf9cc928b745da2f6 Mon Sep 17 00:00:00 2001 From: Mathieu Moran Date: Mon, 10 Aug 2026 05:59:53 -0400 Subject: [PATCH] fix: use total trip distance as odometer fallback when PID 0xA6 unavailable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 <223556219+Copilot@users.noreply.github.com> --- server/modules/db.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/server/modules/db.py b/server/modules/db.py index d149be4..092747d 100644 --- a/server/modules/db.py +++ b/server/modules/db.py @@ -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(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 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() return {