mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-24 07:53:09 +00:00
feat(tours): import a ski track from GPX and keep it as recorded
SKI-02. Ski joins the types a GPX file can be imported as, offered in the import preview's type field only: TREK routes no ski track, so the planner never offers it. The preview asks for the discipline on purpose (alpine, snowboard, cross-country or ski touring, none chosen at first) and, for cross-country, the technique (classic, skating or unknown); Import waits until both are named, and the technique stays in sight but dimmed for the other disciplines. The track is stored exactly as recorded, with its file name as provenance, its distance and heights from the file and no time: no ski time is worked out and no hiking estimate stands in for one. Opened in the planner, a ski track gets a rail card with its discipline on a tinted tile, a cross-country technique as a badge beside it, the ski time said as not worked out, and an info dot on what TREK does not say (snow, avalanches, open runs, and that the 3D gradient colours are no difficulty or avalanche rating). Change opens a dialog to classify the track again; only the classification changes, through the offline core, with the revision it was made at. Planning over the import is not offered for ski. The existing 3D terrain view, the elevation profile and its focus work on the track as for any import, with the standard map, topo and satellite and no via ferratas. Lists, the day plan and the detail show the discipline as a frosted corner badge on the tile and as a pill with the technique inside; day assignment, copies and take-overs work as for any tour. The corner badge is now one component that the winter label shares. The server keeps tours.ski_discipline and tours.ski_technique (CHECK lists, NULL on every other type), switches the ski type on without a routing profile, refuses a ski import without its discipline, a technique outside cross-country and ski fields on any other type, and takes a planned save's classification off. PUT /api/trips/:tripId/tours/:placeId/ski classifies a ski track again (place_edit, 409 on a stale revision, 400 for a tour that is no ski track) and broadcasts tours:changed. GPX export names the discipline (alpine_skiing, snowboarding, cross_country_skiing, backcountry_skiing), and list_tours describes both fields with what a ski track does not say. Ski is labelled plainly as Ski in every language, so it no longer reads as ski touring.
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
import { tourSkiClassificationRequestSchema } from '@trek/shared';
|
||||
|
||||
import { createZodDto } from 'nestjs-zod';
|
||||
|
||||
export class TourSkiClassificationDto extends createZodDto(tourSkiClassificationRequestSchema) {}
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { BikeProfile, PaddleBoatType, RunProfile } from '@trek/shared';
|
||||
import type { BikeProfile, PaddleBoatType, RunProfile, SkiDiscipline } from '@trek/shared';
|
||||
|
||||
/** What GPX calls the activity in a track's <type>; a paddle tour says what it is paddled in. */
|
||||
const PADDLE_ACTIVITY: Record<PaddleBoatType, string> = {
|
||||
@@ -22,22 +22,33 @@ const RUN_ACTIVITY: Record<RunProfile, string> = {
|
||||
trail: 'trail_running',
|
||||
};
|
||||
|
||||
/** SKI-02: a ski track says how it was skied, in the same words; without a known discipline it is skiing. */
|
||||
const SKI_ACTIVITY: Record<SkiDiscipline, string> = {
|
||||
alpine: 'alpine_skiing',
|
||||
snowboard: 'snowboarding',
|
||||
cross_country: 'cross_country_skiing',
|
||||
touring: 'backcountry_skiing',
|
||||
};
|
||||
|
||||
/**
|
||||
* The activity a tour's track names in GPX: a paddle tour its boat, a bike
|
||||
* tour and a run their profile, a hike on snowshoes snowshoeing (HIK-01) and any other
|
||||
* hike hiking; whatever is missing falls back to the plainest.
|
||||
* tour and a run their profile, a ski track its discipline (SKI-02), a hike on
|
||||
* snowshoes snowshoeing (HIK-01) and any other hike hiking; whatever is
|
||||
* missing falls back to the plainest.
|
||||
*/
|
||||
export function gpxActivityOf(tour: {
|
||||
tour_type: string;
|
||||
boat_type?: string | null;
|
||||
bike_profile?: string | null;
|
||||
run_profile?: string | null;
|
||||
ski_discipline?: string | null;
|
||||
winter_activity?: string | null;
|
||||
}): string {
|
||||
const { tour_type: type, boat_type: boat, bike_profile: bike } = tour;
|
||||
if (type === 'kayak') return PADDLE_ACTIVITY[(boat ?? 'other') as PaddleBoatType] ?? PADDLE_ACTIVITY.other;
|
||||
if (type === 'bike') return BIKE_ACTIVITY[(bike ?? 'touring') as BikeProfile] ?? BIKE_ACTIVITY.touring;
|
||||
if (type === 'run') return RUN_ACTIVITY[(tour.run_profile ?? 'running') as RunProfile] ?? RUN_ACTIVITY.running;
|
||||
if (type === 'ski') return SKI_ACTIVITY[tour.ski_discipline as SkiDiscipline] ?? 'skiing';
|
||||
if (type !== 'hike') return type;
|
||||
// A winter hike is walked as any hike is; only snowshoes make it an activity of its own.
|
||||
return tour.winter_activity === 'snowshoe' ? 'snowshoeing' : 'hiking';
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import { ADDON_IDS } from '../../addons';
|
||||
import { AddonGuard } from '../addons/addon.guard';
|
||||
import { RequireAddon } from '../addons/require-addon.decorator';
|
||||
import { JwtAuthGuard } from '../auth-core/jwt-auth.guard';
|
||||
import { ResponseContract } from '../common/response-contract';
|
||||
import { RequirePermission, TripAccessGuard } from '../permissions/trip-access.guard';
|
||||
import { TourSkiClassificationDto } from './dto/tour-ski.dto';
|
||||
import { TourSkiService } from './tour-ski.service';
|
||||
import { Body, Controller, Headers, Param, Put, UseGuards } from '@nestjs/common';
|
||||
import { tourDetailResponseSchema } from '@trek/shared';
|
||||
|
||||
/**
|
||||
* SKI-02: PUT /api/trips/:tripId/tours/:placeId/ski classifies a ski track
|
||||
* again, its discipline and cross-country technique only, as someone who may
|
||||
* edit the trip's places. Answers the tour's detail, as the editor reads it.
|
||||
*/
|
||||
@Controller('api/trips/:tripId/tours/:placeId/ski')
|
||||
@UseGuards(AddonGuard, JwtAuthGuard, TripAccessGuard)
|
||||
@RequireAddon(ADDON_IDS.TOURS, 'Tours')
|
||||
export class TourSkiController {
|
||||
constructor(private readonly ski: TourSkiService) {}
|
||||
|
||||
@RequirePermission('place_edit')
|
||||
@Put()
|
||||
@ResponseContract(tourDetailResponseSchema)
|
||||
async classify(
|
||||
@Param('tripId') tripId: string,
|
||||
@Param('placeId') placeId: string,
|
||||
@Body() body: TourSkiClassificationDto,
|
||||
@Headers('x-socket-id') socketId?: string,
|
||||
) {
|
||||
return await this.ski.classify(tripId, placeId, body, socketId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
import { Tours } from '../../db/entities/Tours.entity';
|
||||
import type { ToursRepository } from '../../db/repositories/Tours.repository';
|
||||
import { DomainError } from '../common/domain-error';
|
||||
import { toRowId } from '../common/row-id';
|
||||
import { UnitOfWork } from '../database/unit-of-work';
|
||||
import { advanceTourRevision } from './tour-revision';
|
||||
import { ToursService } from './tours.service';
|
||||
import { InjectRepository } from '@mikro-orm/nestjs';
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import type { TourDetailResponse, TourSkiClassificationRequest } from '@trek/shared';
|
||||
|
||||
/**
|
||||
* SKI-02: a ski track classified again after its import, when the discipline
|
||||
* or the cross-country technique chosen then was not the right one. Only the
|
||||
* classification changes: the recorded track, its measures, its days and its
|
||||
* provenance stay as they are, and nothing is routed. A tour that is no ski
|
||||
* track has no classification to change.
|
||||
*/
|
||||
@Injectable()
|
||||
export class TourSkiService {
|
||||
constructor(
|
||||
private readonly uow: UnitOfWork,
|
||||
private readonly tours: ToursService,
|
||||
@InjectRepository(Tours) private readonly toursRepo: ToursRepository,
|
||||
) {}
|
||||
|
||||
async classify(
|
||||
tripId: string,
|
||||
placeId: string,
|
||||
input: TourSkiClassificationRequest,
|
||||
socketId?: string,
|
||||
): Promise<TourDetailResponse> {
|
||||
const tid = toRowId(tripId);
|
||||
const pid = toRowId(placeId);
|
||||
if (tid === null || pid === null) throw new NotFoundException('Tour not found');
|
||||
|
||||
await this.uow.transactional(async () => {
|
||||
const row = await this.toursRepo.findInTrip(tid, pid);
|
||||
if (!row) throw new NotFoundException('Tour not found');
|
||||
if (row.tour_type !== 'ski') {
|
||||
throw new DomainError(400, 'Only a ski track has a ski classification', {
|
||||
code: 'not_a_ski_track',
|
||||
details: { code: 'not_a_ski_track' },
|
||||
});
|
||||
}
|
||||
await advanceTourRevision(this.toursRepo, pid, input.expected_revision);
|
||||
await this.toursRepo.updateSkiInTrip(tid, pid, {
|
||||
ski_discipline: input.ski_discipline,
|
||||
ski_technique: input.ski_technique ?? null,
|
||||
});
|
||||
});
|
||||
|
||||
const result = await this.tours.getTour(tripId, placeId);
|
||||
this.tours.broadcastToursChanged(tripId, [pid], socketId);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -85,7 +85,7 @@ export class ToursMcp {
|
||||
@Tool({
|
||||
name: 'list_tours',
|
||||
description:
|
||||
'List the saved tours of a trip (hikes, city walks, runs, bike tours and paddle tours planned or imported in the Tours addon): name, type (hike, walk for a city walk, run, bike, or kayak for a paddle tour), where it came from (origin: trek, gpx 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 winter label of a hike (winter_activity: winter_hike or snowshoe, null for none; a label the travellers chose, while the route and its time are planned as for any hike, never a statement that a way can be walked in winter or anything about snow or avalanches), 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 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), the revision (raised by every saved change of the tour), and the days of the trip each tour is on.',
|
||||
'List the saved tours of a trip (hikes, city walks, runs, bike tours, paddle tours and ski tracks planned or imported in the Tours addon): name, type (hike, walk for a city walk, run, bike, kayak for a paddle tour, or ski for a ski track), where it came from (origin: trek, gpx 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 winter label of a hike (winter_activity: winter_hike or snowshoe, null for none; a label the travellers chose, while the route and its time are planned as for any hike, never a statement that a way can be walked in winter or anything about snow or avalanches), 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 classification of a ski track (ski_discipline: alpine, snowboard, cross_country or touring for ski touring; ski_technique for cross-country only: classic, skating or unknown when the travellers did not know; a ski track is imported from a GPX file and kept as recorded, never routed, its distance and heights come from 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), the revision (raised by every saved change of the tour), and the days of the trip each tour is on.',
|
||||
inputSchema: { tripId: idSchema },
|
||||
annotations: TOOL_ANNOTATIONS_READONLY,
|
||||
when: addonGate(ADDON_IDS.TOURS),
|
||||
|
||||
@@ -28,6 +28,8 @@ import { TourPaddleCheckService } from './tour-paddle-check.service';
|
||||
import { TourPaddlePlanService } from './tour-paddle-plan.service';
|
||||
import { TourPoiSearchController } from './tour-poi-search.controller';
|
||||
import { TourPoiSearchService } from './tour-poi-search.service';
|
||||
import { TourSkiController } from './tour-ski.controller';
|
||||
import { TourSkiService } from './tour-ski.service';
|
||||
import { TourTrailGradeController } from './tour-trail-grade.controller';
|
||||
import { TourTrailGradeService } from './tour-trail-grade.service';
|
||||
import { TourVisitsController } from './tour-visits.controller';
|
||||
@@ -88,6 +90,7 @@ import { Module } from '@nestjs/common';
|
||||
controllers: [
|
||||
TourTakeOverController,
|
||||
TourPoiSearchController,
|
||||
TourSkiController,
|
||||
TourTrailGradeController,
|
||||
TourVisitsController,
|
||||
TourWalkImportController,
|
||||
@@ -106,6 +109,7 @@ import { Module } from '@nestjs/common';
|
||||
ToursWandererService,
|
||||
TourLibraryService,
|
||||
TourPoiSearchService,
|
||||
TourSkiService,
|
||||
TourTrailGradeService,
|
||||
TourVisitsService,
|
||||
TourWalkImportService,
|
||||
|
||||
@@ -48,6 +48,8 @@ import {
|
||||
type PaddleLakeStyle,
|
||||
type PaddleWaterContext,
|
||||
type RunProfile,
|
||||
type SkiDiscipline,
|
||||
type SkiTechnique,
|
||||
type TourCreateRequest,
|
||||
type TourCreateResponse,
|
||||
type TourDetailResponse,
|
||||
@@ -179,6 +181,8 @@ export class ToursService {
|
||||
winter_activity: r.winter_activity as WinterActivity | null,
|
||||
run_profile: r.run_profile as RunProfile | null,
|
||||
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,
|
||||
boat_type: r.boat_type as PaddleBoatType | null,
|
||||
water_context: r.water_context as PaddleWaterContext | null,
|
||||
paddle_speed_kmh: r.paddle_speed_kmh,
|
||||
@@ -222,6 +226,9 @@ export class ToursService {
|
||||
bike_profile: input.tour_type === 'bike' ? (input.bike_profile ?? null) : null,
|
||||
winter_activity: winterField(input),
|
||||
...runFields(input),
|
||||
// SKI-02: TREK plans no ski track, so a planned save is never one and takes its classification off.
|
||||
ski_discipline: null,
|
||||
ski_technique: null,
|
||||
boat_type: input.boat_type ?? null,
|
||||
water_context: input.water_context ?? null,
|
||||
paddle_speed_kmh: input.paddle_speed_kmh ?? null,
|
||||
@@ -521,6 +528,8 @@ export class ToursService {
|
||||
bike_profile: row.bike_profile as BikeProfile | null,
|
||||
run_profile: row.run_profile as RunProfile | null,
|
||||
run_pace_seconds_per_km: row.run_pace_seconds_per_km,
|
||||
ski_discipline: row.ski_discipline as SkiDiscipline | null,
|
||||
ski_technique: row.ski_technique as SkiTechnique | null,
|
||||
boat_type: row.boat_type as PaddleBoatType | null,
|
||||
water_context: row.water_context as PaddleWaterContext | null,
|
||||
paddle_speed_kmh: row.paddle_speed_kmh,
|
||||
@@ -632,6 +641,8 @@ export class ToursService {
|
||||
winter_activity: row.winter_activity as WinterActivity | null,
|
||||
run_profile: row.run_profile as RunProfile | null,
|
||||
run_pace_seconds_per_km: row.run_pace_seconds_per_km,
|
||||
ski_discipline: row.ski_discipline as SkiDiscipline | null,
|
||||
ski_technique: row.ski_technique as SkiTechnique | null,
|
||||
boat_type: row.boat_type as PaddleBoatType | null,
|
||||
water_context: row.water_context as PaddleWaterContext | null,
|
||||
paddle_speed_kmh: row.paddle_speed_kmh,
|
||||
@@ -815,12 +826,15 @@ export class ToursService {
|
||||
const rows = this.readGpxTracks(fileBuffer, fileName);
|
||||
if (rows.length === 0) return null;
|
||||
await this.assertTourTypeEnabled(fields.tour_type);
|
||||
// What the type adds to each imported tour: a bike tour and a run their profile, a paddle tour its boat and water.
|
||||
// A run comes in without a pace: its time stays unknown until one is planned from it.
|
||||
// What the type adds to each imported tour: a bike tour and a run their profile, a paddle tour its boat and water,
|
||||
// a ski track its discipline and technique (SKI-02). A run comes in without a pace and a ski track without a
|
||||
// time: neither is worked out for them, so they stay unknown.
|
||||
const typeFields = {
|
||||
bike_profile: fields.bike_profile ?? null,
|
||||
run_profile: fields.run_profile ?? null,
|
||||
run_pace_seconds_per_km: null,
|
||||
ski_discipline: fields.ski_discipline ?? null,
|
||||
ski_technique: fields.ski_technique ?? null,
|
||||
boat_type: fields.boat_type ?? null,
|
||||
water_context: fields.water_context ?? null,
|
||||
paddle_speed_kmh: null,
|
||||
|
||||
Reference in New Issue
Block a user