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
@@ -133,6 +133,28 @@ export function ensureSessionResult(sessionId, { state }) {
|
||||
|
||||
|
||||
|
||||
// The all-time fastest lap among every other session in the same class, used to decide
|
||||
// whether a live lap deserves the "track_record" audio cue. Scoped to sessions run on the
|
||||
// same track layout as `session` (see track_layouts_logic.js): once a club starts using
|
||||
// layouts, a lap from a previous, different layout can no longer "beat" today's record.
|
||||
// Sessions with no trackLayoutId (i.e. every session recorded before this feature existed,
|
||||
// or an installation that has never configured a layout) compare only against each other -
|
||||
// this keeps the feature fully inert until a club actually adds a layout.
|
||||
export function getTrackRecordMs(session, { state }) {
|
||||
const event = state.events.find((item) => item.id === session?.eventId);
|
||||
if (!event?.classId) return null;
|
||||
const candidates = state.sessions.filter((item) =>
|
||||
item.id !== session?.id
|
||||
&& String(item.trackLayoutId || "") === String(session?.trackLayoutId || "")
|
||||
&& state.events.find((race) => race.id === item.eventId)?.classId === event.classId);
|
||||
const values = candidates
|
||||
.flatMap((item) => Object.values(state.resultsBySession[item.id]?.competitors || {}).map((row) => Number(row.bestLapMs || 0)))
|
||||
.filter((value) => value > 500);
|
||||
return values.length ? Math.min(...values) : null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
export function buildLeaderboard(session, { ensureSessionResult, getSessionTargetMs, getCompetitorPassings, isCountedPassing, getCompetitorElapsedMs, getCompetitorSeedMetric, getSessionLapWindow, getPassingValidationLabel, formatSeedMetric, formatRaceClock, formatLeaderboardGap, formatLapDelta, formatLap, t }) {
|
||||
const result = ensureSessionResult(session.id);
|
||||
const sessionType = String(session.type || "").toLowerCase();
|
||||
|
||||
Reference in new issue
Block a user