Add track layout tracking so lap-time stats stay comparable
Clubs that reconfigure their track (e.g. running indoors in the same building) can now add named track layouts under Settings, each with just a start date/time - layouts are contiguous, so a layout's end is implicitly the next one's start, with no separate field to keep in sync. Every session freezes which layout was active when it started, so the "track record" audio cue and the Results Archive (which now shows each session's layout) only compare laps run on the same physical track. With no layouts configured, everything behaves exactly as before - the feature is fully inert until a club uses it. Design settled through conversation with the user: global scope (not per class), start-date-only (no redundant stop date), and no changes needed to driver/transponder mapping, since that's already fully independent of track geometry in this app. Deliberately out of scope for this pass: the mobile/driver training profile's own cross-session personal-best trend stats still compare across a driver's whole lap ledger regardless of layout - logged in ROADMAP.md as a real remaining gap for a later pass. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
90df3378a6
commit
fd6efe2c7e
13 files changed
+328
-27
No files matched your search
@@ -0,0 +1,44 @@
|
||||
// A club that reconfigures its track (common indoors, in the same building) needs a way
|
||||
// to say "everything from this point on is a different layout" so lap-time comparisons
|
||||
// don't silently mix incomparable tracks. Layouts are assumed contiguous - a club changes
|
||||
// layout roughly every few weeks and never switches back and forth - so only a start
|
||||
// date/time is stored per layout; a layout's end is implicitly the next one's start (see
|
||||
// ROADMAP.md "Track layout changes and stat continuity" for the fuller reasoning).
|
||||
export function normalizeTrackLayout(layout, { uid } = {}) {
|
||||
return {
|
||||
id: String(layout?.id || (uid ? uid("layout") : "")),
|
||||
label: String(layout?.label || "").trim(),
|
||||
startedAt: Number.isFinite(Number(layout?.startedAt)) ? Number(layout.startedAt) : Date.now(),
|
||||
};
|
||||
}
|
||||
|
||||
export function normalizeTrackLayouts(layouts, { uid } = {}) {
|
||||
const list = (Array.isArray(layouts) ? layouts : [])
|
||||
.map((layout) => normalizeTrackLayout(layout, { uid }))
|
||||
.filter((layout) => layout.id);
|
||||
return list.slice().sort((a, b) => a.startedAt - b.startedAt);
|
||||
}
|
||||
|
||||
// The layout active at `atMs` (default: now) - the latest one whose startedAt has already
|
||||
// passed. Returns "" if no layout has been configured yet (the feature is simply unused,
|
||||
// and every comparison that scopes by this id degrades back to today's unscoped behavior).
|
||||
export function getTrackLayoutIdAt(layouts, atMs = Date.now()) {
|
||||
let current = "";
|
||||
for (const layout of normalizeTrackLayouts(layouts)) {
|
||||
if (layout.startedAt > atMs) break;
|
||||
current = layout.id;
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
export function getTrackLayoutLabel(layouts, layoutId) {
|
||||
if (!layoutId) return "";
|
||||
const layout = (Array.isArray(layouts) ? layouts : []).find((item) => item.id === layoutId);
|
||||
return layout?.label || "";
|
||||
}
|
||||
|
||||
// The default label offered when adding a layout without typing a custom name, numbered
|
||||
// by how many layouts already exist (1-based, so the very first is "Layout 1").
|
||||
export function nextTrackLayoutLabel(layouts) {
|
||||
return `Layout ${(Array.isArray(layouts) ? layouts.length : 0) + 1}`;
|
||||
}
|
||||
Reference in new issue
Block a user