mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-28 23:50:08 +00:00
feat(tours): keep a ski tour's piste router options, build and time
A ski tour now saves the options its legs were planned with and the piste data build they ran on, as one JSON column (a new migration, since the ski migrations have shipped on this branch); the server keeps only the options its discipline reads. Both stay off every other type. The refusal of a ski time is lifted: the piste router works one out, and the planner sends it only when every leg followed the piste data. get_tour_plan names the legs of a tour the router planned as routed, and list_tours says what the new fields hold.
This commit is contained in:
@@ -50,6 +50,7 @@ export class Tours {
|
||||
track_started_at?: string | null;
|
||||
track_ended_at?: string | null;
|
||||
ski_discipline?: TToursSkiDiscipline | null;
|
||||
ski_options?: string | null;
|
||||
tourTypeRef!: Ref<TourTypes>;
|
||||
tour_activities_collection = new Collection<TourActivities>(this);
|
||||
tour_activities_collection1 = new Collection<TourActivities>(this);
|
||||
@@ -181,6 +182,7 @@ export const ToursSchema = defineEntity({
|
||||
track_started_at: p.type(DbTimestampType).nullable(),
|
||||
track_ended_at: p.type(DbTimestampType).nullable(),
|
||||
ski_discipline: p.enum(() => ToursSkiDiscipline).nullable(),
|
||||
ski_options: p.text().nullable(),
|
||||
tourTypeRef: () => p.manyToOne(TourTypes).ref().joinColumn('tour_type').hidden().index('idx_tours_tour_type'),
|
||||
tour_activities_collection: () => p.oneToMany(TourActivities).mappedBy('place').hidden(),
|
||||
tour_activities_collection1: () => p.oneToMany(TourActivities).mappedBy('trackPlace').hidden(),
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
paddleLockSchema,
|
||||
paddleRegionBoundarySchema,
|
||||
paddleRegionGraphStatsSchema,
|
||||
skiRouteOptionsSchema,
|
||||
tourChangeSchema,
|
||||
tourFixedLegSchema,
|
||||
tourSourceHintChangeSchema,
|
||||
@@ -21,6 +22,7 @@ import {
|
||||
type PaddleLock,
|
||||
type PaddleRegionBoundary,
|
||||
type PaddleRegionGraphStats,
|
||||
type SkiRouteOptions,
|
||||
type TourChange,
|
||||
type TourFixedLeg,
|
||||
type TourSourceHintChange,
|
||||
@@ -191,6 +193,19 @@ export const TOUR_HIKING_PREFERENCES: JsonColumn<HikingPreferences | null> = {
|
||||
fallback: () => null,
|
||||
};
|
||||
|
||||
/** What a ski tour's legs were planned with: the piste router's options and the piste data build they ran on. */
|
||||
export interface TourSkiRoute {
|
||||
options: SkiRouteOptions;
|
||||
build: string | null;
|
||||
}
|
||||
|
||||
/** A ski tour's piste router options. A broken row reads as none, and the planner offers the defaults. */
|
||||
export const TOUR_SKI_ROUTE: JsonColumn<TourSkiRoute | null> = {
|
||||
column: 'tours.ski_options',
|
||||
schema: z.object({ options: skiRouteOptionsSchema, build: z.string().nullable() }).nullable(),
|
||||
fallback: () => null,
|
||||
};
|
||||
|
||||
/** A paddle object's own geometry (PAD-05A). A broken row has none, and the object is left out rather than drawn anywhere. */
|
||||
export const PADDLE_FEATURE_GEOMETRY: JsonColumn<PaddleGeometry | null> = {
|
||||
column: 'paddle_features.geometry',
|
||||
|
||||
@@ -37,4 +37,5 @@ export interface ToursTable {
|
||||
track_started_at: InsertOptional<string | null>;
|
||||
track_ended_at: InsertOptional<string | null>;
|
||||
ski_discipline: InsertOptional<string | null>;
|
||||
ski_options: InsertOptional<string | null>;
|
||||
}
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
import { Migration } from '@mikro-orm/migrations';
|
||||
|
||||
/**
|
||||
* A ski tour keeps what its legs were planned for: the piste router's options
|
||||
* (difficulty limit, lifts to avoid, pace and the rest) and the build of the
|
||||
* piste data they were planned on, as one JSON text written by the server
|
||||
* (`TOUR_SKI_ROUTE` in json-columns.ts). NULL for every other type, for an
|
||||
* imported track and for a ski tour saved before the router. Reopened, the
|
||||
* tour is planned with the same options, and a newer build of the piste data
|
||||
* can be offered instead of applied.
|
||||
*/
|
||||
export class Migration20200101046140_a_ski_tour_keeps_its_piste_router_options extends Migration {
|
||||
override name = 'Migration20200101046140_a_ski_tour_keeps_its_piste_router_options';
|
||||
|
||||
override up(): void {
|
||||
this.addSql('ALTER TABLE tours ADD COLUMN ski_options TEXT');
|
||||
}
|
||||
}
|
||||
@@ -45,6 +45,8 @@ export interface TourListRow {
|
||||
/** SKI-02: a ski tour's discipline and, for cross-country, its technique; NULL on every other type. */
|
||||
ski_discipline: string | null;
|
||||
ski_technique: string | null;
|
||||
/** A ski tour's piste router options and build, still JSON text; absent where a read does not take it. */
|
||||
ski_options?: string | null;
|
||||
boat_type: string | null;
|
||||
water_context: string | null;
|
||||
paddle_speed_kmh: number | null;
|
||||
@@ -123,6 +125,7 @@ export interface TourRow {
|
||||
ski_technique: string | null;
|
||||
track_started_at: string | null;
|
||||
track_ended_at: string | null;
|
||||
ski_options: string | null;
|
||||
}
|
||||
const _tourRowKeys: AssertRowKeys<TourRow, Tours> = true;
|
||||
|
||||
@@ -146,6 +149,8 @@ export interface TourInsert {
|
||||
/** SKI-02: a ski tour's discipline and technique; left out, NULL. */
|
||||
ski_discipline?: SkiDiscipline | null;
|
||||
ski_technique?: SkiTechnique | null;
|
||||
/** A ski tour's piste router options and build as JSON text; left out, NULL. */
|
||||
ski_options?: string | null;
|
||||
/** A paddle tour's boat, water and chosen speed; left out, a hike's NULLs. */
|
||||
boat_type?: PaddleBoatType | null;
|
||||
water_context?: PaddleWaterContext | null;
|
||||
@@ -305,6 +310,7 @@ export class ToursRepository extends TrekRepository<Tours> {
|
||||
't.run_pace_seconds_per_km as run_pace_seconds_per_km',
|
||||
't.ski_discipline as ski_discipline',
|
||||
't.ski_technique as ski_technique',
|
||||
't.ski_options as ski_options',
|
||||
't.boat_type as boat_type',
|
||||
't.water_context as water_context',
|
||||
't.paddle_speed_kmh as paddle_speed_kmh',
|
||||
@@ -771,6 +777,7 @@ export class ToursRepository extends TrekRepository<Tours> {
|
||||
run_pace_seconds_per_km: input.run_pace_seconds_per_km ?? null,
|
||||
ski_discipline: input.ski_discipline ?? null,
|
||||
ski_technique: input.ski_technique ?? null,
|
||||
ski_options: input.ski_options ?? null,
|
||||
boat_type: input.boat_type ?? null,
|
||||
water_context: input.water_context ?? null,
|
||||
paddle_speed_kmh: input.paddle_speed_kmh ?? null,
|
||||
@@ -862,6 +869,7 @@ export class ToursRepository extends TrekRepository<Tours> {
|
||||
run_pace_seconds_per_km: input.run_pace_seconds_per_km,
|
||||
ski_discipline: input.ski_discipline,
|
||||
ski_technique: input.ski_technique,
|
||||
...(input.ski_options !== undefined ? { ski_options: input.ski_options } : {}),
|
||||
boat_type: input.boat_type,
|
||||
water_context: input.water_context,
|
||||
paddle_speed_kmh: input.paddle_speed_kmh,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* The read half of ToursService that needs no database: a tour as it is
|
||||
* listed, and where it came from as its provenance names it.
|
||||
*/
|
||||
import { TOUR_HIKING_PREFERENCES, TOUR_TRACK_MARKS } from '../../db/json-columns';
|
||||
import { TOUR_HIKING_PREFERENCES, TOUR_SKI_ROUTE, TOUR_TRACK_MARKS } from '../../db/json-columns';
|
||||
import type { TourActivityRefRow } from '../../db/repositories/TourActivities.repository';
|
||||
import type { TourWaypointRow } from '../../db/repositories/TourWaypoints.repository';
|
||||
import type { TourListRow, TourProvenanceRow } from '../../db/repositories/Tours.repository';
|
||||
@@ -32,6 +32,13 @@ function stageStopsOrNull(points: Parameters<typeof tourStageStopsOf>[0]): TourL
|
||||
return stops.length > 0 ? stops : null;
|
||||
}
|
||||
|
||||
/** A ski tour's piste router options and the build its legs ran on, where it keeps them; nothing for any other tour. */
|
||||
function skiRouteFacts(r: TourListRow): Pick<TourListItem, 'ski_options' | 'ski_route_build'> {
|
||||
if (r.tour_type !== 'ski' || !r.ski_options) return {};
|
||||
const route = decodeJson(TOUR_SKI_ROUTE, r.ski_options, 'tour');
|
||||
return route ? { ski_options: route.options, ski_route_build: route.build } : {};
|
||||
}
|
||||
|
||||
/**
|
||||
* A tour as it is listed; a city walk with the stations its points make and their stays (CW-02, CW-03),
|
||||
* every tour with the recordings assigned to it and the tour it documents itself (ACT-01).
|
||||
@@ -64,6 +71,7 @@ export function tourItemOf(
|
||||
run_pace_seconds_per_km: r.run_pace_seconds_per_km,
|
||||
ski_discipline: r.ski_discipline as SkiDiscipline | null,
|
||||
ski_technique: r.ski_technique as SkiTechnique | null,
|
||||
...skiRouteFacts(r),
|
||||
boat_type: r.boat_type as PaddleBoatType | null,
|
||||
water_context: r.water_context as PaddleWaterContext | null,
|
||||
paddle_speed_kmh: r.paddle_speed_kmh,
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* or an update stores, the checks a write passes before its transaction, and
|
||||
* the keys its points keep.
|
||||
*/
|
||||
import { TOUR_HIKING_PREFERENCES } from '../../db/json-columns';
|
||||
import { TOUR_HIKING_PREFERENCES, TOUR_SKI_ROUTE } from '../../db/json-columns';
|
||||
import type { TourUpdate } from '../../db/repositories/Tours.repository';
|
||||
import { encodeJson } from '../../utils/json-column';
|
||||
import { badRequest } from '../common/domain-error';
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
maxTourMinutesFor,
|
||||
plannedTimeLimitMessage,
|
||||
plannedTourDurationMinutesSchema,
|
||||
skiOptionsForDiscipline,
|
||||
tourStageCountOf,
|
||||
tourStageIssues,
|
||||
tourWebsiteSchema,
|
||||
@@ -41,6 +42,17 @@ function skiFields(input: TourCreateCommand): Pick<TourUpdate, 'ski_discipline'
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* A save's piste router options as stored, with the build its legs ran on:
|
||||
* only a ski tour keeps them, and only the options its discipline reads.
|
||||
* Without options (an older client, a type without them) none are kept.
|
||||
*/
|
||||
function skiRouteField(input: TourCreateCommand): string | null {
|
||||
if (input.tour_type !== 'ski' || !input.ski_discipline || !input.ski_options) return null;
|
||||
const options = skiOptionsForDiscipline(input.ski_discipline, input.ski_options);
|
||||
return encodeJson(TOUR_SKI_ROUTE, { options, build: input.ski_route_build ?? null });
|
||||
}
|
||||
|
||||
/**
|
||||
* RUN-01: a save's run profile and pace as stored. Only a run keeps them;
|
||||
* another type takes them off. A run without a pace keeps none: its time stays
|
||||
@@ -92,6 +104,7 @@ export function tourRouteFields(input: TourCreateCommand): TourUpdate {
|
||||
bike_profile: input.tour_type === 'bike' ? (input.bike_profile ?? null) : null,
|
||||
...runFields(input),
|
||||
...skiFields(input),
|
||||
ski_options: skiRouteField(input),
|
||||
boat_type: input.boat_type ?? null,
|
||||
water_context: input.water_context ?? null,
|
||||
paddle_speed_kmh: input.paddle_speed_kmh ?? null,
|
||||
|
||||
@@ -61,8 +61,11 @@ function planOf({ detail, days, line, names }: PlanRead, run: WalkProgress | nul
|
||||
waypoints: planPoints(detail.tour.tour_type, named, run),
|
||||
// ACT-01: the recorded tracks assigned to the tour, with their values and without their lines.
|
||||
activities: (detail.activities ?? []).map(withoutLine),
|
||||
// SKI-02: a planned ski tour's legs are drawn straight between its points; no router planned them.
|
||||
legs: planLegs(detail.waypoints, { recorded, drawn: detail.tour.tour_type === 'ski' }),
|
||||
// SKI-02: a ski tour saved before the piste router, or with none of its legs planned by it, was drawn straight.
|
||||
legs: planLegs(detail.waypoints, {
|
||||
recorded,
|
||||
drawn: detail.tour.tour_type === 'ski' && !detail.tour.ski_route_build,
|
||||
}),
|
||||
line: saved,
|
||||
...(isWalk ? { run: run ? planRun(run) : null } : {}),
|
||||
derived: derivedFields(detail, { controlsFromTrack, line: saved, run }),
|
||||
@@ -102,7 +105,7 @@ export class ToursMcp {
|
||||
@Tool({
|
||||
name: 'list_tours',
|
||||
description:
|
||||
'List the saved tours of a trip (hikes, city walks, runs, bike tours, paddle tours, rides on horseback and ski and winter tours planned or imported in the Tours addon): name, type (hike, walk for a city walk, run, bike, kayak for a paddle tour, horse for a ride, or ski for a ski and winter tour; a ride and a ski tour have no time worked out, so their duration is null), where it came from (origin: trek, gpx for an imported GPX, KML or KMZ file, or wanderer), distance in km, ascent and descent in metres, the stored routing limit of a hike (max_hiking_difficulty, SAC T1 to T6) and its route choices (hiking_preferences: avoid_climbs for gentler ways, avoid_steps, avoid_ferries; weightings, never a grade of the path), the profile a bike tour is routed for (bike_profile: touring for paved cycle paths and quiet roads, road for asphalt, gravel for gravel and farm tracks, mtb for rough tracks; a routing preference, never a statement that a way is rideable or safe), the profile and pace of a run (run_profile: running for runnable, mostly paved ways in towns and parks, trail for forest tracks and natural paths up to mountain paths (T2); a routing preference, never a statement that a way can be run; run_pace_seconds_per_km, the pace the runners planned with, null while they entered none; its duration is the distance at that pace and nothing else, no climb, descent or difficulty is in it, and it is a plan, never a recorded time), the discipline of a ski tour (ski_discipline: alpine, snowboard, cross_country, touring for ski touring, snowshoe or winter_hike; snowshoeing and winter hiking are ski tours, a hike is summer only; ski_technique for cross-country only: classic, skating or unknown when the travellers did not know; a planned ski tour has every leg drawn straight between its points, never routed along pistes, lifts or trails, an imported one is kept as recorded; its distance and heights come from that line or the file, it has no ski time worked out, and nothing in it says anything about snow, avalanches or whether a run or trail is open), the boat, water and chosen speed of a paddle tour (boat_type, water_context, paddle_speed_kmh in km/h, null while the suggested speed of the boat applies), the check bench of a paddle tour (paddle_check: how far the OpenStreetMap obstacle data covers its line and how many obstacles are open, to check again or decided by the travellers; a planning status, never a safety or legal clearance), for a city walk the number of its stations (station_count: its points without the shaping points and the way back of a loop), their stays as far as entered (station_stay_minutes) and how many have none (station_stays_unknown), whether a tour still waits for its way to be planned (route_pending: saved with its points only, so its distance and walking time stay null until someone opens it in the planner and saves it), for a multi-day tour the number of stages its route is split into (stage_count: one route planned whole, each stage ending at a stop marked as its end; null for a tour of one day) and the stops they run between (stage_stops, in route order with key and coordinates: stage n runs from stop n-1 to stop n, and is known by the key of the stop it starts at), the revision (raised by every saved change of the tour), the recorded tracks assigned to a tour (activity_tracks) and, for a recorded track, the tour it documents (activity_of), when an imported track was recorded (track_started_at, track_ended_at; null when the file carried no times), the time a tour without a planned time (an import) is estimated to take (time_estimate: minutes and basis, din33466 for a hike by the hiking signpost rule DIN 33466 from its distance, ascent and descent, run_pace for a run at the pace entered; worked out on reading and without breaks, never a recorded or planned time; minutes null when the track has no heights, and time_estimate null where nothing estimates it, a tour the planner timed among them, whose duration is its time), and the days of the trip each tour is on (tour_stage_key names the stage a day holds by its starting stop, null where the day holds the whole tour; a stage may also be on no day yet).',
|
||||
'List the saved tours of a trip (hikes, city walks, runs, bike tours, paddle tours, rides on horseback and ski and winter tours planned or imported in the Tours addon): name, type (hike, walk for a city walk, run, bike, kayak for a paddle tour, horse for a ride, or ski for a ski and winter tour; a ride has no time worked out, so its duration is null), where it came from (origin: trek, gpx for an imported GPX, KML or KMZ file, or wanderer), distance in km, ascent and descent in metres, the stored routing limit of a hike (max_hiking_difficulty, SAC T1 to T6) and its route choices (hiking_preferences: avoid_climbs for gentler ways, avoid_steps, avoid_ferries; weightings, never a grade of the path), the profile a bike tour is routed for (bike_profile: touring for paved cycle paths and quiet roads, road for asphalt, gravel for gravel and farm tracks, mtb for rough tracks; a routing preference, never a statement that a way is rideable or safe), the profile and pace of a run (run_profile: running for runnable, mostly paved ways in towns and parks, trail for forest tracks and natural paths up to mountain paths (T2); a routing preference, never a statement that a way can be run; run_pace_seconds_per_km, the pace the runners planned with, null while they entered none; its duration is the distance at that pace and nothing else, no climb, descent or difficulty is in it, and it is a plan, never a recorded time), the discipline of a ski tour (ski_discipline: alpine, snowboard, cross_country, touring for ski touring, snowshoe or winter_hike; snowshoeing and winter hiking are ski tours, a hike is summer only; ski_technique for cross-country only: classic, skating or unknown when the travellers did not know; a planned ski tour has its legs planned by the piste router along the runs, lifts and trails of OpenStreetMap where that data reaches (ski_options: the router options it was planned with, ski_route_build: the piste data build) and drawn straight elsewhere, an imported one is kept as recorded; its duration is the estimate of the router only when every leg was planned by it, else null, and nothing in it says anything about snow, avalanches or whether a run or trail is open), the boat, water and chosen speed of a paddle tour (boat_type, water_context, paddle_speed_kmh in km/h, null while the suggested speed of the boat applies), the check bench of a paddle tour (paddle_check: how far the OpenStreetMap obstacle data covers its line and how many obstacles are open, to check again or decided by the travellers; a planning status, never a safety or legal clearance), for a city walk the number of its stations (station_count: its points without the shaping points and the way back of a loop), their stays as far as entered (station_stay_minutes) and how many have none (station_stays_unknown), whether a tour still waits for its way to be planned (route_pending: saved with its points only, so its distance and walking time stay null until someone opens it in the planner and saves it), for a multi-day tour the number of stages its route is split into (stage_count: one route planned whole, each stage ending at a stop marked as its end; null for a tour of one day) and the stops they run between (stage_stops, in route order with key and coordinates: stage n runs from stop n-1 to stop n, and is known by the key of the stop it starts at), the revision (raised by every saved change of the tour), the recorded tracks assigned to a tour (activity_tracks) and, for a recorded track, the tour it documents (activity_of), when an imported track was recorded (track_started_at, track_ended_at; null when the file carried no times), the time a tour without a planned time (an import) is estimated to take (time_estimate: minutes and basis, din33466 for a hike by the hiking signpost rule DIN 33466 from its distance, ascent and descent, run_pace for a run at the pace entered; worked out on reading and without breaks, never a recorded or planned time; minutes null when the track has no heights, and time_estimate null where nothing estimates it, a tour the planner timed among them, whose duration is its time), and the days of the trip each tour is on (tour_stage_key names the stage a day holds by its starting stop, null where the day holds the whole tour; a stage may also be on no day yet).',
|
||||
inputSchema: { tripId: idSchema },
|
||||
annotations: TOOL_ANNOTATIONS_READONLY,
|
||||
when: addonGate(ADDON_IDS.TOURS),
|
||||
|
||||
Reference in New Issue
Block a user