mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-01 08:53:13 +00:00
fix(map): drop the hotel leg to/from a transport endpoint on arrival days (#1321)
On the first day of a trip the morning hotel is only a check-in fallback — you arrive from home, you didn't sleep there — so bookending the route from that hotel to the flight/train departure point drew a phantom hotel → departure leg, both on the map and in the day sidebar. The same backwards leg showed up on a multi-day transport's arrival day, and its mirror departure → hotel on an evening departure. getDayBookendHotels now also reports whether the morning hotel is one you actually slept in and whether you sleep in the evening hotel tonight. The map and sidebar only draw a hotel↔transport bookend when that holds; a hotel↔place leg is always kept, so the home-base loop and onward-travel legs are unaffected. The optimizer keeps using the hotel values as before.
This commit is contained in:
@@ -117,4 +117,40 @@ describe('getDayBookendHotels', () => {
|
||||
const h = hotel({ place_lat: null, place_lng: null })
|
||||
expect(getDayBookendHotels(days[1], days, [h])).toEqual({})
|
||||
})
|
||||
|
||||
it('flags an arrival/check-in day as not slept-here in the morning (#1321)', () => {
|
||||
// Day 1: you arrive from home and check in tonight, so the morning hotel is only a
|
||||
// check-in fallback — no hotel → departure leg should be drawn.
|
||||
const into = hotel({ start_day_id: 10, end_day_id: 30, place_lat: 3, place_lng: 4 })
|
||||
const r = getDayBookendHotels(days[0], days, [into])
|
||||
expect(r.morning).toBe(into)
|
||||
expect(r.morningIsSleptHere).toBe(false)
|
||||
expect(r.eveningIsOvernight).toBe(true)
|
||||
// The optimizer anchor must stay a loop on the check-in day (values unchanged).
|
||||
expect(getAccommodationAnchors(days[0], days, [into])).toEqual({ start: { lat: 3, lng: 4 }, end: { lat: 3, lng: 4 } })
|
||||
})
|
||||
|
||||
it('flags a mid-stay day as slept-here and overnight', () => {
|
||||
const h = hotel({ start_day_id: 10, end_day_id: 30 })
|
||||
const r = getDayBookendHotels(days[1], days, [h])
|
||||
expect(r.morningIsSleptHere).toBe(true)
|
||||
expect(r.eveningIsOvernight).toBe(true)
|
||||
})
|
||||
|
||||
it('an evening departure with no replacement check-in is not overnight (S7 mirror)', () => {
|
||||
// You woke up here but check out today and board an evening transport — you do not
|
||||
// sleep here tonight, so the last-stop → hotel leg must be droppable.
|
||||
const h = hotel({ start_day_id: 10, end_day_id: 20, place_lat: 1, place_lng: 1 })
|
||||
const r = getDayBookendHotels(days[1], days, [h])
|
||||
expect(r.morningIsSleptHere).toBe(true)
|
||||
expect(r.eveningIsOvernight).toBe(false)
|
||||
})
|
||||
|
||||
it('flags a transfer day as slept-here in the morning and overnight in the evening', () => {
|
||||
const out = hotel({ start_day_id: 10, end_day_id: 20, place_lat: 1, place_lng: 1 })
|
||||
const into = hotel({ start_day_id: 20, end_day_id: 30, place_lat: 9, place_lng: 9 })
|
||||
const r = getDayBookendHotels(days[1], days, [out, into])
|
||||
expect(r.morningIsSleptHere).toBe(true)
|
||||
expect(r.eveningIsOvernight).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -12,7 +12,7 @@ export const getDayBookendHotels = (
|
||||
day: Day,
|
||||
days: Day[],
|
||||
accommodations: Accommodation[],
|
||||
): { morning?: Accommodation; evening?: Accommodation } => {
|
||||
): { morning?: Accommodation; evening?: Accommodation; morningIsSleptHere?: boolean; eveningIsOvernight?: boolean } => {
|
||||
const inRange = accommodations.filter(a =>
|
||||
a.place_lat != null && a.place_lng != null &&
|
||||
isDayInAccommodationRange(day, a.start_day_id, a.end_day_id, days),
|
||||
@@ -30,6 +30,13 @@ export const getDayBookendHotels = (
|
||||
return {
|
||||
morning: sleptHere ?? checkIn ?? inRange[0],
|
||||
evening: checkIn ?? sleptHere ?? inRange[0],
|
||||
// Provenance for the drawing consumers (map + sidebar). A hotel↔transport bookend
|
||||
// is only real when you actually used the hotel: morningIsSleptHere is true only
|
||||
// when you woke up there (not a check-in fallback on an arrival day), and
|
||||
// eveningIsOvernight is true only when you sleep there tonight (you check in today,
|
||||
// or an earlier stay continues past today). The optimizer keeps using the values.
|
||||
morningIsSleptHere: sleptHere != null,
|
||||
eveningIsOvernight: checkIn != null || (sleptHere != null && orderOf(sleptHere.end_day_id) > dayOrd),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user