feat(training): fold-out practice stints with every lap time on Training and the driver's page (1.86.0)
This commit is contained in:
1 parent
3870510d8c
commit
73e1c0ccf3
16 files changed
+224
-5
No files matched your search
@@ -8,6 +8,12 @@ The application version is maintained in `package.json` and displayed in the adm
|
||||
|
||||
No changes recorded yet.
|
||||
|
||||
## 1.86.0
|
||||
|
||||
### Added
|
||||
|
||||
- Practice stints fold out to every lap time, a bit like the MyLaps app. Each stint is a card with its date, laps, best lap, average and duration; tap it to see every lap with a bar against the best lap, the best lap starred, slow laps (over 15% above the stint median) in red and the out lap after a break greyed out. It is on the club Training view (the 10 latest stints, above the stint analysis) and on the driver's own page (the 8 latest stints). Open cards stay open while new laps come in. Practice only - races keep their per-session table.
|
||||
|
||||
## 1.85.0
|
||||
|
||||
- **Send heats to House of RC automatically:** tick **Send heats automatically** under Manage → Participants on a race made from House of RC. After every qualifying heat or final, the race controller sends heats and qualifying by itself – never the final placings, so no driver is notified by mistake. Without internet it tries again every minute until it gets through.
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "rc-racecore",
|
||||
"version": "1.85.0",
|
||||
"version": "1.86.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "rc-racecore",
|
||||
"version": "1.85.0",
|
||||
"version": "1.86.0",
|
||||
"hasInstallScript": true,
|
||||
"dependencies": {
|
||||
"better-sqlite3": "^12.11.1",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "rc-racecore",
|
||||
"version": "1.85.0",
|
||||
"version": "1.86.0",
|
||||
"private": true,
|
||||
"description": "RC RaceCore live timing and race control with AMMC ingest and SQLite persistence",
|
||||
"engines": {
|
||||
|
||||
@@ -678,6 +678,8 @@ function buildPublicTrainingStats(allLaps, layoutLaps = allLaps) {
|
||||
number: index + 1, startedAt, lapCount: stint.laps.length,
|
||||
bestLapMs: values.length ? Math.min(...values) : 0, averageLapMs: average(values),
|
||||
durationMs: Math.max(0, endedAt - startedAt),
|
||||
// Lap times only (no timestamps) for the fold-out list on the driver's page.
|
||||
laps: stint.laps.slice(0, 300).map((lap) => ({ lapMs: lap.lapMs, excluded: Boolean(lap.excludedFromPace) })),
|
||||
};
|
||||
}).sort((left, right) => right.startedAt - left.startedAt).slice(0, 8);
|
||||
|
||||
|
||||
@@ -1663,6 +1663,10 @@ const TRANSLATIONS = {
|
||||
"training.stint_slower": "{lap} långsammare",
|
||||
"training.stint_same": "Oförändrat",
|
||||
"training.stint_analysis": "Stintanalys",
|
||||
"training.stint_average": "Snitt",
|
||||
"training.stint_lap_times": "Varvtider per stint",
|
||||
"training.stint_lap_times_hint": "Tryck på en stint för att se alla varvtider. ★ = bästa varvet, röd = över 15 % långsammare än stintens median, startvarv = första varvet efter en paus.",
|
||||
"training.stint_out_lap": "Startvarv",
|
||||
"training.stint_analysis_hint": "En passering över inställd max varvtid, eller en paus över två minuter utan maxgräns, startar en ny stint. Övergångsvarvet räknas i race men inte i pace. 5-min resultat visar 300 sekunder plus sista påbörjade varvet.",
|
||||
"training.best_stint": "Bästa stint {stint}: {laps} varv, {pace}",
|
||||
"training.stint_five_minute": "5-min resultat",
|
||||
@@ -3917,6 +3921,10 @@ const TRANSLATIONS = {
|
||||
"training.stint_slower": "{lap} slower",
|
||||
"training.stint_same": "Unchanged",
|
||||
"training.stint_analysis": "Stint analysis",
|
||||
"training.stint_average": "Average",
|
||||
"training.stint_lap_times": "Lap times per stint",
|
||||
"training.stint_lap_times_hint": "Tap a stint to see every lap time. ★ = best lap, red = over 15% slower than the stint median, out lap = first lap after a break.",
|
||||
"training.stint_out_lap": "Out lap",
|
||||
"training.stint_analysis_hint": "A passing over the configured maximum lap time, or a break over two minutes without a max limit, starts a new stint. The transition lap counts in the race but not in pace. The 5-minute result covers 300 seconds plus the final started lap.",
|
||||
"training.best_stint": "Best stint {stint}: {laps} laps, {pace}",
|
||||
"training.stint_five_minute": "5-minute result",
|
||||
|
||||
@@ -1518,3 +1518,30 @@ button {
|
||||
border: 1px solid rgba(245, 166, 35, 0.6);
|
||||
background: rgba(245, 166, 35, 0.12);
|
||||
}
|
||||
|
||||
/* Fold-out practice stints with every lap (src/stint_laps_view.js) - same block in styles.css and public_training.css. */
|
||||
.stint-laps { display: grid; gap: 8px; margin: 8px 0 14px; }
|
||||
.stint-laps-card { border: 1px solid var(--line); border-radius: 12px; background: color-mix(in srgb, var(--text) 3%, transparent); overflow: hidden; }
|
||||
.stint-laps-card > summary { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 18px; padding: 10px 14px; cursor: pointer; list-style: none; }
|
||||
.stint-laps-card > summary::-webkit-details-marker { display: none; }
|
||||
.stint-laps-card > summary::after { content: "▾"; margin-left: auto; color: var(--muted); transition: transform 0.15s; }
|
||||
.stint-laps-card[open] > summary::after { transform: rotate(180deg); }
|
||||
.stint-laps-head { display: flex; flex-direction: column; min-width: 120px; }
|
||||
.stint-laps-head small { color: var(--muted); font-size: 0.8rem; }
|
||||
.stint-laps-stats { display: flex; flex-wrap: wrap; gap: 4px 18px; }
|
||||
.stint-laps-stats > span { display: inline-flex; flex-direction: column; min-width: 4.5em; font-variant-numeric: tabular-nums; font-weight: 700; }
|
||||
.stint-laps-stats small { color: var(--muted); font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
|
||||
.stint-lap-list { margin: 0; padding: 4px 14px 12px; list-style: none; border-top: 1px solid var(--line); columns: 2 260px; column-gap: 24px; }
|
||||
.stint-lap { display: grid; grid-template-columns: 2.2em 5.5em 1fr 4.6em; align-items: center; gap: 8px; padding: 3px 0; break-inside: avoid; font-variant-numeric: tabular-nums; }
|
||||
.stint-lap-no { color: var(--muted); text-align: right; }
|
||||
.stint-lap-time { font-weight: 700; }
|
||||
.stint-lap-bar { height: 6px; border-radius: 3px; background: color-mix(in srgb, var(--text) 8%, transparent); overflow: hidden; }
|
||||
.stint-lap-bar i { display: block; height: 100%; border-radius: 3px; background: var(--muted); }
|
||||
.stint-lap-delta { color: var(--muted); font-size: 0.82rem; text-align: right; }
|
||||
.stint-lap.is-best .stint-lap-time, .stint-lap.is-best .stint-lap-delta { color: var(--green, var(--ok)); }
|
||||
.stint-lap.is-best .stint-lap-bar i { background: var(--green, var(--ok)); }
|
||||
.stint-lap.is-slow .stint-lap-time { color: var(--accent); }
|
||||
.stint-lap.is-slow .stint-lap-bar i { background: var(--accent); }
|
||||
.stint-lap.is-excluded { opacity: 0.55; }
|
||||
.stint-laps-empty { color: var(--muted); }
|
||||
.stint-laps-title { margin: 12px 0 2px; }
|
||||
+18
-1
@@ -1,3 +1,5 @@
|
||||
import { renderStintLapCards, openStintLapCardIds } from "./stint_laps_view.js";
|
||||
|
||||
const root = document.getElementById("publicTrainingRoot");
|
||||
const shareToken = decodeURIComponent(window.location.pathname.split("/").filter(Boolean).at(-1) || "");
|
||||
const requestedLanguage = new URLSearchParams(window.location.search).get("lang");
|
||||
@@ -107,6 +109,11 @@ const messages = {
|
||||
stintNumber: "Stint",
|
||||
duration: "Tid",
|
||||
noStints: "Inga stintar registrerade ännu.",
|
||||
stintLaps: "Varv",
|
||||
stintBest: "Bästa",
|
||||
stintLapList: "Varvtider",
|
||||
stintExcluded: "Startvarv",
|
||||
stintLapsHint: "Tryck på en stint för att se alla varvtider. ★ = bästa varvet, röd = över 15 % långsammare än stintens median.",
|
||||
paceBlocks: "Tempo per aktivt 30-minutersblock",
|
||||
paceBlocksHint: "Visar bara block där bilen har registrerat giltiga varv.",
|
||||
markerTitle: "Markera en biländring",
|
||||
@@ -283,6 +290,11 @@ const messages = {
|
||||
stintNumber: "Stint",
|
||||
duration: "Duration",
|
||||
noStints: "No stints have been recorded yet.",
|
||||
stintLaps: "Laps",
|
||||
stintBest: "Best",
|
||||
stintLapList: "Lap times",
|
||||
stintExcluded: "Out lap",
|
||||
stintLapsHint: "Tap a stint to see every lap time. ★ = best lap, red = over 15% slower than the stint median.",
|
||||
paceBlocks: "Pace per active 30-minute block",
|
||||
paceBlocksHint: "Only blocks containing valid recorded laps are shown.",
|
||||
markerTitle: "Mark a car change",
|
||||
@@ -641,6 +653,11 @@ function renderProfile(data) {
|
||||
: `<tr><td colspan="4">-</td></tr>`;
|
||||
const paceBuckets = Array.isArray(stats.paceBuckets) ? stats.paceBuckets : [];
|
||||
const paceBucketMarkup = paceBuckets.length ? paceBuckets.map((bucket) => `<article><span>${escapeHtml(new Date(bucket.startTs).toLocaleString(language, { dateStyle: "short", timeStyle: "short" }))}</span><strong>${formatLap(bucket.paceMs)}</strong><small>${escapeHtml(t("blockLaps", { laps: bucket.lapCount }))} · PB ${formatLap(bucket.bestLapMs)}${bucket.markerCount ? " · " + escapeHtml(t("blockMarkers", { count: bucket.markerCount })) : ""}</small></article>`).join("") : `<p class="profile-empty">-</p>`;
|
||||
// Practice: fold-out stint cards with every lap. Races/all keep the plain table.
|
||||
const stintCards = (data.lapSource || "practice") === "practice" ? renderStintLapCards(stats.stintSummaries, {
|
||||
formatLap, formatDuration: formatRaceResultTime, escapeHtml, locale: language, openIds: openStintLapCardIds(root),
|
||||
labels: { stint: t("stintNumber"), laps: t("stintLaps"), best: t("stintBest"), average: t("average"), duration: t("duration"), lap: t("stintLapList"), excluded: t("stintExcluded"), empty: t("noStints") },
|
||||
}) : "";
|
||||
const stintRows = stats.stintSummaries.length ? stats.stintSummaries.slice(0, 6).map((stint) => `
|
||||
<tr><td>${stint.number}</td><td>${escapeHtml(new Date(stint.startedAt).toLocaleString(language, { dateStyle: "short", timeStyle: "short" }))}</td><td>${stint.lapCount}</td><td>${formatLap(stint.bestLapMs)}</td><td>${formatLap(stint.averageLapMs)}</td><td>${formatRaceResultTime(stint.durationMs)}</td></tr>
|
||||
`).join("") : `<tr><td colspan="6">${escapeHtml(t("noStints"))}</td></tr>`;
|
||||
@@ -880,7 +897,7 @@ function renderProfile(data) {
|
||||
<div class="profile-pace-blocks"><h3>${escapeHtml(t("paceBlocks"))}</h3><p>${escapeHtml(t("paceBlocksHint"))}</p><div>${paceBucketMarkup}</div></div>
|
||||
<div class="profile-stint-table-wrap">
|
||||
<h3>${escapeHtml(t("stintDetails"))}</h3>
|
||||
<div class="profile-history-wrap"><table class="profile-history"><thead><tr><th>${escapeHtml(t("stintNumber"))}</th><th>${escapeHtml(t("date"))}</th><th>${escapeHtml(t("laps"))}</th><th>${escapeHtml(t("best"))}</th><th>${escapeHtml(t("average"))}</th><th>${escapeHtml(t("duration"))}</th></tr></thead><tbody>${stintRows}</tbody></table></div>
|
||||
${stintCards ? `<p>${escapeHtml(t("stintLapsHint"))}</p>${stintCards}` : `<div class="profile-history-wrap"><table class="profile-history"><thead><tr><th>${escapeHtml(t("stintNumber"))}</th><th>${escapeHtml(t("date"))}</th><th>${escapeHtml(t("laps"))}</th><th>${escapeHtml(t("best"))}</th><th>${escapeHtml(t("average"))}</th><th>${escapeHtml(t("duration"))}</th></tr></thead><tbody>${stintRows}</tbody></table></div>`}
|
||||
</div>
|
||||
</details>
|
||||
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
// Practice stints as fold-out cards with every lap time (a bit like the MyLaps app).
|
||||
// Shared by the club Training view and the driver's own page (public_training.js),
|
||||
// so it takes its formatters and labels as arguments and imports nothing.
|
||||
|
||||
const MAX_LAPS_SHOWN = 300;
|
||||
|
||||
// laps: [{ lapMs, excluded }] in driving order. excluded = the lap that opened the stint
|
||||
// after a break (it counts as a lap but not for pace). Slow = over 15% above the median,
|
||||
// the same "mistake" line the stint analysis uses.
|
||||
export function buildStintLapRows(laps) {
|
||||
const list = (Array.isArray(laps) ? laps : [])
|
||||
.map((lap) => ({ lapMs: Math.round(Number(lap?.lapMs || 0)), excluded: Boolean(lap?.excluded) }))
|
||||
.filter((lap) => lap.lapMs > 0)
|
||||
.slice(0, MAX_LAPS_SHOWN);
|
||||
const values = list.filter((lap) => !lap.excluded).map((lap) => lap.lapMs).sort((a, b) => a - b);
|
||||
const bestMs = values[0] || 0;
|
||||
const medianMs = values.length ? values[Math.floor((values.length - 1) / 2)] : 0;
|
||||
return list.map((lap, index) => ({
|
||||
number: index + 1,
|
||||
lapMs: lap.lapMs,
|
||||
excluded: lap.excluded,
|
||||
best: Boolean(bestMs && !lap.excluded && lap.lapMs === bestMs),
|
||||
slow: Boolean(medianMs && !lap.excluded && lap.lapMs > medianMs * 1.15),
|
||||
deltaMs: bestMs && !lap.excluded ? lap.lapMs - bestMs : null,
|
||||
// 1% slower = 5% shorter bar, so a few tenths show; 18% or more bottoms out.
|
||||
barPct: bestMs && !lap.excluded ? Math.max(8, Math.round(100 - ((lap.lapMs - bestMs) / bestMs) * 500)) : 0,
|
||||
}));
|
||||
}
|
||||
|
||||
// stints: [{ id, number, startedAt, lapCount, bestLapMs, averageLapMs, durationMs, laps }]
|
||||
// labels: { stint, laps, best, average, duration, lap, excluded, empty }
|
||||
// openIds: cards to keep open - both pages re-render as laps come in, which would
|
||||
// otherwise fold every card shut (collect them with openStintLapCardIds first).
|
||||
export function renderStintLapCards(stints, { formatLap, formatDuration, escapeHtml, labels, locale, openIds = new Set() } = {}) {
|
||||
const items = Array.isArray(stints) ? stints.filter((stint) => Array.isArray(stint?.laps) && stint.laps.length) : [];
|
||||
if (!items.length) return `<p class="stint-laps-empty">${escapeHtml(labels.empty)}</p>`;
|
||||
return `<div class="stint-laps">${items.map((stint) => {
|
||||
const rows = buildStintLapRows(stint.laps);
|
||||
const started = new Date(Number(stint.startedAt || 0)).toLocaleString(locale, { dateStyle: "short", timeStyle: "short" });
|
||||
const lapItems = rows.map((row) => `
|
||||
<li class="stint-lap${row.best ? " is-best" : ""}${row.slow ? " is-slow" : ""}${row.excluded ? " is-excluded" : ""}">
|
||||
<span class="stint-lap-no">${row.number}</span>
|
||||
<span class="stint-lap-time">${escapeHtml(formatLap(row.lapMs))}</span>
|
||||
<span class="stint-lap-bar"><i style="width:${row.barPct}%"></i></span>
|
||||
<span class="stint-lap-delta">${row.excluded ? escapeHtml(labels.excluded) : row.best ? "★" : `+${(row.deltaMs / 1000).toFixed(3)}`}</span>
|
||||
</li>`).join("");
|
||||
const id = String(stint.id ?? stint.startedAt ?? stint.number);
|
||||
return `
|
||||
<details class="stint-laps-card" data-stint-id="${escapeHtml(id)}"${openIds.has(id) ? " open" : ""}>
|
||||
<summary>
|
||||
<span class="stint-laps-head"><strong>${escapeHtml(labels.stint)} ${Number(stint.number || 0)}</strong><small>${escapeHtml(started)}</small></span>
|
||||
<span class="stint-laps-stats"><span><small>${escapeHtml(labels.laps)}</small>${Number(stint.lapCount || rows.length)}</span>
|
||||
<span><small>${escapeHtml(labels.best)}</small>${escapeHtml(formatLap(stint.bestLapMs))}</span>
|
||||
<span><small>${escapeHtml(labels.average)}</small>${escapeHtml(formatLap(stint.averageLapMs))}</span>
|
||||
<span><small>${escapeHtml(labels.duration)}</small>${escapeHtml(formatDuration(stint.durationMs))}</span></span>
|
||||
</summary>
|
||||
<ol class="stint-lap-list" aria-label="${escapeHtml(labels.lap)}">${lapItems}</ol>
|
||||
</details>`;
|
||||
}).join("")}</div>`;
|
||||
}
|
||||
|
||||
export function openStintLapCardIds(container) {
|
||||
return new Set([...(container?.querySelectorAll?.(".stint-laps-card[open]") || [])].map((card) => card.dataset.stintId));
|
||||
}
|
||||
@@ -4960,3 +4960,30 @@ tr:has(> td > .medal-3) { background: linear-gradient(90deg, rgba(205, 127, 60,
|
||||
.hor-event { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: transparent; color: inherit; cursor: pointer; }
|
||||
.hor-event:hover, .hor-event:focus-visible { border-color: var(--accent); }
|
||||
.hor-event small { opacity: 0.75; }
|
||||
|
||||
/* Fold-out practice stints with every lap (src/stint_laps_view.js) - same block in styles.css and public_training.css. */
|
||||
.stint-laps { display: grid; gap: 8px; margin: 8px 0 14px; }
|
||||
.stint-laps-card { border: 1px solid var(--line); border-radius: 12px; background: color-mix(in srgb, var(--text) 3%, transparent); overflow: hidden; }
|
||||
.stint-laps-card > summary { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 18px; padding: 10px 14px; cursor: pointer; list-style: none; }
|
||||
.stint-laps-card > summary::-webkit-details-marker { display: none; }
|
||||
.stint-laps-card > summary::after { content: "▾"; margin-left: auto; color: var(--muted); transition: transform 0.15s; }
|
||||
.stint-laps-card[open] > summary::after { transform: rotate(180deg); }
|
||||
.stint-laps-head { display: flex; flex-direction: column; min-width: 120px; }
|
||||
.stint-laps-head small { color: var(--muted); font-size: 0.8rem; }
|
||||
.stint-laps-stats { display: flex; flex-wrap: wrap; gap: 4px 18px; }
|
||||
.stint-laps-stats > span { display: inline-flex; flex-direction: column; min-width: 4.5em; font-variant-numeric: tabular-nums; font-weight: 700; }
|
||||
.stint-laps-stats small { color: var(--muted); font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
|
||||
.stint-lap-list { margin: 0; padding: 4px 14px 12px; list-style: none; border-top: 1px solid var(--line); columns: 2 260px; column-gap: 24px; }
|
||||
.stint-lap { display: grid; grid-template-columns: 2.2em 5.5em 1fr 4.6em; align-items: center; gap: 8px; padding: 3px 0; break-inside: avoid; font-variant-numeric: tabular-nums; }
|
||||
.stint-lap-no { color: var(--muted); text-align: right; }
|
||||
.stint-lap-time { font-weight: 700; }
|
||||
.stint-lap-bar { height: 6px; border-radius: 3px; background: color-mix(in srgb, var(--text) 8%, transparent); overflow: hidden; }
|
||||
.stint-lap-bar i { display: block; height: 100%; border-radius: 3px; background: var(--muted); }
|
||||
.stint-lap-delta { color: var(--muted); font-size: 0.82rem; text-align: right; }
|
||||
.stint-lap.is-best .stint-lap-time, .stint-lap.is-best .stint-lap-delta { color: var(--green, var(--ok)); }
|
||||
.stint-lap.is-best .stint-lap-bar i { background: var(--green, var(--ok)); }
|
||||
.stint-lap.is-slow .stint-lap-time { color: var(--accent); }
|
||||
.stint-lap.is-slow .stint-lap-bar i { background: var(--accent); }
|
||||
.stint-lap.is-excluded { opacity: 0.55; }
|
||||
.stint-laps-empty { color: var(--muted); }
|
||||
.stint-laps-title { margin: 12px 0 2px; }
|
||||
@@ -530,6 +530,10 @@ export function buildTrainingStintAnalysis(state, driverId, classId = "", { layo
|
||||
lapCount: values.length,
|
||||
bestLapMs: values.length ? Math.min(...values) : 0,
|
||||
paceMs: trimmedAverage(values),
|
||||
averageLapMs: values.length ? Math.round(values.reduce((sum, value) => sum + value, 0) / values.length) : 0,
|
||||
// Every lap in driving order for the fold-out lap list; the opening lap after a break
|
||||
// is kept but flagged, since it counts as a lap but not for pace.
|
||||
laps: (stint.laps || []).filter((lap) => Number(lap.lapMs || 0) > 500).map((lap) => ({ lapMs: Number(lap.lapMs), excluded: Boolean(lap.excludedFromPace) })),
|
||||
racePace10Ms: values.length >= 10 ? getBestConsecutiveAverage(laps, 10) : 0,
|
||||
fiveMinuteResult: getBestTrainingDurationResult([stint], 5 * 60 * 1000),
|
||||
mistakes: outlierLaps,
|
||||
|
||||
@@ -4,6 +4,7 @@ import { normalizeTrackLayouts } from "./track_layouts_logic.js";
|
||||
import { renderTrackLayoutBar, bindTrackLayoutBar } from "./track_layout_bar.js";
|
||||
import { buildTrainingRaceSessions } from "./training_logic.js";
|
||||
import { normalizePublicBaseUrl } from "./public_url.js";
|
||||
import { renderStintLapCards, openStintLapCardIds } from "./stint_laps_view.js";
|
||||
|
||||
// Which track layout the pace/record/consistency numbers are for: "current" (default),
|
||||
// "all" (overall), "none" (laps from before any layout existed), or a layout id. Module
|
||||
@@ -421,12 +422,20 @@ export function renderTrainingView(deps) {
|
||||
? featuredStints.map((row) => renderStintRow(row, { t, escapeHtml, formatLap, formatRaceClock, state })).join("")
|
||||
: `<tr><td colspan="11">${escapeHtml(t("training.no_stints"))}</td></tr>`;
|
||||
const allStintRows = stintAnalysis.rows.map((row) => renderStintRow(row, { t, escapeHtml, formatLap, formatRaceClock, state })).join("");
|
||||
// The 10 latest stints as fold-out cards with every lap, above the analysis table.
|
||||
const stintLapCards = renderStintLapCards(stintAnalysis.rows.slice(0, 10), {
|
||||
formatLap, formatDuration: formatRaceClock, escapeHtml, openIds: openStintLapCardIds(document),
|
||||
labels: { stint: t("training.stint"), laps: t("training.laps"), best: t("training.best_lap"), average: t("training.stint_average"), duration: t("training.stint_duration"), lap: t("training.stint_lap_times"), excluded: t("training.stint_out_lap"), empty: t("training.no_stints") },
|
||||
});
|
||||
// Stints are for practice only; with "Races" chosen the race-session table replaces them.
|
||||
const stintSectionMarkup = `
|
||||
<div class="training-section-title">
|
||||
<div><h3>${escapeHtml(t("training.stint_analysis"))}</h3><p class="hint">${escapeHtml(t("training.stint_analysis_hint"))}</p></div>
|
||||
${stintAnalysis.best ? `<span class="badge success">${escapeHtml(t("training.best_stint", { stint: stintAnalysis.best.number, laps: stintAnalysis.best.lapCount, pace: formatLap(stintAnalysis.best.paceMs) }))}</span>` : ""}
|
||||
</div>
|
||||
<h4 class="stint-laps-title">${escapeHtml(t("training.stint_lap_times"))}</h4>
|
||||
<p class="hint">${escapeHtml(t("training.stint_lap_times_hint"))}</p>
|
||||
${stintLapCards}
|
||||
<div class="table-wrap training-history-wrap">
|
||||
<table data-sort-id="training-stints-featured" class="training-history-table training-stint-table"><thead>${stintColumns}</thead><tbody>${featuredStintRows}</tbody></table>
|
||||
</div>
|
||||
|
||||
@@ -42,10 +42,18 @@ export async function runTrainingSourceSmoke({ evaluate, navigate, savedState, w
|
||||
assert.equal(await evaluate(`document.getElementById("training-source").value`), "practice", "practice is the default");
|
||||
assert.equal(await evaluate(`Boolean(document.querySelector('[data-sort-id="training-stints-featured"]'))`), true, "stints for practice");
|
||||
assert.equal(await evaluate(`document.querySelectorAll(".training-race-origin").length`), 0, "no race laps mixed into practice");
|
||||
// The stint card folds out to every lap, with the best lap starred.
|
||||
assert.equal(await evaluate(`document.querySelectorAll(".stint-laps-card").length`), 1, "one practice stint card");
|
||||
await evaluate(`document.querySelector(".stint-laps-card > summary").click()`);
|
||||
assert.equal(await evaluate(`document.querySelector(".stint-laps-card").open`), true, "the card opens");
|
||||
assert.deepEqual(await evaluate(`[...document.querySelectorAll(".stint-laps-card .stint-lap-time")].map((cell) => cell.textContent.trim())`), ["0:20.000", "0:20.000", "0:19.500", "0:19.500"]);
|
||||
assert.equal(await evaluate(`document.querySelectorAll(".stint-laps-card .stint-lap.is-best").length`), 2, "both 19.500 laps are best");
|
||||
console.log("PASS training stats: a practice stint folds out to every lap time");
|
||||
|
||||
await evaluate(`(() => { const select = document.getElementById("training-source"); select.value = "race"; select.dispatchEvent(new Event("change")); })()`);
|
||||
await waitFor(async () => Boolean(await evaluate(`document.querySelector('[data-sort-id="training-race-sessions"]')`)), "race sessions table");
|
||||
assert.equal(await evaluate(`Boolean(document.querySelector('[data-sort-id="training-stints-featured"]'))`), false, "no stints for races");
|
||||
assert.equal(await evaluate(`document.querySelectorAll(".stint-laps-card").length`), 0, "no stint cards for races");
|
||||
const row = await evaluate(`[...document.querySelectorAll('[data-sort-id="training-race-sessions"] tbody tr')].map((tr) => [...tr.children].map((td) => td.textContent.trim()))[0]`);
|
||||
assert.equal(row[1], "🏁 TS Winter #3 TS 2WD · Kval 2 · TS Winter Cup", "race, session and series");
|
||||
assert.equal(row[2], "3");
|
||||
|
||||
@@ -520,3 +520,12 @@ test("each class in a mobile profile carries the time of its latest lap, so the
|
||||
profile = buildPublicTrainingProfile(state, DRIVER_ONE_TOKEN, new Date(now).toISOString());
|
||||
assert.equal(lastLapAt("class_2"), now - 1000);
|
||||
});
|
||||
|
||||
test("public profile stint summaries carry lap times only, for the fold-out stint cards", () => {
|
||||
const profile = buildPublicTrainingProfile(buildState(), DRIVER_ONE_TOKEN, "");
|
||||
const stints = profile.classProfiles[0].stats.stintSummaries;
|
||||
assert.ok(stints.length > 0);
|
||||
const laps = stints.flatMap((stint) => stint.laps);
|
||||
assert.equal(laps.length, stints.reduce((sum, stint) => sum + stint.lapCount, 0));
|
||||
laps.forEach((lap) => assert.deepEqual(Object.keys(lap).sort(), ["excluded", "lapMs"]));
|
||||
});
|
||||
@@ -3,7 +3,8 @@ import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
import vm from "node:vm";
|
||||
|
||||
const source = fs.readFileSync(new URL("../src/public_training.js", import.meta.url), "utf8");
|
||||
// The page is an ES module; drop its imports to run it as a plain script (rendering is stubbed below).
|
||||
const source = fs.readFileSync(new URL("../src/public_training.js", import.meta.url), "utf8").replace(/^import .*$/gm, "");
|
||||
|
||||
function profileHarness() {
|
||||
const ui = { editing: false, saving: false, requests: 0, renders: 0, html: "existing profile" };
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import "./auth.test.js";
|
||||
import "./backend_url.test.js";
|
||||
import "./houseofrc_logic.test.js";
|
||||
import "./stint_laps_view.test.js";
|
||||
import "./judging_penalties.test.js";
|
||||
import "./practice_rank.test.js";
|
||||
import "./team_race_logic.test.js";
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { buildStintLapRows, renderStintLapCards } from "../src/stint_laps_view.js";
|
||||
import { buildTrainingStintAnalysis } from "../src/training_logic.js";
|
||||
|
||||
const escapeHtml = (value) => String(value).replace(/[&<>"]/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """ })[c]);
|
||||
const labels = { stint: "Stint", laps: "Varv", best: "Bästa", average: "Snitt", duration: "Tid", lap: "Varvtider", excluded: "Startvarv", empty: "Inga" };
|
||||
const fmt = (ms) => (ms / 1000).toFixed(3);
|
||||
|
||||
test("buildStintLapRows marks best, slow and the out lap, with deltas against the best lap", () => {
|
||||
const rows = buildStintLapRows([{ lapMs: 150000, excluded: true }, { lapMs: 13500 }, { lapMs: 13201 }, { lapMs: 13400 }, { lapMs: 16000 }]);
|
||||
assert.deepEqual(rows.map((row) => row.number), [1, 2, 3, 4, 5]);
|
||||
assert.equal(rows[0].excluded, true);
|
||||
assert.equal(rows[0].deltaMs, null, "the out lap is not compared");
|
||||
assert.equal(rows[2].best, true);
|
||||
assert.equal(rows[1].deltaMs, 299);
|
||||
assert.equal(rows[4].slow, true, "over 15% above the median");
|
||||
assert.equal(rows[2].barPct, 100);
|
||||
});
|
||||
|
||||
test("renderStintLapCards lists every lap and keeps open cards open", () => {
|
||||
const stints = [{ id: "s1", number: 2, startedAt: 1, lapCount: 2, bestLapMs: 13201, averageLapMs: 13300, durationMs: 26601, laps: [{ lapMs: 13400 }, { lapMs: 13201 }] }];
|
||||
const html = renderStintLapCards(stints, { formatLap: fmt, formatDuration: fmt, escapeHtml, labels, openIds: new Set(["s1"]) });
|
||||
assert.equal((html.match(/class="stint-lap[ "]/g) || []).length, 2);
|
||||
assert.match(html, /data-stint-id="s1" open/);
|
||||
assert.match(html, /\+0\.199/);
|
||||
assert.match(html, /★/);
|
||||
assert.match(renderStintLapCards([], { escapeHtml, labels }), /Inga/);
|
||||
});
|
||||
|
||||
test("buildTrainingStintAnalysis rows carry their laps for the fold-out list", () => {
|
||||
const ledger = [10_000, 23_000, 36_500].map((timestamp, index) => ({ driverId: "d1", sourceId: "tp", sessionId: "p1", timestamp, lapMs: [10_000, 13_000, 13_500][index] }));
|
||||
const { rows } = buildTrainingStintAnalysis({ training: { ledger } }, "d1");
|
||||
assert.deepEqual(rows[0].laps.map((lap) => lap.lapMs), [10_000, 13_000, 13_500]);
|
||||
assert.equal(rows[0].averageLapMs, 12_167);
|
||||
});
|
||||
Reference in new issue
Block a user