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:
larssand
2026-09-10 14:17:06 +02:00
parent 90df3378a6
commit fd6efe2c7e
13 changed files with 328 additions and 27 deletions

View File

@@ -1,6 +1,6 @@
import { sortableTable, sortValuesAttribute } from "./list_sorting.js";
function buildArchiveRows(state, { getEventName, getClassName }) {
function buildArchiveRows(state, { getEventName, getClassName, getTrackLayoutLabel }) {
return (state.sessions || [])
.filter((session) => session.status === "finished")
.map((session) => {
@@ -20,6 +20,7 @@ function buildArchiveRows(state, { getEventName, getClassName }) {
date: event?.date || (session.endedAt ? new Date(session.endedAt).toISOString().slice(0, 10) : ""),
winnerName: winner?.displayName || winner?.driverName || "",
adjustmentCount: (result?.adjustments || []).length,
trackLayoutLabel: getTrackLayoutLabel(state.trackLayouts, session.trackLayoutId),
};
})
.sort((left, right) => Number(right.session.endedAt || 0) - Number(left.session.endedAt || 0));
@@ -43,7 +44,7 @@ function renderArchiveDetail(row, deps) {
return `
<section class="panel archive-detail" style="margin-top:14px">
<div class="panel-header">
<h3>${escapeHtml(row.eventName)} - ${escapeHtml(session.name)}</h3>
<h3>${escapeHtml(row.eventName)} - ${escapeHtml(session.name)}${row.trackLayoutLabel ? ` <span class="badge">${escapeHtml(row.trackLayoutLabel)}</span>` : ""}</h3>
<div class="actions-inline">
${event ? `<button class="btn" id="archiveExportPdf" type="button">${t("archive.export_pdf")}</button>` : ""}
${event ? `<button class="btn" id="archiveExportJson" type="button">${t("archive.export_json")}</button>` : ""}
@@ -116,10 +117,11 @@ export function renderResultsArchiveView(deps) {
getClassName, getEventName, buildLeaderboard, getCompetitorPassings,
exportRaceResultsPdf, buildRacePackagePayload, downloadJsonFile, sanitizeFilenameSegment,
getArchiveFilters, setArchiveFilters, getSelectedSessionId, setSelectedSessionId,
getTrackLayoutLabel,
} = deps;
const filters = getArchiveFilters();
const allRows = buildArchiveRows(state, { getEventName, getClassName });
const allRows = buildArchiveRows(state, { getEventName, getClassName, getTrackLayoutLabel });
const filteredRows = allRows.filter((row) => matchesArchiveFilters(row, filters));
const selectedSessionId = getSelectedSessionId();
const selectedRow = selectedSessionId ? allRows.find((row) => row.session.id === selectedSessionId) : null;
@@ -129,13 +131,14 @@ export function renderResultsArchiveView(deps) {
const table = sortableTable(
renderTable(
[t("archive.date"), t("archive.event"), t("archive.session"), t("archive.class"), t("archive.drivers"), t("archive.winner"), t("archive.penalties_short"), ""],
[t("archive.date"), t("archive.event"), t("archive.session"), t("archive.class"), t("archive.layout"), t("archive.drivers"), t("archive.winner"), t("archive.penalties_short"), ""],
filteredRows.map((row) => `
<tr data-sort-values="${sortValuesAttribute([row.date, row.eventName, row.session.name, row.className, row.competitors.length, row.winnerName, row.adjustmentCount, null])}">
<tr data-sort-values="${sortValuesAttribute([row.date, row.eventName, row.session.name, row.className, row.trackLayoutLabel, row.competitors.length, row.winnerName, row.adjustmentCount, null])}">
<td>${escapeHtml(row.date || "-")}</td>
<td>${escapeHtml(row.eventName)}</td>
<td>${escapeHtml(row.session.name)}</td>
<td>${escapeHtml(row.className || "-")}</td>
<td>${escapeHtml(row.trackLayoutLabel || "-")}</td>
<td>${row.competitors.length}</td>
<td>${escapeHtml(row.winnerName || "-")}</td>
<td>${row.adjustmentCount || "-"}</td>
@@ -144,7 +147,7 @@ export function renderResultsArchiveView(deps) {
`)
),
"archive-sessions",
[1, 2, 3, 5]
[1, 2, 3, 4, 6]
);
dom.view.innerHTML = `