feat: simulated odometer in trip replay + trip list (continuous across trips)
- Pi route_points: emit per-point odometer (raw OBD value or baseline+prior+within-trip distance) - Pi get_trip_route: SELECT ODOMETER, compute prior-trips distance + baseline - Pi list_trips: fallback now starts from baseline (was 0) - Server get_trip_route: per-point odometer (raw or simulated) with haversine accumulation - Server list_trips: odo_start/end from baseline + cumulative (was hardcoded None) - history.js: Odometer line in replay scrubber below speed - Both history templates: trip-replay-odometer element
This commit is contained in:
+14
-1
@@ -216,7 +216,7 @@ def build_trip_summaries(raw_rows):
|
||||
return trips
|
||||
|
||||
|
||||
def route_points(raw_rows, max_points=2000):
|
||||
def route_points(raw_rows, max_points=2000, odometer_baseline=0.0, prior_km=0.0):
|
||||
rows = normalize_tracking_rows(raw_rows)
|
||||
filtered_rows = []
|
||||
for row in rows:
|
||||
@@ -226,6 +226,7 @@ def route_points(raw_rows, max_points=2000):
|
||||
continue
|
||||
filtered_rows.append(row)
|
||||
rows = filtered_rows
|
||||
cumulative_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:
|
||||
@@ -235,6 +236,17 @@ def route_points(raw_rows, max_points=2000):
|
||||
if distance_km * 1000 >= GPS_MOTION_METERS
|
||||
else 0
|
||||
)
|
||||
if index:
|
||||
segment_km, _ = _segment(row, rows[index - 1])
|
||||
cumulative_km += segment_km
|
||||
# Odometer per point: use the raw OBD value when the vehicle reports
|
||||
# one; otherwise simulate it as baseline + prior trips + within-trip
|
||||
# distance (continuous across trips, matching get_overview_stats).
|
||||
raw_odometer = row.get("odometer")
|
||||
if raw_odometer is not None and raw_odometer > 0:
|
||||
row["odometer"] = raw_odometer
|
||||
else:
|
||||
row["odometer"] = odometer_baseline + prior_km + cumulative_km
|
||||
if len(rows) <= max_points:
|
||||
selected = rows
|
||||
else:
|
||||
@@ -250,4 +262,5 @@ def route_points(raw_rows, max_points=2000):
|
||||
"longitude": row["longitude"],
|
||||
"speed": round(row["speed"], 1),
|
||||
"speed_source": row["speed_source"],
|
||||
"odometer": round(row["odometer"], 1) if row["odometer"] is not None else None,
|
||||
} for row in selected]
|
||||
|
||||
Reference in New Issue
Block a user