mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-05 02:14:05 +00:00
acc294dd8e
A day of a tour that names nobody now counts for every member of the trip, not only for its owner. In the planner an empty participant list means everyone, and a full member list is stored back as empty, so members got nothing for most shared tours. Only a day that names participants without the user stays theirs. The tours of a shared trip on no day or only on undated days are now named as not counting for members as well. A whole route a multi-day tour's stages were planned from is no longer dropped on the server as soon as any stage has a day. Each entry carries derived_from_place_id and the shared summary leaves the route out only while one of its stages is done, counted and in the period and type. A route walked last year now still counts when a stage of it is planned for next month or was left out because it fell through, in the Atlas and over MCP alike. A tour on several days is dated on the last of them, as is a recording on no day, so it no longer counts while it is still under way. The info text, the get_tour_activity_stats description and the wiki say so.
96 lines
4.5 KiB
TypeScript
96 lines
4.5 KiB
TypeScript
import { idSchema } from '../common/primitives.schema';
|
|
import { tourTypeKeySchema } from './tours.schema';
|
|
|
|
import { z } from 'zod';
|
|
|
|
/**
|
|
* STA-02: the user's own tour activities, as the Atlas sums them. One entry is
|
|
* one tour the user did on one day of a trip, read from what the trip holds:
|
|
*
|
|
* - The plan's values stand in for the tour while nothing was recorded
|
|
* (`basis: 'plan'`), and say so. A tour on several days still counts once
|
|
* (`day_count` says on how many), on the last of them, so a tour still under
|
|
* way is not done yet.
|
|
* - A recorded track linked to an execution of the tour (ACT-01) takes the
|
|
* plan's place (`basis: 'track'`), one entry per recording; the plan of that
|
|
* tour is then not counted besides it, and the recording is never counted as
|
|
* a tour of its own.
|
|
* - An import some other tour of the trip was planned from (the whole route a
|
|
* multi-day tour's stages were cut from) is named by those tours in
|
|
* `derived_from_place_id`, and the summary leaves it out while one of them
|
|
* counts, so the route and its stages are never added up together. A stage
|
|
* still ahead or left out does not hide the route.
|
|
* - Only the user's own part counts: an execution names the user as one of its
|
|
* participants, or names nobody, which in the planner means everyone of the
|
|
* trip. A day that names participants without the user is not theirs.
|
|
*
|
|
* Whether an entry is done is the reader's question (`date` before today, in
|
|
* the reader's own time zone): the server answers every entry it found, the
|
|
* upcoming ones too, so the app can say how many are still ahead.
|
|
*/
|
|
|
|
/** Where an entry's values come from: the trip's planning, or a track recorded while doing it. */
|
|
export const TOUR_ACTIVITY_BASES = ['plan', 'track'] as const;
|
|
export const tourActivityBasisSchema = z.enum(TOUR_ACTIVITY_BASES);
|
|
export type TourActivityBasis = z.infer<typeof tourActivityBasisSchema>;
|
|
|
|
/** A calendar day, YYYY-MM-DD, as a trip's days carry it. */
|
|
export const tourActivityDateSchema = z.string().regex(/^\d{4}-\d{2}-\d{2}$/);
|
|
|
|
export const tourActivityStatsEntrySchema = z.object({
|
|
place_id: idSchema,
|
|
name: z.string(),
|
|
tour_type: tourTypeKeySchema,
|
|
trip: z.object({ id: idSchema, title: z.string() }),
|
|
/** The whole route this tour was planned from, a stage of it; null for any other tour. */
|
|
derived_from_place_id: idSchema.nullable(),
|
|
/** The day it was done on: the recording's day, else the last of the user's dated days the tour is on. */
|
|
date: tourActivityDateSchema,
|
|
basis: tourActivityBasisSchema,
|
|
/** The recording whose values these are; null for the plan. */
|
|
track: z.object({ place_id: idSchema, name: z.string() }).nullable(),
|
|
/** On how many of the user's dated days the tour is planned; it counts once however many. */
|
|
day_count: z.number().int().positive(),
|
|
/** Null where the source does not know the value; a paddle tour never has heights. */
|
|
distance_km: z.number().nonnegative().nullable(),
|
|
ascent_m: z.number().nonnegative().nullable(),
|
|
descent_m: z.number().nonnegative().nullable(),
|
|
/** Left out of the user's sums on purpose (a tour that fell through); the plan stays as it is. */
|
|
excluded: z.boolean(),
|
|
});
|
|
export type TourActivityStatsEntry = z.infer<typeof tourActivityStatsEntrySchema>;
|
|
|
|
export const tourActivityStatsResponseSchema = z.object({
|
|
/** The newest first. */
|
|
entries: z.array(tourActivityStatsEntrySchema),
|
|
/**
|
|
* Tours of the user's trips that cannot count as done: on no day at all, or
|
|
* only on the user's days without a date. A whole route whose stages are on
|
|
* the user's days is not among them. Said, so a missing tour is not a mystery.
|
|
*/
|
|
uncounted: z.object({
|
|
unassigned: z.number().int().nonnegative(),
|
|
undated: z.number().int().nonnegative(),
|
|
}),
|
|
});
|
|
export type TourActivityStatsResponse = z.infer<typeof tourActivityStatsResponseSchema>;
|
|
|
|
/** Leaving a tour out of the user's own sums, or counting it again. Nothing of the tour changes. */
|
|
export const tourActivityExclusionRequestSchema = z
|
|
.object({
|
|
place_id: idSchema,
|
|
excluded: z.boolean(),
|
|
})
|
|
.strict();
|
|
export type TourActivityExclusionRequest = z.infer<typeof tourActivityExclusionRequestSchema>;
|
|
|
|
/** What a reader narrows the sums by: a period (both days included) and one type. */
|
|
export const tourActivityStatsQuerySchema = z
|
|
.object({
|
|
from: tourActivityDateSchema.optional(),
|
|
to: tourActivityDateSchema.optional(),
|
|
type: tourTypeKeySchema.optional(),
|
|
})
|
|
.strict();
|
|
export type TourActivityStatsQuery = z.infer<typeof tourActivityStatsQuerySchema>;
|