mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-29 16:10:07 +00:00
fix(roadtrip): seat rides and the drive into tomorrow by one rule, and say why a way was not taken
The slot the desktop stores for a ride within one day was worked out over the rows the day list shows, so a hotel it hides on the far shore was left out, the ferry was filed behind it and the road trip drove there overland before the crossing. It is now worked out over every stop the drive reads, timed the way the drive times it. An overnight ride no longer seats its arrival by the slot seeded on the day it left, and opens the day it lands on unless somebody placed it there. A via behind a day's last stop goes once that stop is no longer last, for the rail's drags and removals, the list's reorder and the server's sorts and seated nights alike; some of them used to bend a leg of the day through it instead. A leg OSRM drew while the avoidance router did not answer is now known as such: the picker no longer reads it as that router's road, has the leg routed again when its own road is chosen and says so, and a join that fell back is asked for again and flagged on its card. A refused way that leaves a class out names the setting that drives it, the ferry hint covers a crossing that lands the next day, a road another engine timed names that engine, and the desk bar keeps the keyboard on the chip while a choice is checked and announces the outcome. A ride on none of the trip's days is no longer said to have no date.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { parseTimeToMinutes, getSpanPhase, hidesOnMiddleDay, getTransportRouteEndpoints, getDisplayTimeForDay, getTransportForDay, getAssignmentReservations, getMergedItems, rideSeatKey, timedSlot } from './dayMerge'
|
||||
import { parseTimeToMinutes, getSpanPhase, hidesOnMiddleDay, getTransportRouteEndpoints, getDisplayTimeForDay, getTransportForDay, getAssignmentReservations, getMergedItems, rideSeatKey, stayStartingOn, storedRideSlot, timedSlot } from './dayMerge'
|
||||
|
||||
describe('parseTimeToMinutes', () => {
|
||||
it('parses HH:MM string', () => {
|
||||
@@ -336,7 +336,9 @@ describe('getMergedItems: a ride within one day, seated by where it goes (#2461)
|
||||
})
|
||||
|
||||
it('opens the day with a ride that lands next to its first stop, ahead of a note too', () => {
|
||||
expect(read([newcastle()], [ferry()], [{ id: 10, sort_order: 0 }])).toEqual(['transport:69', 'place:2', 'note:10'])
|
||||
// The note keeps its place ahead of the stop; the ride goes ahead of both.
|
||||
expect(read([newcastle()], [ferry()], [{ id: 10, sort_order: 0 }])).toEqual(['transport:69', 'note:10', 'place:2'])
|
||||
expect(read([newcastle()], [ferry()], [{ id: 10, sort_order: 2 }])).toEqual(['transport:69', 'place:2', 'note:10'])
|
||||
})
|
||||
|
||||
it('leaves a slot somebody stored where it is', () => {
|
||||
@@ -357,6 +359,59 @@ describe('getMergedItems: a ride within one day, seated by where it goes (#2461)
|
||||
})
|
||||
})
|
||||
|
||||
// The slot the desktop stores for a ride nobody placed yet, worked out over the rows the
|
||||
// road trip drives rather than the ones the list shows (#2461).
|
||||
describe('storedRideSlot', () => {
|
||||
const row = (id: number, order_index: number, lat: number | null, lng: number | null, place_time: string | null = null) =>
|
||||
({ id, order_index, place_id: id * 10, place: { lat, lng, place_time } })
|
||||
const amsterdam = row(1, 0, 52.3731, 4.8926)
|
||||
// The hotel a booking put on the day: hidden in the list, a stop of the drive.
|
||||
const hotel = row(3, 1, 54.975, -1.61)
|
||||
const ferry = (over: Record<string, unknown> = {}) => ({
|
||||
id: 69, type: 'ferry', title: 'IJmuiden to Newcastle', day_id: 5, end_day_id: 5,
|
||||
reservation_time: '2026-10-06T17:30', reservation_end_time: '2026-10-06T23:00',
|
||||
endpoints: [
|
||||
{ role: 'from', sequence: 0, name: 'IJmuiden', lat: 52.4581, lng: 4.5879 },
|
||||
{ role: 'to', sequence: 1, name: 'Port of Tyne', lat: 54.9925, lng: -1.4522 },
|
||||
],
|
||||
...over,
|
||||
})
|
||||
|
||||
it('puts a ferry ahead of the hotel across the water that the list does not show', () => {
|
||||
// Over the visible Amsterdam alone the clock closed the day at 1.5, behind the hotel,
|
||||
// and the drive went there overland before the crossing.
|
||||
expect(storedRideSlot(ferry(), [amsterdam, hotel], [{ place_id: 30, start_day_id: 5, check_in: null }], 5)).toBe(0.5)
|
||||
})
|
||||
|
||||
it('times a night by the check-in of the stay that starts there, and the clock still binds', () => {
|
||||
// Checked in at three, the hotel is behind the drive by the 17:30 sailing already.
|
||||
const checkIn = [{ place_id: 30, start_day_id: 5, check_in: '15:00' }]
|
||||
expect(storedRideSlot(ferry(), [amsterdam, hotel], checkIn, 5)).toBe(1.5)
|
||||
// A stay that starts on another day says nothing about this one.
|
||||
expect(storedRideSlot(ferry(), [amsterdam, hotel], [{ ...checkIn[0], start_day_id: 4 }], 5)).toBe(0.5)
|
||||
})
|
||||
|
||||
it('opens the day, closes it, or sits behind a timed row, measured on order indexes', () => {
|
||||
expect(storedRideSlot(ferry(), [row(2, 3, 54.9783, -1.6178)], [], 5)).toBe(2.5)
|
||||
expect(storedRideSlot(ferry(), [amsterdam], [], 5)).toBe(0.5)
|
||||
expect(storedRideSlot(ferry(), [amsterdam, row(2, 1, 54.9783, -1.6178, '10:00')], [], 5)).toBe(1.5)
|
||||
// A row without coordinates is no stop of the drive, but the day still closes behind it.
|
||||
expect(storedRideSlot(ferry(), [amsterdam, row(4, 1, null, null)], [], 5)).toBe(1.5)
|
||||
})
|
||||
|
||||
it('leaves anything but a ride within one day to the clock', () => {
|
||||
expect(storedRideSlot(ferry({ type: 'taxi' }), [amsterdam, hotel], [], 5)).toBeNull()
|
||||
expect(storedRideSlot(ferry({ end_day_id: 6 }), [amsterdam, hotel], [], 5)).toBeNull()
|
||||
expect(storedRideSlot(ferry(), [], [], 5)).toBeNull()
|
||||
})
|
||||
|
||||
it('finds the stay by its place and the day it starts', () => {
|
||||
const stays = [{ id: 1, place_id: 30, start_day_id: 4 }, { id: 2, place_id: 30, start_day_id: 5 }]
|
||||
expect(stayStartingOn(stays, 30, 5)?.id).toBe(2)
|
||||
expect(stayStartingOn(stays, 31, 5)).toBeUndefined()
|
||||
})
|
||||
})
|
||||
|
||||
// A stop with a start is drawn by it, and the road trip drives the stored order, so a
|
||||
// stop joining a day from elsewhere is stored where the list will draw it.
|
||||
describe('timedSlot', () => {
|
||||
|
||||
@@ -322,6 +322,69 @@ export function rideSeatKey(r: CarrierBooking, rows: readonly MergedItem[]): num
|
||||
return ride ? rideSeatAfter(rows.flatMap(seatItemsOf), ride) : null
|
||||
}
|
||||
|
||||
/** A booked stay, as far as the road trip times a stop by it. */
|
||||
interface StayStart {
|
||||
place_id?: number | null
|
||||
start_day_id?: number | null
|
||||
check_in?: string | null
|
||||
}
|
||||
|
||||
/**
|
||||
* The stay a stop at `placeId` begins on day `dayId`, the one whose check-in the road trip
|
||||
* times that stop by. Only the day the stay starts: a check-out says when the room has to
|
||||
* be handed back, not when the drive sets off.
|
||||
*/
|
||||
export function stayStartingOn<T extends StayStart>(stays: readonly T[], placeId: number | null | undefined, dayId: number): T | undefined {
|
||||
return stays.find(stay => stay.place_id === placeId && stay.start_day_id === dayId)
|
||||
}
|
||||
|
||||
/** A stored row of a day, as far as `storedRideSlot` reads it. */
|
||||
interface StoredStop {
|
||||
order_index: number
|
||||
place_id?: number | null
|
||||
place?: { lat?: number | null; lng?: number | null; place_time?: string | null } | null
|
||||
}
|
||||
|
||||
/**
|
||||
* The slot to store for a ride that lands on the day it left (`sameDayRide`) and has none
|
||||
* yet: worked out over the day's rows the way the road trip seats its terminals among
|
||||
* them (`seatCarrierStops`), so the slot the list is drawn by and the drive agree. Null for
|
||||
* any other booking, which keeps the clock's slot.
|
||||
*
|
||||
* Read over every stored row the drive stops at, the ones the list hides included: the
|
||||
* hotel a booking put on the day, a petrol station kept out of the list. The slot is a
|
||||
* number among their order indexes all the same, and worked out over the rows the list
|
||||
* shows it could land behind a hidden stop on the far shore, which the drive then went to
|
||||
* overland before the crossing (#2461). Each row counts with its start, else the check-in
|
||||
* of the stay that begins there that day (`stayStartingOn`), and with its coordinates; a
|
||||
* row without them is no stop of the drive. Where the rule keeps the clock's seat, the
|
||||
* clock is read over the same rows: behind the last one timed at or before the departure,
|
||||
* else at the end of the day.
|
||||
*/
|
||||
export function storedRideSlot(
|
||||
r: CarrierBooking,
|
||||
day: readonly StoredStop[],
|
||||
stays: readonly StayStart[],
|
||||
dayId: number,
|
||||
): number | null {
|
||||
const ride = sameDayRide(r)
|
||||
if (!ride || !day.length) return null
|
||||
const items: SeatItem[] = day.flatMap(row => {
|
||||
const lat = row.place?.lat
|
||||
const lng = row.place?.lng
|
||||
if (typeof lat !== 'number' || typeof lng !== 'number' || !Number.isFinite(lat) || !Number.isFinite(lng)) return []
|
||||
const start = row.place?.place_time ?? stayStartingOn(stays, row.place_id, dayId)?.check_in
|
||||
return [{ key: row.order_index, minutes: parseTimeToMinutes(start), point: { lat, lng } }]
|
||||
})
|
||||
const keys = day.map(row => row.order_index)
|
||||
const seat = rideSeatAfter(items, ride)
|
||||
if (seat === -Infinity) return Math.min(...keys) - 0.5
|
||||
if (seat !== null) return seat + 0.5
|
||||
const departs = ride.minutes ?? 0
|
||||
const before = items.filter(item => item.minutes !== null && item.minutes <= departs).map(item => item.key)
|
||||
return (before.length ? Math.max(...before) : Math.max(...keys)) + 0.5
|
||||
}
|
||||
|
||||
/** Merge places, notes, and transports into a single ordered day timeline. */
|
||||
export function getMergedItems(opts: {
|
||||
dayAssignments: any[]
|
||||
|
||||
Reference in New Issue
Block a user