feat: add GPS trip detection, history panel, and playback (#23)
Auto-detect trips from GPS data (5-min idle threshold), pre-compute OSRM routes on trip completion, add trip history side panel with toggleable trips, and animated trip playback with speed controls. - Add GpsTrip model with TripStatus enum and migration - Trip detection in syncPositions cron (start on movement, end on idle) - Trip finalization with OSRM route matching and stats computation - API endpoints: list/detail/active/merge/backfill trips - Stats tab overhaul: trip list panel + map with colored polylines - Trip playback: animated marker, progressive trail, 1x-16x speed - Live map shows active trip trail instead of full day history - Historical backfill from existing GPS location data Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
-- CreateEnum
|
||||
CREATE TYPE "TripStatus" AS ENUM ('ACTIVE', 'COMPLETED', 'PROCESSING', 'FAILED');
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "gps_trips" (
|
||||
"id" TEXT NOT NULL,
|
||||
"deviceId" TEXT NOT NULL,
|
||||
"status" "TripStatus" NOT NULL DEFAULT 'ACTIVE',
|
||||
"startTime" TIMESTAMP(3) NOT NULL,
|
||||
"endTime" TIMESTAMP(3),
|
||||
"startLatitude" DOUBLE PRECISION NOT NULL,
|
||||
"startLongitude" DOUBLE PRECISION NOT NULL,
|
||||
"endLatitude" DOUBLE PRECISION,
|
||||
"endLongitude" DOUBLE PRECISION,
|
||||
"distanceMiles" DOUBLE PRECISION,
|
||||
"durationSeconds" INTEGER,
|
||||
"topSpeedMph" DOUBLE PRECISION,
|
||||
"averageSpeedMph" DOUBLE PRECISION,
|
||||
"pointCount" INTEGER NOT NULL DEFAULT 0,
|
||||
"matchedRoute" JSONB,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "gps_trips_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "gps_trips_deviceId_startTime_idx" ON "gps_trips"("deviceId", "startTime");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "gps_trips_status_idx" ON "gps_trips"("status");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "gps_trips" ADD CONSTRAINT "gps_trips_deviceId_fkey" FOREIGN KEY ("deviceId") REFERENCES "gps_devices"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -405,6 +405,7 @@ model GpsDevice {
|
||||
|
||||
// Location history
|
||||
locationHistory GpsLocationHistory[]
|
||||
trips GpsTrip[]
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
@@ -434,6 +435,45 @@ model GpsLocationHistory {
|
||||
@@index([timestamp]) // For cleanup job
|
||||
}
|
||||
|
||||
enum TripStatus {
|
||||
ACTIVE // Currently in progress
|
||||
COMPLETED // Finished, OSRM route computed
|
||||
PROCESSING // OSRM computation in progress
|
||||
FAILED // OSRM computation failed
|
||||
}
|
||||
|
||||
model GpsTrip {
|
||||
id String @id @default(uuid())
|
||||
deviceId String
|
||||
device GpsDevice @relation(fields: [deviceId], references: [id], onDelete: Cascade)
|
||||
|
||||
status TripStatus @default(ACTIVE)
|
||||
|
||||
startTime DateTime
|
||||
endTime DateTime?
|
||||
startLatitude Float
|
||||
startLongitude Float
|
||||
endLatitude Float?
|
||||
endLongitude Float?
|
||||
|
||||
// Pre-computed stats (filled on completion)
|
||||
distanceMiles Float?
|
||||
durationSeconds Int?
|
||||
topSpeedMph Float?
|
||||
averageSpeedMph Float?
|
||||
pointCount Int @default(0)
|
||||
|
||||
// Pre-computed OSRM route (stored as JSON for instant display)
|
||||
matchedRoute Json? // { coordinates: [lat,lng][], distance, duration, confidence }
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
@@map("gps_trips")
|
||||
@@index([deviceId, startTime])
|
||||
@@index([status])
|
||||
}
|
||||
|
||||
model GpsSettings {
|
||||
id String @id @default(uuid())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user