mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 00:20:07 +00:00
fix(planner): no hotel bookend legs against a same-day carrier without stay times (#2157)
This commit is contained in:
@@ -116,6 +116,21 @@ export function getTransportRouteEndpoints(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this booking is a carrier that contributes a located route endpoint on the
|
||||
* given day — the signal that the day's geography changes by riding something rather
|
||||
* than driving, which the hotel-bookend rules need on days without recorded
|
||||
* check-in/check-out times (#2157). The span rules above make an overnight carrier
|
||||
* count only on the days it actually touches. A carrier saved without coordinates
|
||||
* deliberately does not count: it contributes nothing to the drawn route, so treating
|
||||
* it as proof of travel would flip hotel legs on data the map cannot see.
|
||||
*/
|
||||
export function hasCarrierEndpointOnDay(r: any, dayId: number): boolean {
|
||||
if (!isCarrierTransport(r)) return false
|
||||
const { from, to } = getTransportRouteEndpoints(r, dayId)
|
||||
return from != null || to != null
|
||||
}
|
||||
|
||||
export function getDisplayTimeForDay(
|
||||
r: { day_id?: number | null; end_day_id?: number | null; reservation_time?: string | null; reservation_end_time?: string | null },
|
||||
dayId: number
|
||||
|
||||
@@ -225,6 +225,42 @@ describe('shouldDrawMorningLeg', () => {
|
||||
const bookends = { morning: into({ start_day_id: 20, check_in: '15:00' }), morningIsSleptHere: false }
|
||||
expect(shouldDrawMorningLeg(bookends, checkInDay, { isPlace: true, time: '19:00' })).toBe(false)
|
||||
})
|
||||
|
||||
it('does NOT draw on a no-check-in-time day when a carrier arrives or leaves that day (#2157)', () => {
|
||||
// You fly in, so the hotel is where the day ends — the no-time loop default
|
||||
// must not start the day from a hotel you only reach tonight.
|
||||
const noCheckIn = { morning: into({ check_in: null }), morningIsSleptHere: false }
|
||||
expect(shouldDrawMorningLeg(noCheckIn, checkInDay, { isPlace: true, time: null }, true)).toBe(false)
|
||||
expect(shouldDrawMorningLeg(noCheckIn, checkInDay, { isPlace: true, time: '19:00' }, true)).toBe(false)
|
||||
})
|
||||
|
||||
it('still closes the no-time loop when the day has no carrier (#2009 preserved)', () => {
|
||||
const noCheckIn = { morning: into({ check_in: null }), morningIsSleptHere: false }
|
||||
expect(shouldDrawMorningLeg(noCheckIn, checkInDay, { isPlace: true, time: null }, false)).toBe(true)
|
||||
// Callers that don't know about the flag keep the old behaviour.
|
||||
expect(shouldDrawMorningLeg(noCheckIn, checkInDay, { isPlace: true, time: null })).toBe(true)
|
||||
})
|
||||
|
||||
it('a recorded check-in time keeps the timed rule even on a carrier day (#2157)', () => {
|
||||
const bookends = { morning: into({ check_in: '15:00' }), morningIsSleptHere: false }
|
||||
expect(shouldDrawMorningLeg(bookends, checkInDay, { isPlace: true, time: '19:00' }, true)).toBe(true)
|
||||
expect(shouldDrawMorningLeg(bookends, checkInDay, { isPlace: true, time: '10:00' }, true)).toBe(false)
|
||||
})
|
||||
|
||||
it('a carrier does not touch the slept-here morning leg (#2157)', () => {
|
||||
// Mid-stay day with a day-trip by train: you still woke up in this hotel.
|
||||
const bookends = { morning: into(), morningIsSleptHere: true }
|
||||
expect(shouldDrawMorningLeg(bookends, checkInDay, { isPlace: true, time: '06:00' }, true)).toBe(true)
|
||||
})
|
||||
|
||||
it('the no-time default does not reach an edge place out of drive range (#2157)', () => {
|
||||
// "Home", an ocean away from the hotel, with no carrier recorded at all: the
|
||||
// closed loop is a guess, and a guess does not get a 2400 km leg.
|
||||
const noCheckIn = { morning: into({ check_in: null }), morningIsSleptHere: false }
|
||||
expect(shouldDrawMorningLeg(noCheckIn, checkInDay, { isPlace: true, time: null, lat: 21.28, lng: -157.83 })).toBe(false)
|
||||
// A nearby untimed place keeps the #2009 loop.
|
||||
expect(shouldDrawMorningLeg(noCheckIn, checkInDay, { isPlace: true, time: null, lat: 48.2, lng: 11.6 })).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('shouldDrawEveningLeg', () => {
|
||||
@@ -285,4 +321,36 @@ describe('shouldDrawEveningLeg', () => {
|
||||
const bookends = { evening: out({ check_out: '11:00' }), eveningIsOvernight: false }
|
||||
expect(shouldDrawEveningLeg(bookends, checkOutDay, { isPlace: false, time: '09:00' })).toBe(false)
|
||||
})
|
||||
|
||||
it('does NOT draw on a no-check-out-time day when a carrier arrives or leaves that day (#2157)', () => {
|
||||
// The reported last day: fly home, then a "Home" entry — nothing drives from
|
||||
// Home back to the hotel you left that morning.
|
||||
const noCheckOut = { evening: out({ check_out: null }), eveningIsOvernight: false }
|
||||
expect(shouldDrawEveningLeg(noCheckOut, checkOutDay, { isPlace: true, time: null }, true)).toBe(false)
|
||||
expect(shouldDrawEveningLeg(noCheckOut, checkOutDay, { isPlace: true, time: '09:00' }, true)).toBe(false)
|
||||
})
|
||||
|
||||
it('still closes the no-time loop when the day has no carrier (#2009 preserved)', () => {
|
||||
const noCheckOut = { evening: out({ check_out: null }), eveningIsOvernight: false }
|
||||
expect(shouldDrawEveningLeg(noCheckOut, checkOutDay, { isPlace: true, time: null }, false)).toBe(true)
|
||||
expect(shouldDrawEveningLeg(noCheckOut, checkOutDay, { isPlace: true, time: null })).toBe(true)
|
||||
})
|
||||
|
||||
it('a recorded check-out time keeps the timed rule even on a carrier day (#2157)', () => {
|
||||
const bookends = { evening: out({ check_out: '11:00' }), eveningIsOvernight: false }
|
||||
expect(shouldDrawEveningLeg(bookends, checkOutDay, { isPlace: true, time: '09:00' }, true)).toBe(true)
|
||||
expect(shouldDrawEveningLeg(bookends, checkOutDay, { isPlace: true, time: '18:00' }, true)).toBe(false)
|
||||
})
|
||||
|
||||
it('a carrier does not touch the overnight evening leg (#2157)', () => {
|
||||
// You sleep here tonight — the day-trip train changes nothing about that.
|
||||
const bookends = { evening: out(), eveningIsOvernight: true }
|
||||
expect(shouldDrawEveningLeg(bookends, checkOutDay, { isPlace: true, time: '23:00' }, true)).toBe(true)
|
||||
})
|
||||
|
||||
it('the no-time default does not reach an edge place out of drive range (#2157)', () => {
|
||||
const noCheckOut = { evening: out({ check_out: null }), eveningIsOvernight: false }
|
||||
expect(shouldDrawEveningLeg(noCheckOut, checkOutDay, { isPlace: true, time: null, lat: 21.28, lng: -157.83 })).toBe(false)
|
||||
expect(shouldDrawEveningLeg(noCheckOut, checkOutDay, { isPlace: true, time: null, lat: 48.2, lng: 11.6 })).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { Day, Accommodation, RouteAnchors } from '../types'
|
||||
import { parseTimeToMinutes } from './dayMerge'
|
||||
import { withinDriveRange } from './geo'
|
||||
|
||||
/**
|
||||
* Set on an edge waypoint that is the endpoint of a booking which CARRIES you out of
|
||||
@@ -71,13 +72,15 @@ export const getAccommodationAnchors = (
|
||||
// morning hotel (a normal home-base day). On that hotel's check-in day you were traveling TO the
|
||||
// hotel, so the leg is drawn only when the first stop is a PLACE provably timed at/after check-in
|
||||
// (you dropped your bags first). A place before check-in (an airport you reach first, #1465), a
|
||||
// transport arrival (you flew in, weren't at the hotel yet, #1321), an un-timed place ("Home"
|
||||
// before driving out, #1597), or a missing check-in time all mean no leg — mirroring the
|
||||
// evening rule below.
|
||||
// transport arrival (you flew in, weren't at the hotel yet, #1321), or an un-timed place ("Home"
|
||||
// before driving out, #1597) all mean no leg — mirroring the evening rule below. With no
|
||||
// check-in time recorded the loop closes by default (#2009), except on a day a carrier
|
||||
// takes you there or towards an edge place out of drive range (#2157).
|
||||
export const shouldDrawMorningLeg = (
|
||||
bookends: { morning?: Accommodation; morningIsSleptHere?: boolean },
|
||||
day: Day,
|
||||
firstStop?: { isPlace: boolean; time?: string | null; carrierEdge?: CarrierEdge },
|
||||
firstStop?: { isPlace: boolean; time?: string | null; carrierEdge?: CarrierEdge; lat?: number; lng?: number },
|
||||
dayHasCarrier?: boolean,
|
||||
): boolean => {
|
||||
// You landed here. Whatever hotel the day belongs to, nobody drove out of it to the
|
||||
// airport they arrived at — so there is no morning leg, not even on a night you
|
||||
@@ -92,7 +95,17 @@ export const shouldDrawMorningLeg = (
|
||||
// loop at the start of every arrival day, since the hotel picker leaves the
|
||||
// time blank by default (#2009). With a time set, #1465 still holds: an
|
||||
// earlier stop is a place you reached before the hotel and draws no leg.
|
||||
if (checkIn == null) return true
|
||||
if (checkIn == null) {
|
||||
// ...but the closed loop is a guess, and two things disprove it (#2157): a
|
||||
// carrier on the day means you arrive at this hotel by air/rail/sea — on its
|
||||
// check-in day the hotel is where the day ENDS, not where it starts — and an
|
||||
// edge place no drive of the hotel could reach ("Home", an ocean away) was
|
||||
// where you came FROM, not somewhere the hotel sent you.
|
||||
if (dayHasCarrier) return false
|
||||
if (firstStop.lat != null && firstStop.lng != null && m.place_lat != null && m.place_lng != null
|
||||
&& !withinDriveRange({ lat: m.place_lat, lng: m.place_lng }, { lat: firstStop.lat, lng: firstStop.lng })) return false
|
||||
return true
|
||||
}
|
||||
const stop = parseTimeToMinutes(firstStop.time)
|
||||
return stop != null && stop >= checkIn
|
||||
}
|
||||
@@ -105,7 +118,8 @@ export const shouldDrawMorningLeg = (
|
||||
export const shouldDrawEveningLeg = (
|
||||
bookends: { evening?: Accommodation; eveningIsOvernight?: boolean },
|
||||
day: Day,
|
||||
lastStop?: { isPlace: boolean; time?: string | null; carrierEdge?: CarrierEdge },
|
||||
lastStop?: { isPlace: boolean; time?: string | null; carrierEdge?: CarrierEdge; lat?: number; lng?: number },
|
||||
dayHasCarrier?: boolean,
|
||||
): boolean => {
|
||||
// Mirror: you took off from here, so no drive leads from it back to tonight's hotel —
|
||||
// the reported "flight starting airport connected to the accommodation" (#2133).
|
||||
@@ -116,7 +130,15 @@ export const shouldDrawEveningLeg = (
|
||||
const checkOut = parseTimeToMinutes(e.check_out)
|
||||
// Mirror of the morning rule: with no check-out time recorded there is nothing
|
||||
// to have missed, so the return leg is drawn and the loop closes (#2009).
|
||||
if (checkOut == null) return true
|
||||
if (checkOut == null) {
|
||||
// Same two disproofs as the morning (#2157): a carrier on the check-out day
|
||||
// means the hotel is where the day STARTS and nothing drives back to it, and
|
||||
// an edge place out of drive range is where you went instead of returning.
|
||||
if (dayHasCarrier) return false
|
||||
if (lastStop.lat != null && lastStop.lng != null && e.place_lat != null && e.place_lng != null
|
||||
&& !withinDriveRange({ lat: e.place_lat, lng: e.place_lng }, { lat: lastStop.lat, lng: lastStop.lng })) return false
|
||||
return true
|
||||
}
|
||||
const stop = parseTimeToMinutes(lastStop.time)
|
||||
return stop != null && stop <= checkOut
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user