mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-23 21:33:19 +00:00
fix(roadtrip): a hotel visited again on its check-in day is the night only at its last visit
A stop counted as the booked night whenever a stay began at its place on its day, so a hotel on its check-in day twice (the booking's own stop and a rest the traveller planned there) was read as two nights. Both were held to the check-in: the rest waited for the room or was set back to it, and with a check-in far from its arrival the rest and every stop behind it moved onto the next day's card. oneNightPerStay in shared keeps the night and its check-in on the last visit of the place and turns the earlier ones into ordinary stops, still a hotel. The browser and calculate_roadtrip both run it, the stored ride slot times only that row by the check-in, and opening an earlier visit in road trip mode opens the stop rather than the night. Refs #2636
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* ROADTRIP-ASSEMBLE-001..022: what the assembler does with the model's warnings, and
|
||||
* ROADTRIP-ASSEMBLE-001..023: what the assembler does with the model's warnings, and
|
||||
* what it tells a surface about the drive between connected days. From 017 on: a booked
|
||||
* night seated at both ends of its days (`seatNightBookends`) is one spot overnight,
|
||||
* driven to and from like any stop and never between.
|
||||
@@ -14,7 +14,7 @@
|
||||
*/
|
||||
import { assembleRoadtrip } from './assemble';
|
||||
import type { DayWindow } from './dayWindow';
|
||||
import { seatNightBookends } from './nightBookends';
|
||||
import { oneNightPerStay, seatNightBookends } from './nightBookends';
|
||||
import type { PlanDay, RoadtripStop, RoutedLeg, SnappedWaypoint } from './planning-types';
|
||||
import { standsAsDay } from './roadtripModel';
|
||||
|
||||
@@ -386,6 +386,38 @@ describe('assembleRoadtrip booked nights', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('assembleRoadtrip a hotel visited twice on its check-in day (#2636)', () => {
|
||||
// 90 km at the 40 seconds a kilometre `leg` drives is an hour.
|
||||
const hour = 90;
|
||||
const hotel = { placeId: 900, lat: 45, lng: 7, night: true, stopType: 'hotel' };
|
||||
|
||||
it('ROADTRIP-ASSEMBLE-023: the rest at noon is a stop, and the day stays on its card', () => {
|
||||
// A late check-in and a rest at the hotel before it. Both visits read as the night held
|
||||
// the rest to ten at night, and the places behind it went onto the next day's card.
|
||||
const stops = oneNightPerStay([
|
||||
stop({ ownerIndex: 0, time: '09:00', dwellMinutes: 0 }),
|
||||
stop({ ownerIndex: 1, ...hotel, checkInTime: '22:00', dwellMinutes: 60 }),
|
||||
stop({ ownerIndex: 2, dwellMinutes: 30 }),
|
||||
stop({ ownerIndex: 3, ...hotel, checkInTime: '22:00' }),
|
||||
]);
|
||||
|
||||
const routes = assemble(stops, [hour, hour, hour]);
|
||||
|
||||
expect(routes.days).toHaveLength(1);
|
||||
const day = routes.days[0]!;
|
||||
expect(day.stops.map((s) => [s.ownerIndex, s.night, s.checkInTime])).toEqual([
|
||||
[0, undefined, undefined],
|
||||
[1, false, null],
|
||||
[2, undefined, undefined],
|
||||
[3, true, '22:00'],
|
||||
]);
|
||||
expect(day.schedule.entries.map((e) => e.arrival)).toEqual(['09:00', '10:00', '12:00', '22:00']);
|
||||
expect(day.schedule.entries[1]!.anchored).toBeFalsy();
|
||||
expect(day.schedule.entries[3]!.anchored).toBe(true);
|
||||
expect(day.schedule.warnings).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('assembleRoadtrip nights at a booked hotel', () => {
|
||||
// Three nights in one hotel from day 1, places on days 1 and 2, the check-out on day 3
|
||||
// with nothing of its own.
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
* that a night spent at one hotel is a leg going nowhere. From 029 on: a day moved by a
|
||||
* ride the road does not see, a terminal out of a drive's reach, and the flight day of
|
||||
* the report read from the stored day to its nights. From 033 on: the stop a booking put
|
||||
* on its check-in day gives way to the evening at that stay.
|
||||
* on its check-in day gives way to the evening at that stay. From 036 on: a hotel visited
|
||||
* twice on its check-in day is the night at its last visit only (#2636).
|
||||
*/
|
||||
import { assembleRoadtrip } from './assemble';
|
||||
import { carrierLegsFor, carrierSeam, seatCarrierStops, terminalAssignmentId, type CarrierBooking } from './carriers';
|
||||
@@ -18,6 +19,7 @@ import {
|
||||
bookendStaysOf,
|
||||
hotelBookendsOn,
|
||||
isStationaryJoin,
|
||||
oneNightPerStay,
|
||||
seatNightBookends,
|
||||
withStationaryJoins,
|
||||
type BookendStay,
|
||||
@@ -815,3 +817,40 @@ describe('the stop a booking put on its check-in day (#2546)', () => {
|
||||
expect(shape(other[0])).toEqual(['morning:1', 'B', 'P', 'evening:2']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('a hotel visited twice on its check-in day (#2636)', () => {
|
||||
const b = stay(2, D2, D3, WALLINGA);
|
||||
const nights = (day: PlanDay | undefined) =>
|
||||
(day?.stops ?? []).map((s) => [s.bookend ? s.bookend.phase : s.name, s.night ?? false, s.checkInTime ?? null]);
|
||||
|
||||
it('ROADTRIP-BOOKENDS-036: the last visit is the night, an earlier one a stop without the check-in', () => {
|
||||
const rest = stayStop(D2, 0, WALLINGA, { name: 'Rest', placeId: 502, checkInTime: '15:00' });
|
||||
const place = visit(D2, 1, { name: 'P' });
|
||||
const night = stayStop(D2, 2, WALLINGA, { name: 'Night', placeId: 502, checkInTime: '15:00', bookedNightId: 2 });
|
||||
expect(nights(planDay(D2, oneNightPerStay([rest, place, night])))).toEqual([
|
||||
['Rest', false, null],
|
||||
['P', false, null],
|
||||
['Night', true, '15:00'],
|
||||
]);
|
||||
// Still a hotel: only the night and its check-in move.
|
||||
expect(oneNightPerStay([rest, place, night])[0]).toMatchObject({ stopType: 'hotel', placeId: 502 });
|
||||
// One visit per hotel, two hotels on one day, or no hotel: the day comes back as it was.
|
||||
const other = stayStop(D2, 3, GETAWAY, { name: 'Other', placeId: 501, checkInTime: '18:00' });
|
||||
for (const stops of [[place, night], [night, other], [place]]) expect(oneNightPerStay(stops)).toBe(stops);
|
||||
});
|
||||
|
||||
it('ROADTRIP-BOOKENDS-037: with the days at the stay, the rest stays a stop and the booked night ends the day', () => {
|
||||
const stops = oneNightPerStay([
|
||||
stayStop(D2, 0, WALLINGA, { name: 'Rest', placeId: 502, checkInTime: '15:00' }),
|
||||
visit(D2, 1, { name: 'P' }),
|
||||
stayStop(D2, 2, WALLINGA, { name: 'B', placeId: 502, checkInTime: '15:00', bookedNightId: 2 }),
|
||||
]);
|
||||
const [day] = seatNightBookends([planDay(D2, stops)], days, [stay(1, D1, D2, GETAWAY), b]);
|
||||
expect(nights(day)).toEqual([
|
||||
['morning', false, null],
|
||||
['Rest', false, null],
|
||||
['P', false, null],
|
||||
['B', true, '15:00'],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -112,6 +112,33 @@ export function bookendStaysOf<S extends Omit<BookendStay, 'reservation_id'>>(
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* The stored day's stops with one night per hotel: the last visit of a place a stay begins
|
||||
* at on this day (#2636).
|
||||
*
|
||||
* A stop is a night when a stay begins at its place on its day, and a hotel can be on its
|
||||
* check-in day twice: the stop the booking put there and the traveller's own visit, back
|
||||
* for a rest at noon. Both were read as the night and both held to the check-in, so the
|
||||
* rest waited for the room or was set back to it, and a check-in twelve hours off its
|
||||
* arrival moved it and every stop behind it onto the next day's card. The night ends the
|
||||
* day, so the last visit is the night; the ones before it are stops like any other, a
|
||||
* hotel all the same, without the check-in.
|
||||
*
|
||||
* Read over the stops in their stored order, before a terminal or a bookend is seated
|
||||
* among them, the same in the browser and on the server. A day with one visit per hotel
|
||||
* comes back as it was.
|
||||
*/
|
||||
export function oneNightPerStay(stops: RoadtripStop[]): RoadtripStop[] {
|
||||
const last = new Map<number, number>();
|
||||
stops.forEach((stop, i) => {
|
||||
if (stop.night) last.set(stop.placeId, i);
|
||||
});
|
||||
if (last.size === stops.filter((stop) => stop.night).length) return stops;
|
||||
return stops.map((stop, i) =>
|
||||
stop.night && last.get(stop.placeId) !== i ? { ...stop, night: false, checkInTime: null } : stop,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* A bookend as a stop. `legMode` is the mode of the drive that leaves it: the morning's
|
||||
* drive to the first stop goes the way that stop is reached from the hotel
|
||||
|
||||
Reference in New Issue
Block a user