fix: server odometer stat shows 0 when no odometer data exists
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 <[email protected]>
This commit is contained in:
@@ -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(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 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,
|
(device_id,) * 6,
|
||||||
)
|
)
|
||||||
@@ -390,5 +390,5 @@ def get_overview_stats(device_id):
|
|||||||
"total_drive_time_s": int(r[2]),
|
"total_drive_time_s": int(r[2]),
|
||||||
"top_speed_kmh": float(r[3]),
|
"top_speed_kmh": float(r[3]),
|
||||||
"video_count": r[4],
|
"video_count": r[4],
|
||||||
"odometer_km": float(r[5]),
|
"odometer_km": float(r[5]) if r[5] is not None else None,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ async function loadStats() {
|
|||||||
document.getElementById('stat-drivetime').textContent = fmtDuration(d.total_drive_time_s);
|
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-topspeed').textContent = d.top_speed_kmh.toFixed(0);
|
||||||
document.getElementById('stat-videos').textContent = d.video_count;
|
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() {
|
async function loadRecentTrips() {
|
||||||
|
|||||||
Reference in New Issue
Block a user