mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 09:38:54 +00:00
fix(tours): keep a city walk on foot across the water, mark a crossing by boat apart from the walking time and save it only once taken
This commit is contained in:
@@ -434,4 +434,31 @@ describe('city walk briefing helpers (CW-11)', () => {
|
||||
position: 2,
|
||||
});
|
||||
});
|
||||
|
||||
it('CWALK-HELP-015: a way that crosses by boat is none on foot; the estimates stand in and say where the boat starts (CW-12)', () => {
|
||||
const line: Array<[number, number]> = [
|
||||
[45.434, 12.338],
|
||||
[45.4296, 12.3264],
|
||||
[45.4268, 12.33],
|
||||
];
|
||||
const parts = [
|
||||
{ distance: 1400, duration: 1000 },
|
||||
{ distance: 500, duration: 520 },
|
||||
];
|
||||
const way = footWayOf({
|
||||
leg: { line },
|
||||
parts,
|
||||
snapped: [{ meters: 3 }, { meters: 4 }, { meters: 5 }],
|
||||
ferryLegs: [1],
|
||||
});
|
||||
expect(way).toEqual({ kind: 'unrouted', why: 'ferry_only', position: 2 });
|
||||
const { route } = planWalk(plan({ end: null }));
|
||||
expect(describeWalk(route, FRAME, way).estimate).toMatchObject({
|
||||
kind: 'straight_line',
|
||||
why: 'ferry_only',
|
||||
position: 2,
|
||||
});
|
||||
// No crossing named, the way stands.
|
||||
expect(footWayOf({ leg: { line }, parts, ferryLegs: [] })).toMatchObject({ kind: 'routed' });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -211,3 +211,94 @@ describe('server Roadtrip router', () => {
|
||||
expect(await router.profiles()).toContain('plugin:scenic/car');
|
||||
});
|
||||
});
|
||||
|
||||
describe('server Roadtrip router, a walk on foot only (CW-12)', () => {
|
||||
const encode = (value: number) => {
|
||||
let remaining = value < 0 ? ~(value << 1) : value << 1;
|
||||
let encoded = '';
|
||||
while (remaining >= 32) {
|
||||
encoded += String.fromCharCode((32 | (remaining & 31)) + 63);
|
||||
remaining >>>= 5;
|
||||
}
|
||||
return encoded + String.fromCharCode(remaining + 63);
|
||||
};
|
||||
const shape = encode(48000000) + encode(10000000) + encode(1000000) + encode(1000000);
|
||||
const valhallaLegs = (legs: unknown[]) => new Response(JSON.stringify({ trip: { legs } }));
|
||||
const walked = { shape, summary: { length: 1.4, time: 1000, has_ferry: false } };
|
||||
// Measured on Venice: the boat leg as FOSSGIS answers it, boarding at type 28 with ferry true.
|
||||
const byBoat = {
|
||||
shape,
|
||||
summary: { length: 1.9, time: 1250, has_ferry: true },
|
||||
maneuvers: [{ type: 1 }, { type: 28, ferry: true }, { type: 29 }],
|
||||
};
|
||||
|
||||
it('asks Valhalla on foot with no point bound to a boat line, and names the legs that still cross by boat', async () => {
|
||||
vi.mocked(safeFetchAdminConfigured).mockResolvedValueOnce(valhallaLegs([walked, byBoat]));
|
||||
const route = await setup().router.route(1, 1, 0, points, 'walking', [], { footOnly: true });
|
||||
const [url, init] = vi.mocked(safeFetchAdminConfigured).mock.calls[0] as [string, { body: string }];
|
||||
expect(url).toBe('https://valhalla1.openstreetmap.de/route');
|
||||
const body = JSON.parse(init.body) as { locations: Array<Record<string, unknown>>; costing_options: unknown };
|
||||
expect(
|
||||
body.locations.every((location) => (location.search_filter as { exclude_ferry: boolean }).exclude_ferry),
|
||||
).toBe(true);
|
||||
expect(body.costing_options).toEqual({ pedestrian: { use_ferry: 0 } });
|
||||
expect(route.ferryLegs).toEqual([1]);
|
||||
expect(route.parts).toEqual([
|
||||
{ distance: 1400, duration: 1000 },
|
||||
{ distance: 1900, duration: 1250 },
|
||||
]);
|
||||
expect(route.snapped).toHaveLength(3);
|
||||
});
|
||||
|
||||
it('reads a crossing off OSRM steps where no Valhalla is asked, and keeps the foot-only answer apart in the cache', async () => {
|
||||
vi.mocked(safeFetchAdminConfigured).mockResolvedValueOnce(
|
||||
new Response(
|
||||
JSON.stringify({
|
||||
code: 'Ok',
|
||||
routes: [
|
||||
{
|
||||
distance: 3000,
|
||||
duration: 300,
|
||||
geometry: { coordinates: points.map((p) => [p.lng, p.lat]) },
|
||||
legs: [
|
||||
{ distance: 1000, duration: 100, steps: [{ mode: 'walking' }] },
|
||||
{ distance: 2000, duration: 200, steps: [{ mode: 'walking' }, { mode: 'ferry' }] },
|
||||
],
|
||||
},
|
||||
],
|
||||
}),
|
||||
),
|
||||
);
|
||||
const { router } = setup({ routing_base_url: 'http://router.internal' });
|
||||
const route = await router.route(1, 1, 0, points, 'walking', [], { footOnly: true });
|
||||
expect(safeFetchAdminConfigured).toHaveBeenCalledWith(expect.stringContaining('steps=true'), expect.anything());
|
||||
expect(route.ferryLegs).toEqual([1]);
|
||||
expect(route.parts).toEqual([
|
||||
{ distance: 1000, duration: 100 },
|
||||
{ distance: 2000, duration: 200 },
|
||||
]);
|
||||
// The same points asked without the option are another question, answered without ferries named.
|
||||
const plain = router.route(1, 1, 0, points, 'walking', []);
|
||||
await vi.runAllTimersAsync();
|
||||
expect(await plain).not.toHaveProperty('ferryLegs');
|
||||
expect(safeFetchAdminConfigured).toHaveBeenLastCalledWith(
|
||||
expect.stringContaining('steps=false'),
|
||||
expect.anything(),
|
||||
);
|
||||
});
|
||||
|
||||
it('falls back to OSRM on foot when Valhalla fails, and leaves a drive as it was', async () => {
|
||||
vi.mocked(safeFetchAdminConfigured).mockResolvedValueOnce(new Response('', { status: 503 }));
|
||||
const pending = setup().router.route(1, 1, 0, points, 'walking', [], { footOnly: true });
|
||||
await vi.runAllTimersAsync();
|
||||
expect((await pending).ferryLegs).toEqual([]);
|
||||
expect(safeFetchAdminConfigured).toHaveBeenLastCalledWith(
|
||||
expect.stringContaining('routed-foot'),
|
||||
expect.anything(),
|
||||
);
|
||||
|
||||
const drive = await setup().router.route(1, 1, 0, points, 'driving', [], { footOnly: true });
|
||||
expect(drive).not.toHaveProperty('ferryLegs');
|
||||
expect(safeFetchAdminConfigured).toHaveBeenLastCalledWith(expect.stringContaining('routed-car'), expect.anything());
|
||||
});
|
||||
});
|
||||
|
||||
@@ -365,6 +365,47 @@ describe('TourVisitsService', () => {
|
||||
expect(t.realtime.broadcastMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('TOUR-VISITS-011: remaining shares no walking time out along a ferry leg the travellers took (CW-12)', async () => {
|
||||
const { trip, day1 } = await fixture();
|
||||
const island = await makePlace(orm(), trip.id, {
|
||||
name: 'Giudecca',
|
||||
route_geometry: JSON.stringify([
|
||||
[48.1, 11.5],
|
||||
[48.11, 11.51],
|
||||
[48.12, 11.52],
|
||||
[48.13, 11.53],
|
||||
]),
|
||||
});
|
||||
await makeTour(orm(), island.id, { tourTypeRef: 'walk', duration: 60 });
|
||||
const ferry = {
|
||||
kind: 'ferry',
|
||||
geometry: [
|
||||
[48.11, 11.51],
|
||||
[48.12, 11.52],
|
||||
],
|
||||
crossing: [0, 1],
|
||||
minutes: 7,
|
||||
walk_minutes: 0,
|
||||
};
|
||||
await addTourWaypoints(orm(), island.id, [
|
||||
{ lat: 48.1, lng: 11.5, station_key: 'stop-zattere', stay_minutes: 0 },
|
||||
{ lat: 48.11, lng: 11.51, station_key: 'stop-pier', stay_minutes: 0, fixed_leg: JSON.stringify(ferry) },
|
||||
{ lat: 48.12, lng: 11.52, station_key: 'stop-redentore', stay_minutes: 20 },
|
||||
{ lat: 48.13, lng: 11.53, station_key: 'stop-garden', stay_minutes: 30 },
|
||||
]);
|
||||
const onDay1 = await makeDayAssignment(orm(), day1.id, island.id);
|
||||
await markStationVisit(orm(), onDay1.id, 'stop-zattere', 'visited');
|
||||
|
||||
const remaining = await visits.remaining(trip.id, island.id, day1.id);
|
||||
// Two stretches are walked, one is crossed by boat: the landing is passed after half the walk, not two thirds.
|
||||
expect(remaining.open_stations.map((station) => [station.key, station.walk_minutes_from_reference])).toEqual([
|
||||
['stop-pier', 30],
|
||||
['stop-redentore', 30],
|
||||
['stop-garden', 60],
|
||||
]);
|
||||
expect(remaining.walking).toMatchObject({ total_minutes: 60, remaining_minutes: 60 });
|
||||
});
|
||||
|
||||
it('TOUR-VISITS-009: a loop keeps its way back once every station is done, and a walk not on that day is a 404', async () => {
|
||||
const { trip, day1, day3, walk } = await fixture();
|
||||
const loop = await makePlace(orm(), trip.id, {
|
||||
|
||||
Reference in New Issue
Block a user