fix distance calculation

This commit is contained in:
Davide Scaini
2026-03-29 10:50:31 +02:00
parent 643d092acd
commit fa4e91b645
+5 -1
View File
@@ -130,7 +130,11 @@ def _gps_stats(
if not has_data: if not has_data:
return device_dist, None, None, None return device_dist, None, None, None
distance_m = device_dist if device_dist is not None else round(total_dist_m, 1) # Fall back to haversine distance if device recorded 0 but we computed real GPS distance
if device_dist is not None and device_dist > 0:
distance_m = device_dist
else:
distance_m = round(total_dist_m, 1) if total_dist_m > 0 else device_dist
moving_time_s = moving_s if moving_s > 0 else None moving_time_s = moving_s if moving_s > 0 else None
avg_speed_kmh = (moving_dist_m / moving_s) * 3.6 if moving_s > 0 else None avg_speed_kmh = (moving_dist_m / moving_s) * 3.6 if moving_s > 0 else None
# Prefer device speed for max (more stable than GPS-derived per-second spikes) # Prefer device speed for max (more stable than GPS-derived per-second spikes)