Skip to content

fix: time-based detour baseline + station toggle cleanup#24

Merged
GeiserX merged 1 commit intomainfrom
fix/detour-time-baseline-toggle
Apr 6, 2026
Merged

fix: time-based detour baseline + station toggle cleanup#24
GeiserX merged 1 commit intomainfrom
fix/detour-time-baseline-toggle

Conversation

@GeiserX
Copy link
Copy Markdown
Owner

@GeiserX GeiserX commented Apr 6, 2026

Summary

  • Detour accuracy fix: The proportional baseline (routeDuration * geographicFraction) was fundamentally broken because speed varies along the route — highway segments cover lots of distance quickly while city segments are slow per km. Now extracts per-maneuver timing from Valhalla's route response, builds cumulative durations at each coordinate, and sends them to the detour API. The baseline for each station's window is routeDurations[rejoinIdx] - routeDurations[exitIdx] — the exact driving time on the original route, not an approximation.
  • Station toggle fix: Deselecting a station (clicking same station on map or sidebar) now properly removes the isStationLeg waypoint from state. Previously it only cleared the route overlay but left the stale waypoint, preventing reliable toggle-off behavior.

Test plan

  • Route Sangüesa/Zaragoza → Murcia, verify Erla detour badge shows ~10-15 min (was 51 min)
  • Click station on map → adds leg. Click same station → removes leg completely
  • Click station in sidebar → adds leg. Click again → removes leg + reverts to base route
  • Verify detour badges load progressively via NDJSON streaming
  • Try a route with mixed highway/city segments, confirm detour estimates are reasonable

Detour math: the proportional baseline (routeDuration * segFraction)
used geographic distance as a proxy for time, producing wildly wrong
detour estimates where speed varies along the route (e.g. Erla showed
+51min instead of +12min). Now builds per-coordinate cumulative
durations from Valhalla maneuver timing and sends them to the detour
API. Baseline = routeDurations[rejoinIdx] - routeDurations[exitIdx],
which is the exact driving time for that segment.

Station toggle: deselecting a station (map or sidebar) now properly
removes the isStationLeg waypoint. Previously only cleared the route
overlay but left the waypoint in state, preventing clean deselection.
@GeiserX GeiserX merged commit fa6eb80 into main Apr 6, 2026
@GeiserX GeiserX deleted the fix/detour-time-baseline-toggle branch April 6, 2026 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant