feat(tours): plan a run at your own pace

RUN-01. Run joins the tour types in the planner, with Running as its first
profile, chosen on purpose like a bike tour's. A run is routed on foot for
runnable, mostly paved ways: tracks and ferries only where there is no other
way (use_tracks 0, use_ferry 0, measured against the public Valhalla), no
hiking limit and no via ferrata. The runner types a pace in min/km; the
running time is the distance at that pace and nothing else, shown under the
field as badges (8 km x 6:00 /km = 48 min). TREK suggests no pace: without
one the time stays unknown and Save waits, text that is no pace or a pace
outside 2:00 to 20:00 is marked. The info dot, the overview and the head say
climbs, descents and difficulty are not in the time, and the time reads as
planned everywhere, so it never passes for a recorded one; the heights are
shown as for any tour on land.

Type, profile, pace and route come back on opening, survive a draft reload,
an undo of the type, a copy and a take-over; switching to another type drops
profile and pace. Day assignment, the 3D terrain view (with topo and
satellite, no ferratas) and a routing failure keeping the last route work as
for every tour. A GPX file can be imported as a run with its profile and no
pace, and planned over as a run. Runs export to GPX as running and get their
own places along the way (water, toilets, parks, viewpoints).

The server keeps tours.run_profile (CHECK list, already holding trail for
RUN-02, since SQLite cannot widen a CHECK in place) and
tours.run_pace_seconds_per_km (120 to 1200), switches the run type on,
refuses a run without a profile and run fields on any other type, and
list_tours names both with what the planned time does not include.
This commit is contained in:
Maurice
2026-10-20 12:51:29 +02:00
parent cd407cf80c
commit c83eb42730
86 changed files with 2524 additions and 99 deletions
+18 -1
View File
@@ -40,6 +40,8 @@ export class Tours {
taken_over_from_tour_name?: string | null;
bike_profile?: TToursBikeProfile | null;
winter_activity?: TToursWinterActivity | null;
run_profile?: TToursRunProfile | null;
run_pace_seconds_per_km?: number | null;
tourTypeRef!: Ref<TourTypes>;
tour_obstacle_reviews_collection = new Collection<TourObstacleReviews>(this);
tour_sources: Ref<TourSources> | null = null;
@@ -93,6 +95,13 @@ export const ToursWinterActivity = {
export type TToursWinterActivity = (typeof ToursWinterActivity)[keyof typeof ToursWinterActivity];
export const ToursRunProfile = {
RUNNING: 'running',
TRAIL: 'trail',
} as const;
export type TToursRunProfile = (typeof ToursRunProfile)[keyof typeof ToursRunProfile];
export const ToursSchema = defineEntity({
class: Tours,
repository: () => ToursRepository,
@@ -103,7 +112,13 @@ export const ToursSchema = defineEntity({
properties: ['derived_from_place_id'],
},
],
checks: [{ name: 'tours_revision_check', expression: 'revision >= 1' }],
checks: [
{ name: 'tours_revision_check', expression: 'revision >= 1' },
{
name: 'tours_run_pace_seconds_per_km_check',
expression: 'run_pace_seconds_per_km IS NULL OR (run_pace_seconds_per_km >= 120 AND run_pace_seconds_per_km <= 1200)',
},
],
properties: {
place: () => p.oneToOne(Places).primary().ref().deleteRule('cascade').nullable().hidden(),
place_id: p.integer().nullable().persist(false),
@@ -136,6 +151,8 @@ export const ToursSchema = defineEntity({
taken_over_from_tour_name: p.text().nullable(),
bike_profile: p.enum(() => ToursBikeProfile).nullable(),
winter_activity: p.enum(() => ToursWinterActivity).nullable(),
run_profile: p.enum(() => ToursRunProfile).nullable(),
run_pace_seconds_per_km: p.integer().nullable(),
tourTypeRef: () => p.manyToOne(TourTypes).ref().joinColumn('tour_type').hidden().index('idx_tours_tour_type'),
tour_obstacle_reviews_collection: () => p.oneToMany(TourObstacleReviews).mappedBy('place').hidden(),
tour_sources: () => p.oneToOne(TourSources).ref().mappedBy('place').hidden(),
+2
View File
@@ -32,4 +32,6 @@ export interface ToursTable {
taken_over_from_tour_name: InsertOptional<string | null>;
bike_profile: InsertOptional<string | null>;
winter_activity: InsertOptional<string | null>;
run_profile: InsertOptional<string | null>;
run_pace_seconds_per_km: InsertOptional<number | null>;
}
@@ -0,0 +1,26 @@
import { Migration } from '@mikro-orm/migrations';
/**
* RUN-01: a tour can be a run. The `run` key has been in `tour_types`,
* disabled, since every contract type was seeded; it is switched on here. The
* profile it is routed for and the pace the runner plans it at are columns of
* the tour, NULL on every other type, so no existing tour changes its meaning.
*
* The profile list already holds trail running, which RUN-02 brings to the
* contract: SQLite cannot widen a column's CHECK without rebuilding the table.
* The pace is whole seconds per kilometre, from 2:00 to 20:00 min/km as the
* contract takes it, NULL while the runner has entered none.
*/
export class Migration20200101045510_a_tour_can_be_a_run extends Migration {
override name = 'Migration20200101045510_a_tour_can_be_a_run';
override up(): void {
this.addSql(
"ALTER TABLE tours ADD COLUMN run_profile TEXT CHECK (run_profile IS NULL OR run_profile IN ('running', 'trail'))",
);
this.addSql(
'ALTER TABLE tours ADD COLUMN run_pace_seconds_per_km INTEGER CHECK (run_pace_seconds_per_km IS NULL OR (run_pace_seconds_per_km >= 120 AND run_pace_seconds_per_km <= 1200))',
);
this.addSql("UPDATE tour_types SET enabled = 1 WHERE key = 'run'");
}
}
+26 -1
View File
@@ -2,7 +2,14 @@ import { type Tours, type TToursOrigin, ToursOrigin } from '../entities/Tours.en
import type { DB } from '../kysely/db';
import type { AssertRowKeys } from './_shared/rows';
import { TrekRepository } from './_shared/trek-repository';
import type { BikeProfile, PaddleBoatType, PaddleLakeStyle, PaddleWaterContext, WinterActivity } from '@trek/shared';
import type {
BikeProfile,
PaddleBoatType,
PaddleLakeStyle,
PaddleWaterContext,
RunProfile,
WinterActivity,
} from '@trek/shared';
/**
* A tour as the Tours list and detail read it: the `tours` facet joined with
@@ -32,6 +39,9 @@ export interface TourListRow {
bike_profile: string | null;
/** HIK-01: a hike's winter label; NULL for none and on every other type. */
winter_activity: string | null;
/** RUN-01: a run's profile and the pace it is planned at, seconds per km; NULL on every other type. */
run_profile: string | null;
run_pace_seconds_per_km: number | null;
boat_type: string | null;
water_context: string | null;
paddle_speed_kmh: number | null;
@@ -100,6 +110,8 @@ export interface TourRow {
taken_over_from_tour_name: string | null;
bike_profile: string | null;
winter_activity: string | null;
run_profile: string | null;
run_pace_seconds_per_km: number | null;
}
const _tourRowKeys: AssertRowKeys<TourRow, Tours> = true;
@@ -119,6 +131,9 @@ export interface TourInsert {
bike_profile?: BikeProfile | null;
/** HIK-01: a hike's winter label; left out, NULL on a new tour and kept as it is by an edit. */
winter_activity?: WinterActivity | null;
/** RUN-01: a run's profile and its pace, seconds per km; left out, NULL. */
run_profile?: RunProfile | null;
run_pace_seconds_per_km?: number | null;
/** A paddle tour's boat, water and chosen speed; left out, a hike's NULLs. */
boat_type?: PaddleBoatType | null;
water_context?: PaddleWaterContext | null;
@@ -136,6 +151,8 @@ export type TourUpdate = Omit<
| 'planned_duration_minutes'
| 'break_additional_minutes'
| 'bike_profile'
| 'run_profile'
| 'run_pace_seconds_per_km'
| 'boat_type'
| 'water_context'
| 'paddle_speed_kmh'
@@ -145,6 +162,8 @@ export type TourUpdate = Omit<
planned_duration_minutes?: number | null;
break_additional_minutes?: number | null;
bike_profile: BikeProfile | null;
run_profile: RunProfile | null;
run_pace_seconds_per_km: number | null;
boat_type: PaddleBoatType | null;
water_context: PaddleWaterContext | null;
paddle_speed_kmh: number | null;
@@ -248,6 +267,8 @@ export class ToursRepository extends TrekRepository<Tours> {
't.origin as origin',
't.bike_profile as bike_profile',
't.winter_activity as winter_activity',
't.run_profile as run_profile',
't.run_pace_seconds_per_km as run_pace_seconds_per_km',
't.boat_type as boat_type',
't.water_context as water_context',
't.paddle_speed_kmh as paddle_speed_kmh',
@@ -614,6 +635,8 @@ export class ToursRepository extends TrekRepository<Tours> {
max_hiking_difficulty: input.max_hiking_difficulty,
bike_profile: input.bike_profile ?? null,
winter_activity: input.winter_activity ?? null,
run_profile: input.run_profile ?? null,
run_pace_seconds_per_km: input.run_pace_seconds_per_km ?? null,
boat_type: input.boat_type ?? null,
water_context: input.water_context ?? null,
paddle_speed_kmh: input.paddle_speed_kmh ?? null,
@@ -699,6 +722,8 @@ export class ToursRepository extends TrekRepository<Tours> {
match_confidence: input.match_confidence,
max_hiking_difficulty: input.max_hiking_difficulty,
bike_profile: input.bike_profile,
run_profile: input.run_profile,
run_pace_seconds_per_km: input.run_pace_seconds_per_km,
boat_type: input.boat_type,
water_context: input.water_context,
paddle_speed_kmh: input.paddle_speed_kmh,