fix(roadtrip): the range warning and the per-leg figures in the server plan

deriveDriveWarnings takes a two-slot "does this stop refuel" pair, slot 0 for
the stop a leg leaves and slot 1 for the stop it reaches, and the assembler
hard-coded slot 1 to false. The suppression the model was written and tested
for could therefore never fire through it: a day that reaches a charger 700 km
in reported running dry at the charger, and a run of warnings that should
collapse to one stayed at full length. Pinned by a spec of its own now, since
the wrapper had none.

The server's plan built each leg by spreading the whole run's segment and then
overriding only its metres and seconds, so every leg of a multi-stop run
carried the run's distance text, its duration text and its polyline midpoint:
leg one of a 480 km day reported 100 km with "480 km" printed beside it. The
four texts and the midpoint are per leg now, in the reader's own unit rather
than the router's hard-coded kilometres, which also ends a response that mixed
miles in its day labels with kilometres in its legs.
This commit is contained in:
Maurice
2026-09-13 23:22:52 +02:00
parent 61880ce7d6
commit f4380727c7
5 changed files with 150 additions and 10 deletions
@@ -15,6 +15,9 @@ import {
parseClock,
effectiveRangeKm,
parseAvoid,
formatDistance,
formatDurationShort,
type DistanceUnit,
type RoadtripStop,
type PlanDay,
type RoutedLeg,
@@ -133,6 +136,8 @@ export class RoadtripPlanService {
if (context.visits.length > 150)
throw new HttpException({ error: 'This trip exceeds the 150-visit calculation limit.' }, 400);
const asked = new Set<string>();
const distanceUnit: DistanceUnit =
this.settings.getUserSettings(userId).distance_unit === 'imperial' ? 'imperial' : 'metric';
const fetchRun = async (stops: RoadtripStop[], dayId: number, profile: string) => {
const points: { lat: number; lng: number }[] = [];
const stopAt: number[] = [];
@@ -152,12 +157,28 @@ export class RoadtripPlanService {
try {
if (points.length > 100) throw new Error('Too many waypoints');
const routed = await this.router.route(userId, tripId, dayId, points, profile, avoid);
const legs = routed.parts.map((part, index) => ({
...routed.leg.seg,
...part,
from: [points[index].lat, points[index].lng] as [number, number],
to: [points[index + 1].lat, points[index + 1].lng] as [number, number],
}));
// Spreading the run's own seg first carried its whole-route text and
// midpoint onto every leg of a multi-stop run: `part` only overrides the
// metres and the seconds, so leg one of a 480 km day reported 100 km with
// "480 km" printed beside it. The four texts and the midpoint are per leg
// now, the way the browser has always computed them — and in the reader's
// own unit, rather than the router's hard-coded kilometres.
const legs = routed.parts.map((part, index) => {
const from = [points[index].lat, points[index].lng] as [number, number];
const to = [points[index + 1].lat, points[index + 1].lng] as [number, number];
const durationText = formatDurationShort(part.duration);
return {
...routed.leg.seg,
...part,
from,
to,
mid: [(from[0] + to[0]) / 2, (from[1] + to[1]) / 2] as [number, number],
distanceText: formatDistance(part.distance / 1000, distanceUnit),
durationText,
drivingText: durationText,
walkingText: durationText,
};
});
Object.assign(
allLegs,
foldRouteRun(stops, stopAt, { coordinates: routed.leg.line, legs, vias: routed.leg.vias }, profile),
@@ -236,7 +257,7 @@ export class RoadtripPlanService {
vehicleKind,
connectDays,
boundaries: context.boundaries,
distanceUnit: this.settings.getUserSettings(userId).distance_unit === 'imperial' ? 'imperial' : 'metric',
distanceUnit,
labels: { start: 'Continue journey', end: 'End of day' },
});
return {