From 8f8c03a26a261e34ebe64ce434b7a1ea07250fa9 Mon Sep 17 00:00:00 2001 From: Mathieu Moran Date: Mon, 10 Aug 2026 05:58:22 -0400 Subject: [PATCH] fix: server odometer stat shows 0 when no odometer data exists MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit COALESCE(MAX(odometer), 0) returned 0 when all tracking rows have NULL odometer (expected before the car is connected — PID 0xA6 likely unsupported on 2013 Yaris). Now returns NULL which the overview JS renders as '—'. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- server/modules/db.py | 4 ++-- server/templates/index.html | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/server/modules/db.py b/server/modules/db.py index d117510..d149be4 100644 --- a/server/modules/db.py +++ b/server/modules/db.py @@ -379,7 +379,7 @@ 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 COALESCE(MAX(odometer), 0) FROM tracking_points WHERE device_id = %s) AS odometer_km + (SELECT MAX(odometer) FROM tracking_points WHERE device_id = %s AND odometer IS NOT NULL) AS odometer_km """, (device_id,) * 6, ) @@ -390,5 +390,5 @@ def get_overview_stats(device_id): "total_drive_time_s": int(r[2]), "top_speed_kmh": float(r[3]), "video_count": r[4], - "odometer_km": float(r[5]), + "odometer_km": float(r[5]) if r[5] is not None else None, } diff --git a/server/templates/index.html b/server/templates/index.html index e4d6f0b..996bbfe 100644 --- a/server/templates/index.html +++ b/server/templates/index.html @@ -142,7 +142,7 @@ async function loadStats() { document.getElementById('stat-drivetime').textContent = fmtDuration(d.total_drive_time_s); document.getElementById('stat-topspeed').textContent = d.top_speed_kmh.toFixed(0); document.getElementById('stat-videos').textContent = d.video_count; - document.getElementById('stat-odometer').textContent = d.odometer_km.toFixed(0); + document.getElementById('stat-odometer').textContent = d.odometer_km != null ? d.odometer_km.toFixed(0) : '—'; } async function loadRecentTrips() {