fix: BUG-22 smooth GPS-derived speeds in trip max (trailing window)

This commit is contained in:
Mathieu Moran
2026-08-14 23:00:53 -04:00
parent d9314969d8
commit a0be96dfaa
2 changed files with 36 additions and 8 deletions
+10 -7
View File
@@ -461,13 +461,16 @@ def compute_trips_for_device(device_id):
speeds.append(s)
max_speeds.append(s)
else:
# GPS-derived fallback for max (mirror the Pi): when OBD speed
# is missing, use the segment's GPS speed (>= 8 m, <= 220 km/h).
seconds = (seg_rows[i][0] - seg_rows[i - 1][0]).total_seconds()
if seconds > 0 and d * 1000 >= 8:
seg_speed = d / seconds * 3600
if seg_speed <= 220:
max_speeds.append(seg_speed)
# GPS-derived fallback for max (mirror the Pi, but smoothed over
# a trailing ~30s window so GPS position jitter can't spike the max).
j = max(0, i - 6)
w_dt = (seg_rows[i][0] - seg_rows[j][0]).total_seconds()
w_d = haversine_km(seg_rows[j][1], seg_rows[j][2],
seg_rows[i][1], seg_rows[i][2])
if w_dt > 0 and w_d * 1000 >= 8:
w_speed = w_d / w_dt * 3600
if w_speed <= 220:
max_speeds.append(w_speed)
duration_s = int((seg_rows[-1][0] - seg_rows[0][0]).total_seconds())
if duration_s < 30 or distance < 0.05: