fix: smooth GPS-derived replay speed to kill jitter spikes
route_points (Pi) and get_trip_route (server) derived GPS speed from a single 5s segment, so GPS position jitter could read 150+ km/h when the car wasn't going that fast. Both now average over a trailing ~30s window (same as the max-speed calc), so spikes are damped.
This commit is contained in:
+22
-6
@@ -285,12 +285,28 @@ def route_points(raw_rows, max_points=2000, odometer_baseline=0.0, prior_km=0.0)
|
||||
for index, row in enumerate(rows):
|
||||
row["speed_source"] = "obd" if row["speed"] > 0 else "gps"
|
||||
if row["speed"] <= 0 and index:
|
||||
distance_km, segment_speed = _segment(row, rows[index - 1])
|
||||
row["speed"] = (
|
||||
segment_speed
|
||||
if distance_km * 1000 >= GPS_MOTION_METERS
|
||||
else 0
|
||||
)
|
||||
# Derive GPS speed over a trailing ~30s window, not the raw 5s
|
||||
# segment — a single segment can spike 100+ km/h on GPS jitter
|
||||
# (same smoothing build_trip_summaries uses for max speed).
|
||||
window_start = max(0, index - GPS_SPEED_WINDOW)
|
||||
start_row = rows[window_start]
|
||||
seconds = (
|
||||
row["datetime"] - start_row["datetime"]
|
||||
).total_seconds()
|
||||
if seconds > 0:
|
||||
window_km = haversine_km(
|
||||
(start_row["latitude"], start_row["longitude"]),
|
||||
(row["latitude"], row["longitude"]),
|
||||
)
|
||||
window_speed = window_km / seconds * 3600
|
||||
row["speed"] = (
|
||||
window_speed
|
||||
if window_km * 1000 >= GPS_MOTION_METERS
|
||||
and window_speed <= MAX_PLAUSIBLE_SPEED_KMH
|
||||
else 0
|
||||
)
|
||||
else:
|
||||
row["speed"] = 0
|
||||
if index:
|
||||
segment_km, _ = _segment(row, rows[index - 1])
|
||||
cumulative_km += segment_km
|
||||
|
||||
Reference in New Issue
Block a user