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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user