mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 00:20:07 +00:00
feat(tours): assistant takes found places into saved tours and route files from the chat
P6: insert_tour_stop and remove_tour_stop take a place into a saved hike or city walk as one stop and out again, each the other's undo, with change cards in the chat. The planner's insertion rule (poiInsertion) moved to shared so the planner and the server place a stop the same way. "+ Tour" on a found place holds it as a stop of the saved tour open in the planner. P7: GPX, KML and KMZ files attached in the chat are read into their tracks and each is held as a change that takes it in as a hike through import_tour_gpx, undoable per track; the GPX text stays on the held call.
This commit is contained in:
@@ -0,0 +1,190 @@
|
||||
import {
|
||||
alongRouteM,
|
||||
chosenAfterId,
|
||||
defaultAfterId,
|
||||
insertionBlock,
|
||||
insertionPreview,
|
||||
insertionSlots,
|
||||
placesInTour,
|
||||
straightDetourM,
|
||||
withPointAfter,
|
||||
withPointAppended,
|
||||
type InsertionPoint,
|
||||
} from './poi-insertion';
|
||||
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
// TOUR-POI-INSERT-001 to TOUR-POI-INSERT-012, moved here from the planner with the module.
|
||||
|
||||
const point = (id: string, lat: number, lng: number, over: Partial<InsertionPoint> = {}): InsertionPoint => ({
|
||||
id,
|
||||
lat,
|
||||
lng,
|
||||
role: 'via',
|
||||
...over,
|
||||
});
|
||||
|
||||
const A = point('a', 47.0, 11.0, { role: 'start' });
|
||||
const B = point('b', 47.01, 11.0);
|
||||
const C = point('c', 47.02, 11.0, { role: 'end' });
|
||||
const NEW = point('new', 47.005, 11.001);
|
||||
|
||||
describe('placing a found place in the tour (PLN-03)', () => {
|
||||
it('TOUR-POI-INSERT-001: goes in right after the point chosen, as a stop the router plans to', () => {
|
||||
expect(withPointAfter([A, B, C], 'a', NEW)?.map((p) => p.id)).toEqual(['a', 'new', 'b', 'c']);
|
||||
expect(withPointAfter([A, B, C], 'a', NEW)?.[1]).toMatchObject({ role: 'via' });
|
||||
// After the last point the tour goes on to it.
|
||||
expect(withPointAfter([A, B, C], 'c', NEW)?.map((p) => p.id)).toEqual(['a', 'b', 'c', 'new']);
|
||||
});
|
||||
|
||||
it('TOUR-POI-INSERT-002: never cuts a fixed line or a stretch drawn by hand', () => {
|
||||
const ferrata = point('b', 47.01, 11.0, {
|
||||
fixedLeg: {
|
||||
kind: 'ferrata',
|
||||
ref: 'way/1',
|
||||
name: null,
|
||||
geometry: [
|
||||
[47.01, 11.0],
|
||||
[47.02, 11.0],
|
||||
],
|
||||
},
|
||||
});
|
||||
const free = point('b', 47.01, 11.0, {
|
||||
fixedLeg: {
|
||||
kind: 'free',
|
||||
geometry: [
|
||||
[47.01, 11.0],
|
||||
[47.02, 11.0],
|
||||
],
|
||||
},
|
||||
});
|
||||
expect(insertionBlock([A, ferrata, C], 'b')).toBe('fixed');
|
||||
expect(insertionBlock([A, free, C], 'b')).toBe('free');
|
||||
expect(withPointAfter([A, free, C], 'b', NEW)).toBeNull();
|
||||
expect(insertionBlock([A, free, C], 'a')).toBeNull();
|
||||
});
|
||||
|
||||
it('TOUR-POI-INSERT-003: nothing goes after the way back of a loop, or after a point that is gone', () => {
|
||||
const back = point('back', 47.0, 11.0, { role: 'end' });
|
||||
expect(insertionBlock([A, B, back], 'back')).toBe('none');
|
||||
expect(insertionBlock([A, B, C], 'gone')).toBe('none');
|
||||
expect(withPointAfter([A, B, back], 'back', NEW)).toBeNull();
|
||||
});
|
||||
|
||||
it('TOUR-POI-INSERT-004: suggests the last point before the place along the route', () => {
|
||||
const route: Array<[number, number]> = [
|
||||
[47.0, 11.0],
|
||||
[47.01, 11.0],
|
||||
[47.02, 11.0],
|
||||
];
|
||||
// About 1.6 km along: after B (1.1 km), before C (2.2 km).
|
||||
expect(defaultAfterId([A, B, C], route, 1600)).toBe('b');
|
||||
expect(defaultAfterId([A, B, C], route, 100)).toBe('a');
|
||||
// Without a route the points themselves stand in for the line.
|
||||
expect(defaultAfterId([A, B, C], null, 1600)).toBe('b');
|
||||
});
|
||||
|
||||
it('TOUR-POI-INSERT-005: skips a point that cannot take a stop, and has nothing to suggest without one', () => {
|
||||
const free = point('b', 47.01, 11.0, {
|
||||
fixedLeg: {
|
||||
kind: 'free',
|
||||
geometry: [
|
||||
[47.01, 11.0],
|
||||
[47.02, 11.0],
|
||||
],
|
||||
},
|
||||
});
|
||||
expect(defaultAfterId([A, free, C], null, 1600)).toBe('a');
|
||||
expect(defaultAfterId([], null, 0)).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('the slots a found place can go into (PLN-04)', () => {
|
||||
const back = point('back', 47.0, 11.0, { role: 'end' });
|
||||
|
||||
it('TOUR-POI-INSERT-006: one slot per point, between it and the next, the last one as the new end', () => {
|
||||
expect(insertionSlots([A, B, C])).toEqual([
|
||||
{ afterId: 'a', beforeId: 'b', block: null },
|
||||
{ afterId: 'b', beforeId: 'c', block: null },
|
||||
{ afterId: 'c', beforeId: null, block: null },
|
||||
]);
|
||||
// A loop has no new end: the slot after its way back is listed as one that cannot take the place.
|
||||
expect(insertionSlots([A, B, back])[2]).toEqual({ afterId: 'back', beforeId: null, block: 'none' });
|
||||
});
|
||||
|
||||
it('TOUR-POI-INSERT-007: the preview runs through the place to the next point, or ends on it as the new end', () => {
|
||||
const place = { lat: 47.03, lng: 11.0 };
|
||||
expect(insertionPreview([A, B, C], 'b', place)).toEqual([
|
||||
[47.01, 11.0],
|
||||
[47.03, 11.0],
|
||||
[47.02, 11.0],
|
||||
]);
|
||||
expect(insertionPreview([A, B, C], 'c', place)).toEqual([
|
||||
[47.02, 11.0],
|
||||
[47.03, 11.0],
|
||||
]);
|
||||
expect(insertionPreview([A, B, back], 'back', place)).toBeNull();
|
||||
});
|
||||
|
||||
it('TOUR-POI-INSERT-008: the detour as the crow flies: the way round less the stretch it replaces', () => {
|
||||
// 1.11 km on to the place and 1.11 km back, instead of the 1.11 km between the points.
|
||||
const between = straightDetourM([
|
||||
[47.01, 11.0],
|
||||
[47.02, 11.0],
|
||||
[47.01, 11.0],
|
||||
]);
|
||||
expect(between).toBeGreaterThan(2200);
|
||||
expect(between).toBeLessThan(2250);
|
||||
// A place on the way adds nothing.
|
||||
expect(
|
||||
straightDetourM([
|
||||
[47.0, 11.0],
|
||||
[47.01, 11.0],
|
||||
[47.02, 11.0],
|
||||
]),
|
||||
).toBeLessThan(1);
|
||||
// As the new end, the whole way to it.
|
||||
expect(
|
||||
straightDetourM([
|
||||
[47.02, 11.0],
|
||||
[47.03, 11.0],
|
||||
]),
|
||||
).toBeGreaterThan(1100);
|
||||
});
|
||||
|
||||
it('TOUR-POI-INSERT-009: keeps the point picked for the place while it is there, the suggestion otherwise', () => {
|
||||
const place = { id: 'node:1', along_m: 1600 };
|
||||
expect(chosenAfterId([A, B, C], null, place, { poiId: 'node:1', afterId: 'c' })).toBe('c');
|
||||
// Picked for another place, or a point undone since.
|
||||
expect(chosenAfterId([A, B, C], null, place, { poiId: 'node:2', afterId: 'c' })).toBe('b');
|
||||
expect(chosenAfterId([A, B, C], null, place, { poiId: 'node:1', afterId: 'gone' })).toBe('b');
|
||||
expect(chosenAfterId([A, B, C], null, place, null)).toBe('b');
|
||||
});
|
||||
|
||||
it('TOUR-POI-INSERT-010: tells the places that are a point of the tour already by their spot', () => {
|
||||
const places = [
|
||||
{ id: 'node:1', lat: B.lat, lng: B.lng },
|
||||
{ id: 'node:2', lat: B.lat + 0.001, lng: B.lng },
|
||||
];
|
||||
expect([...placesInTour(places, [A, B, C])]).toEqual(['node:1']);
|
||||
expect(placesInTour(places, [A, C]).size).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('a stop the assistant takes in (P6)', () => {
|
||||
it('TOUR-POI-INSERT-011: a new end goes after the last point, or before the way back of a loop', () => {
|
||||
const back = point('back', 47.0, 11.0, { role: 'end' });
|
||||
expect(withPointAppended([A, B, C], NEW).map((p) => p.id)).toEqual(['a', 'b', 'c', 'new']);
|
||||
expect(withPointAppended([A, B, C], NEW)[3]).toMatchObject({ role: 'end' });
|
||||
expect(withPointAppended([A, B, back], NEW).map((p) => p.id)).toEqual(['a', 'b', 'new', 'back']);
|
||||
expect(withPointAppended([A, B, back], NEW)[2]).toMatchObject({ role: 'via' });
|
||||
});
|
||||
|
||||
it('TOUR-POI-INSERT-012: never suggests a shaping point, and reads how far along the route a place lies', () => {
|
||||
const shaping = point('s', 47.01, 11.0, { shaping: true });
|
||||
expect(defaultAfterId([A, shaping, C], null, 1600)).toBe('a');
|
||||
const along = alongRouteM([A, B, C], null, { lat: 47.015, lng: 11.0 });
|
||||
expect(along).toBeGreaterThan(1600);
|
||||
expect(along).toBeLessThan(1700);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,178 @@
|
||||
import { haversineMetres } from '../geo/haversine';
|
||||
import { nearnessToLine } from './route-corridor';
|
||||
import { isClosedLoop } from './tour-walk';
|
||||
import type { TourFixedLeg } from './tours.schema';
|
||||
|
||||
/**
|
||||
* PLN-03 and PLN-04: where a place found along a tour can go in as a stop,
|
||||
* the same answer for the planner in the browser and for the assistant's
|
||||
* insert_tour_stop on the server. Plain list operations on the ordered points
|
||||
* of a tour; neither side's own point type is needed, only its id, spot,
|
||||
* role and the fixed line its leg to the next point keeps.
|
||||
*/
|
||||
export interface InsertionPoint {
|
||||
id: string;
|
||||
lat: number;
|
||||
lng: number;
|
||||
role: string;
|
||||
fixedLeg?: TourFixedLeg | null;
|
||||
shaping?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Why a place cannot go in after a point (PLN-03): the leg after it is a
|
||||
* fixed line (a via ferrata, a portage) or drawn by hand, which a new point in
|
||||
* between would cut or redraw without being asked; or there is no leg after it
|
||||
* to go into (the way back of a loop, a point that is gone).
|
||||
*/
|
||||
export type InsertionBlock = 'fixed' | 'free' | 'none';
|
||||
|
||||
/**
|
||||
* The points with a new end: after the last point, or for a loop between its
|
||||
* last stop and the way back to the start, so the tour still comes back.
|
||||
*/
|
||||
export function withPointAppended<T extends { lat: number; lng: number; role: string }>(
|
||||
points: readonly T[],
|
||||
point: T,
|
||||
): T[] {
|
||||
if (!isClosedLoop(points)) return [...points, { ...point, role: 'end' }];
|
||||
const end = points[points.length - 1];
|
||||
return end ? [...points.slice(0, -1), { ...point, role: 'via' }, end] : [{ ...point, role: 'end' }];
|
||||
}
|
||||
|
||||
/** What would stop a place going in after `afterId`, or null when it can. */
|
||||
export function insertionBlock(points: readonly InsertionPoint[], afterId: string): InsertionBlock | null {
|
||||
const index = points.findIndex((point) => point.id === afterId);
|
||||
if (index < 0) return 'none';
|
||||
const last = index === points.length - 1;
|
||||
// After the last point the tour goes on to the place; after the way back of a loop there is nothing.
|
||||
if (last) return isClosedLoop(points) ? 'none' : null;
|
||||
const leg = points[index]?.fixedLeg;
|
||||
if (leg?.kind === 'free') return 'free';
|
||||
if (leg) return 'fixed';
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The points with a new stop right after `afterId`: in a leg the router plans,
|
||||
* between that point and the next, or as the new end after the last. Null
|
||||
* where {@link insertionBlock} says it cannot go; nothing else is changed.
|
||||
*/
|
||||
export function withPointAfter<T extends InsertionPoint>(points: readonly T[], afterId: string, point: T): T[] | null {
|
||||
if (insertionBlock(points, afterId) !== null) return null;
|
||||
const index = points.findIndex((candidate) => candidate.id === afterId);
|
||||
if (index === points.length - 1) return withPointAppended(points, point);
|
||||
return [...points.slice(0, index + 1), { ...point, role: 'via' }, ...points.slice(index + 1)];
|
||||
}
|
||||
|
||||
/**
|
||||
* The point a place found at `alongM` metres along the route most likely
|
||||
* follows: the last point before it along the line, where a stop can go in.
|
||||
* The first point that can take one when none lies before it. A shaping point
|
||||
* only steers the line, so a stop never goes in after one.
|
||||
*/
|
||||
export function defaultAfterId(
|
||||
points: readonly InsertionPoint[],
|
||||
route: ReadonlyArray<readonly [number, number, ...number[]]> | null,
|
||||
alongM: number,
|
||||
): string | null {
|
||||
const open = points.filter((point) => point.shaping !== true && insertionBlock(points, point.id) === null);
|
||||
if (!open.length) return null;
|
||||
const line = route && route.length > 1 ? route : points.map((point): [number, number] => [point.lat, point.lng]);
|
||||
let chosen = open[0]?.id ?? null;
|
||||
for (const point of open) {
|
||||
const along = nearnessToLine(point, line)?.alongM ?? 0;
|
||||
if (along <= alongM) chosen = point.id;
|
||||
}
|
||||
return chosen;
|
||||
}
|
||||
|
||||
/** How far along the route a place lies, in metres, read from the line or the points joined straight. */
|
||||
export function alongRouteM(
|
||||
points: readonly InsertionPoint[],
|
||||
route: ReadonlyArray<readonly [number, number, ...number[]]> | null,
|
||||
place: { lat: number; lng: number },
|
||||
): number {
|
||||
const line = route && route.length > 1 ? route : points.map((point): [number, number] => [point.lat, point.lng]);
|
||||
return nearnessToLine(place, line)?.alongM ?? 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* The point a place goes in after: the one picked for it while that point is
|
||||
* still there (not undone, not removed), else the suggestion.
|
||||
*/
|
||||
export function chosenAfterId(
|
||||
points: readonly InsertionPoint[],
|
||||
route: ReadonlyArray<readonly [number, number, ...number[]]> | null,
|
||||
place: { id: string; along_m: number },
|
||||
picked: { poiId: string; afterId: string } | null,
|
||||
): string | null {
|
||||
if (picked?.poiId === place.id && points.some((point) => point.id === picked.afterId)) return picked.afterId;
|
||||
return defaultAfterId(points, route, place.along_m);
|
||||
}
|
||||
|
||||
/**
|
||||
* PLN-04: where a place can go, one slot per point: between it and the next
|
||||
* point, or after the last as the new end, which makes the tour longer. A
|
||||
* slot that cannot take it says why, so the list can show it dimmed.
|
||||
*/
|
||||
export interface InsertionSlot {
|
||||
afterId: string;
|
||||
/** The point it would go in before; null where it would become the new end. */
|
||||
beforeId: string | null;
|
||||
block: InsertionBlock | null;
|
||||
}
|
||||
|
||||
export function insertionSlots(points: readonly InsertionPoint[]): InsertionSlot[] {
|
||||
return points.map((point, index) => ({
|
||||
afterId: point.id,
|
||||
beforeId: points[index + 1]?.id ?? null,
|
||||
block: insertionBlock(points, point.id),
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* The straight lines a place would add in the slot after `afterId`: from that
|
||||
* point to the place and on to the next, or only to the place as the new
|
||||
* end. Null where it cannot go there.
|
||||
*/
|
||||
export function insertionPreview(
|
||||
points: readonly InsertionPoint[],
|
||||
afterId: string,
|
||||
place: { lat: number; lng: number },
|
||||
): Array<[number, number]> | null {
|
||||
if (insertionBlock(points, afterId) !== null) return null;
|
||||
const index = points.findIndex((point) => point.id === afterId);
|
||||
const from = points[index];
|
||||
if (!from) return null;
|
||||
const to = points[index + 1];
|
||||
const line: Array<[number, number]> = [
|
||||
[from.lat, from.lng],
|
||||
[place.lat, place.lng],
|
||||
];
|
||||
return to ? [...line, [to.lat, to.lng]] : line;
|
||||
}
|
||||
|
||||
/** How much longer the preview's lines make the tour, as the crow flies; the route planned after says it exactly. */
|
||||
export function straightDetourM(line: ReadonlyArray<readonly [number, number]>): number {
|
||||
const legs = (path: ReadonlyArray<readonly [number, number]>) =>
|
||||
path.slice(1).reduce((sum, [lat, lng], index) => {
|
||||
const [fromLat, fromLng] = path[index] ?? [lat, lng];
|
||||
return sum + haversineMetres(fromLat, fromLng, lat, lng);
|
||||
}, 0);
|
||||
const first = line[0];
|
||||
const last = line[line.length - 1];
|
||||
const replaced = line.length > 2 && first && last ? legs([first, last]) : 0;
|
||||
return Math.max(0, legs(line) - replaced);
|
||||
}
|
||||
|
||||
/** The places of a search that are a point of the tour already, told by where they lie: a taken place keeps its spot. */
|
||||
export function placesInTour(
|
||||
places: ReadonlyArray<{ id: string; lat: number; lng: number }>,
|
||||
points: ReadonlyArray<{ lat: number; lng: number }>,
|
||||
): Set<string> {
|
||||
const spots = new Set(points.map((point) => `${point.lat.toFixed(6)},${point.lng.toFixed(6)}`));
|
||||
return new Set(
|
||||
places.filter((place) => spots.has(`${place.lat.toFixed(6)},${place.lng.toFixed(6)}`)).map((place) => place.id),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
import {
|
||||
tourStopInsertRequestSchema,
|
||||
tourStopInsertResultSchema,
|
||||
tourStopRemoveRequestSchema,
|
||||
tourStopRemoveResultSchema,
|
||||
} from './tour-stop.schema';
|
||||
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
const stop = { lat: 47.6, lng: 11.3, name: 'Herzogstandhaus', poi_category: 'shelter' };
|
||||
const tour = {
|
||||
place_id: 4,
|
||||
name: 'Herzogstand',
|
||||
tour_type: 'hike',
|
||||
revision: 3,
|
||||
distance_km: 9.1,
|
||||
minutes: 210,
|
||||
route_pending: false,
|
||||
};
|
||||
|
||||
describe('a stop taken into a saved tour (P6)', () => {
|
||||
it('TOUR-STOP-SCHEMA-001: takes a stop against the revision, after a key or where it lies along the way', () => {
|
||||
expect(tourStopInsertRequestSchema.safeParse({ placeId: 4, expected_revision: 2, stop }).success).toBe(true);
|
||||
const after = { placeId: 4, expected_revision: 2, stop, after_key: 'abc123' };
|
||||
expect(tourStopInsertRequestSchema.safeParse(after).success).toBe(true);
|
||||
expect(tourStopInsertRequestSchema.safeParse({ placeId: 4, stop }).success).toBe(false);
|
||||
expect(tourStopInsertRequestSchema.safeParse({ ...after, after_key: 'no spaces' }).success).toBe(false);
|
||||
});
|
||||
|
||||
it('TOUR-STOP-SCHEMA-002: refuses a stop off the globe and fields it does not know', () => {
|
||||
const off = { placeId: 4, expected_revision: 2, stop: { ...stop, lat: 91 } };
|
||||
expect(tourStopInsertRequestSchema.safeParse(off).success).toBe(false);
|
||||
const extra = { placeId: 4, expected_revision: 2, stop: { ...stop, stay: 5 } };
|
||||
expect(tourStopInsertRequestSchema.safeParse(extra).success).toBe(false);
|
||||
expect(tourStopInsertRequestSchema.safeParse({ placeId: 4, expected_revision: 2, stop, x: 1 }).success).toBe(false);
|
||||
});
|
||||
|
||||
it('TOUR-STOP-SCHEMA-003: takes a stop out by its key, against the revision', () => {
|
||||
expect(tourStopRemoveRequestSchema.safeParse({ placeId: 4, expected_revision: 3, key: 'abc123' }).success).toBe(
|
||||
true,
|
||||
);
|
||||
expect(tourStopRemoveRequestSchema.safeParse({ placeId: 4, key: 'abc123' }).success).toBe(false);
|
||||
expect(tourStopRemoveRequestSchema.safeParse({ placeId: 4, expected_revision: 0, key: 'abc123' }).success).toBe(
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
it('TOUR-STOP-SCHEMA-004: describes what an insert and a removal answer', () => {
|
||||
const point = { key: 'abc123', ...stop };
|
||||
const inserted = {
|
||||
tour,
|
||||
stop: { ...point, after_key: 'start1', after_name: 'Parking' },
|
||||
before: { distance_km: 8.2, minutes: 190 },
|
||||
};
|
||||
expect(tourStopInsertResultSchema.safeParse(inserted).success).toBe(true);
|
||||
expect(tourStopRemoveResultSchema.safeParse({ tour, removed: { ...point, after_key: null } }).success).toBe(true);
|
||||
expect(tourStopRemoveResultSchema.safeParse({ tour: { ...tour, tour_type: 'bike' }, removed: point }).success).toBe(
|
||||
false,
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,101 @@
|
||||
import { idSchema } from '../common/primitives.schema';
|
||||
import { stationKeySchema, tourRevisionSchema, tourWaypointSchema } from './tours.schema';
|
||||
|
||||
import { z } from 'zod';
|
||||
|
||||
/**
|
||||
* P6: a place found along a saved tour (a search result, a place the
|
||||
* traveller names) taken in as one stop, and the same stop taken out again.
|
||||
* The server lays the stop in with the planner's own rule (poi-insertion.ts):
|
||||
* after the point named, or where it most likely belongs along the route, and
|
||||
* never into a leg drawn by hand or a fixed line. A hike plans its way anew
|
||||
* through the points, a city walk saves the stop as a station; both against
|
||||
* the revision the tour was read at.
|
||||
*/
|
||||
|
||||
const { lat, lng, name, poi_category, opening_hours } = tourWaypointSchema.shape;
|
||||
|
||||
const placeId = idSchema.describe('The place id of the tour, as list_tours gives it');
|
||||
const expectedRevision = tourRevisionSchema.describe(
|
||||
'The revision of the tour as last read (get_tour_plan or list_tours); a tour changed since is refused, not overwritten',
|
||||
);
|
||||
|
||||
const tourStopSchema = z
|
||||
.object({
|
||||
lat,
|
||||
lng,
|
||||
name: name.describe('The name of the place the stop is, such as a hut, a café or a viewpoint'),
|
||||
poi_category: poi_category.describe(
|
||||
'What kind of place it is, where it is one: peak, shelter, drinking_water, viewpoint, restaurant, museum',
|
||||
),
|
||||
opening_hours: opening_hours.describe(
|
||||
'On a city walk: the opening hours of the place as OpenStreetMap writes them, where known',
|
||||
),
|
||||
})
|
||||
.strict();
|
||||
export type TourStop = z.infer<typeof tourStopSchema>;
|
||||
|
||||
export const tourStopInsertRequestSchema = z
|
||||
.object({
|
||||
placeId,
|
||||
expected_revision: expectedRevision,
|
||||
stop: tourStopSchema.describe('The place taken in as a stop: where it is and what it is called'),
|
||||
after_key: stationKeySchema
|
||||
.optional()
|
||||
.describe(
|
||||
'The key of the point of the tour the stop comes after, as get_tour_plan gives it; left out, the stop goes after the last point before it along the route',
|
||||
),
|
||||
})
|
||||
.strict();
|
||||
export type TourStopInsertRequest = z.infer<typeof tourStopInsertRequestSchema>;
|
||||
|
||||
export const tourStopRemoveRequestSchema = z
|
||||
.object({
|
||||
placeId,
|
||||
expected_revision: expectedRevision,
|
||||
key: stationKeySchema.describe('The key of the stop to take out, as get_tour_plan or insert_tour_stop gives it'),
|
||||
})
|
||||
.strict();
|
||||
export type TourStopRemoveRequest = z.infer<typeof tourStopRemoveRequestSchema>;
|
||||
|
||||
/** The tour types a stop is taken in or out of over the assistant; any other type in the planner. */
|
||||
export const TOUR_STOP_TYPES = ['hike', 'walk'] as const;
|
||||
|
||||
/** The tour as an insert or a removal of a stop saved it. */
|
||||
const tourStopTourSchema = z.object({
|
||||
place_id: idSchema,
|
||||
name: z.string(),
|
||||
tour_type: z.enum(TOUR_STOP_TYPES),
|
||||
revision: tourRevisionSchema,
|
||||
distance_km: z.number().nullable(),
|
||||
minutes: z.number().nullable(),
|
||||
route_pending: z.boolean(),
|
||||
});
|
||||
|
||||
/** One stop as an answer names it: its key (null where the tour gave it none), its place and its name. */
|
||||
const tourStopPointSchema = z.object({
|
||||
key: stationKeySchema.nullable(),
|
||||
lat: z.number(),
|
||||
lng: z.number(),
|
||||
name: z.string().nullable(),
|
||||
poi_category: z.string().nullable(),
|
||||
});
|
||||
|
||||
/**
|
||||
* What insert_tour_stop answers: the tour as saved, the stop with its key and
|
||||
* the point it came after, and the distance and time before and after as the
|
||||
* tour stored them (null where not known).
|
||||
*/
|
||||
export const tourStopInsertResultSchema = z.object({
|
||||
tour: tourStopTourSchema,
|
||||
stop: tourStopPointSchema.extend({ after_key: stationKeySchema.nullable(), after_name: z.string().nullable() }),
|
||||
before: z.object({ distance_km: z.number().nullable(), minutes: z.number().nullable() }),
|
||||
});
|
||||
export type TourStopInsertResult = z.infer<typeof tourStopInsertResultSchema>;
|
||||
|
||||
/** What remove_tour_stop answers: the tour as saved and the stop it took out, with the point it came after. */
|
||||
export const tourStopRemoveResultSchema = z.object({
|
||||
tour: tourStopTourSchema,
|
||||
removed: tourStopPointSchema.extend({ after_key: stationKeySchema.nullable() }),
|
||||
});
|
||||
export type TourStopRemoveResult = z.infer<typeof tourStopRemoveResultSchema>;
|
||||
Reference in New Issue
Block a user