GPS Trip Detection, History & Playback #23
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Trip Detection, History & Playback
Problem
Solution
Pre-compute trips from GPS data, store them in the database, and build a rich trip history UI with playback.
Phase 1: Database & Trip Detection Engine
Schema: New
GpsTripmodelid,deviceId,driverIdstartTime,endTimestartLatitude,startLongitude,endLatitude,endLongitudedistanceMiles(OSRM road distance, pre-computed)durationMinutesrouteGeometry(JSON - pre-computed OSRM coordinates for instant display)confidence(OSRM match confidence)pointCount(number of GPS points in trip)status:ACTIVE|COMPLETED|MERGEDmergedIntoId(for consolidated trips)createdAt,updatedAtTrip Detection Cron Job (runs every 2 minutes)
GpsTriprecord with start/end times and locationsCOMPLETEDTrip Consolidation Endpoint
POST /gps/trips/merge- merge multiple trip IDs into onestatustoMERGEDon child trips, recalculates distance/duration on parentPhase 2: Backend API Endpoints
Trip CRUD
GET /gps/trips?driverId=X&from=DATE&to=DATE- list trips with filtersGET /gps/trips/:tripId- single trip with full route geometryGET /gps/trips/active?driverId=X- get currently active trip (for live map)POST /gps/trips/merge- consolidate tripsGET /gps/trips/summary?driverId=X&from=DATE&to=DATE- aggregate stats (total miles, trips, driving time)Key design: route geometry is PRE-COMPUTED and stored in the trip record.
No more on-the-fly OSRM calls when viewing trips = instant load.
Phase 3: Live Map Cleanup
Current behavior: Shows all GPS history as one continuous trail
New behavior:
/gps/trips/active)Phase 4: Driver Statistics Overhaul
Trip List Side Panel
Trip Map
Phase 5: Trip Playback
Playback Controls (on the Stats map)
Implementation: Animate a marker along the pre-computed route coordinates using requestAnimationFrame, interpolating between points based on playback speed.
Implementation Order
Each phase is independently deployable and testable.
Implemented in
cc3375e. All 5 phases complete:Backend:
Frontend:
Deployed to production - trip detection already working live.
positions.txt Here was a recent trip. But the
perhaps we need to reimagine how the trips are begun and ended, we can't have that many trips to consolidate, there has to be an easy way to decide what a 'trip' is. I don't know why it made so many. See if you can fix this so it does not have SOOO many trips when it was obviously 1. trip there and 1 trip back.
Fixed trip detection algorithm:
Cleared all bad trips, redeployed. Use Backfill button in Stats tab to regenerate.
Simplified: Now using Traccar built-in trip detection. Removed ~490 lines of custom detection code. Traccar correctly returns 3 trips vs our broken 5+. Added geocoded addresses to trip cards. Commit:
53eb82c