fix: Pi trip builder drops GPS lock-in drift trips (BUG-23)
Add the server's minimum-trip filter to build_trip_summaries() — duration < 30s OR distance < 0.05km is rejected — so GPS lock-in drift no longer spawns false trips on the Pi. Also sort normalized rows by datetime (the server already orders by recorded_at ASC), fixing clock-rollback trip boundaries. Bump TRIP_BUILD_VERSION to force a Pi-side rebuild.
This commit is contained in:
+1
-1
@@ -25,7 +25,7 @@ IDLE_LOG_INTERVAL = 60
|
||||
GPS_LOG_DISTANCE_METERS = 8
|
||||
TRIP_REFRESH_INTERVAL = 30
|
||||
TRIP_REBUILD_OVERLAP_ROWS = 120
|
||||
TRIP_BUILD_VERSION = 3
|
||||
TRIP_BUILD_VERSION = 4
|
||||
|
||||
_conn = None
|
||||
_conn_lock = Lock()
|
||||
|
||||
+9
-1
@@ -62,6 +62,10 @@ def normalize_tracking_rows(rows):
|
||||
"speed": max(0, speed),
|
||||
"odometer": odometer,
|
||||
})
|
||||
# The server reads tracking_points with ORDER BY recorded_at ASC — sort the
|
||||
# same way here so a clock rollback (BUG-17, pre-RTC) can't make a trip's
|
||||
# start/end span a backwards time jump.
|
||||
normalized.sort(key=lambda item: item["datetime"])
|
||||
return normalized
|
||||
|
||||
|
||||
@@ -220,7 +224,11 @@ def build_trip_summaries(raw_rows):
|
||||
duration_seconds = max(
|
||||
0, int((end["datetime"] - start["datetime"]).total_seconds())
|
||||
)
|
||||
if not any(event["obd"] for event in events) and duration_seconds < 10:
|
||||
# Match the server's minimum-trip filter (server/modules/db.py):
|
||||
# duration < 30s OR distance < 0.05km means the "trip" was GPS lock-in
|
||||
# drift or a sub-50m shuffle — the car wasn't actually moving, so skip
|
||||
# it. Keeps the Pi's trip count in lockstep with the server's.
|
||||
if duration_seconds < 30 or distance_km < 0.05:
|
||||
continue
|
||||
|
||||
# Speed-only rows (logged before the first GPS fix) have NULL coords.
|
||||
|
||||
Reference in New Issue
Block a user