feat(training): Standard / Pro switch on the driver's page; purple day-best lap and stint consistency (1.87.0)

This commit is contained in:
larssand committed 2026-11-09 22:44:47 +01:00
1 parent 73e1c0ccf3
commit 0caf50254a
13 files changed
+204 -28

No files matched your search

+11
View File
@@ -8,6 +8,17 @@ The application version is maintained in `package.json` and displayed in the adm
No changes recorded yet.
## 1.87.0
### Added
- **Standard / Pro switch on the driver's own page:** **Pro** is a clean practice view without goals, challenges, exercises or settings - just the practice day at the top (laps, stints, drive time, best, average and personal best today) and the fold-out stint cards. **Standard** is the page as before. The phone remembers the choice, and a link with `?mode=pro` opens straight in Pro.
- **Stint cards:** the fastest lap of the stint is green and the fastest lap of the day is purple; each stint also shows its total time and consistency (on Training too).
### Fixed
- Stint duration on the driver's page now reads "5:14" instead of a long race-clock format.
## 1.86.0
### Added
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "rc-racecore",
"version": "1.86.0",
"version": "1.87.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "rc-racecore",
"version": "1.86.0",
"version": "1.87.0",
"hasInstallScript": true,
"dependencies": {
"better-sqlite3": "^12.11.1",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "rc-racecore",
"version": "1.86.0",
"version": "1.87.0",
"private": true,
"description": "RC RaceCore live timing and race control with AMMC ingest and SQLite persistence",
"engines": {
+1
View File
@@ -678,6 +678,7 @@ 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),
consistencyPct: values.length >= 3 ? Math.round(publicTrainingSpread(values) * 10) / 10 : null,
// 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) })),
};
+4 -2
View File
@@ -1665,8 +1665,9 @@ const TRANSLATIONS = {
"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_lap_times_hint": "Tryck på en stint för att se alla varvtider. grön = stintens snabbaste varv, lila = dagens snabbaste, röd = över 15 % långsammare än stintens median, startvarv = första varvet efter en paus.",
"training.stint_out_lap": "Startvarv",
"training.stint_total_time": "Totaltid",
"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",
@@ -3923,8 +3924,9 @@ const TRANSLATIONS = {
"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_lap_times_hint": "Tap a stint to see every lap time. green = fastest lap of the stint, purple = fastest of the day, red = over 15% slower than the stint median, out lap = first lap after a break.",
"training.stint_out_lap": "Out lap",
"training.stint_total_time": "Total time",
"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",
+21 -3
View File
@@ -1522,13 +1522,14 @@ button {
/* 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 { position: relative; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 18px; padding: 10px 36px 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 > summary::after { content: "▾"; position: absolute; top: 12px; right: 14px; 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 { display: grid; grid-template-columns: repeat(5, auto); gap: 6px 18px; }
@media (max-width: 520px) { .stint-laps-stats { width: 100%; grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.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; }
@@ -1540,8 +1541,25 @@ button {
.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-day-best .stint-lap-time, .stint-lap.is-day-best .stint-lap-delta, .stint-laps-stats .is-day-best { color: #b67cff; }
.stint-lap.is-day-best .stint-lap-bar i { background: #a259ff; }
.stint-laps-stats .is-best { color: var(--green, var(--ok)); }
.stint-laps-stats .is-best small, .stint-laps-stats .is-day-best small { color: var(--muted); }
.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; }
/* Standard / Pro mode switch: Pro keeps the header, the name and today's stints only. */
.profile-mode-switch { position: absolute; top: 14px; right: 14px; z-index: 1; display: inline-flex; padding: 3px; border: 1px solid var(--line); border-radius: 999px; background: color-mix(in srgb, var(--bg) 70%, transparent); }
.profile-mode-switch button { padding: 6px 14px; border: 0; border-radius: 999px; background: transparent; color: var(--muted); font: inherit; font-size: 0.82rem; font-weight: 700; cursor: pointer; }
.profile-mode-switch button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.public-training-root.is-pro > :not(.profile-header):not(.profile-hero):not(.profile-pro) { display: none !important; }
.public-training-root.is-pro #profileSource, .public-training-root.is-pro #profileLayout { display: none; }
.public-training-root.is-pro .profile-class-select:has(#profileSource), .public-training-root.is-pro .profile-class-select:has(#profileLayout) { display: none; }
.profile-pro { display: grid; gap: 14px; margin-top: 14px; }
.profile-pro .profile-stat-grid { margin: 0; grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 520px) { .profile-pro .profile-stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.profile-pro-stints .profile-card-body > p { margin: 0 0 6px; color: var(--muted); font-size: 0.86rem; }
@media (max-width: 520px) { .profile-mode-switch { position: static; margin-bottom: 12px; } }
+87 -5
View File
@@ -10,6 +10,14 @@ const DEFAULT_TIMER_CONFIG = Object.freeze({ pushMinutes: 10, controlMinutes: 10
const MAX_TIMER_BLOCK_MINUTES = 120;
let selectedClassId = new URLSearchParams(window.location.search).get("class") || "";
let selectedLayout = new URLSearchParams(window.location.search).get("layout") || "current";
// "pro" = a clean practice view: today's numbers and the stint cards, nothing else.
// From the link (?mode=pro) first, else what this phone chose last time.
const MODE_STORAGE_KEY = "rcPublicTrainingMode";
let profileMode = (() => {
const fromUrl = new URLSearchParams(window.location.search).get("mode");
if (fromUrl === "pro" || fromUrl === "standard") return fromUrl;
try { return localStorage.getItem(MODE_STORAGE_KEY) === "pro" ? "pro" : "standard"; } catch { return "standard"; }
})();
let selectedSource = new URLSearchParams(window.location.search).get("source") || "practice";
const messages = {
@@ -25,6 +33,17 @@ const messages = {
loadError: "Kunde inte läsa träningsprofilen. Länken kan vara avstängd eller ersatt.",
development: "Förarutveckling",
class: "Klass",
modePro: "Pro",
modeStandard: "Standard",
stintTotal: "Totaltid",
stintConsistency: "Jämnhet",
todayAverage: "Snitt idag",
todayDriveTime: "Körtid idag",
modeLabel: "Visning",
todayLaps: "Varv idag",
todayBest: "Bästa idag",
personalBest: "Personbästa",
todayStints: "Stintar idag",
drivingOtherClass: "Dina senaste varv i dag är i {className}. Passet och övningarna räknar bara vald klass.",
switchClass: "Byt till {className}",
layoutStats: "Banlayout",
@@ -113,7 +132,7 @@ const messages = {
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.",
stintLapsHint: "Tryck på en stint för att se alla varvtider. Grön = stintens snabbaste varv, lila = dagens snabbaste, 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",
@@ -206,6 +225,17 @@ const messages = {
loadError: "The training profile could not be loaded. The link may be disabled or replaced.",
development: "Driver development",
class: "Class",
modePro: "Pro",
modeStandard: "Standard",
stintTotal: "Total time",
stintConsistency: "Consistency",
todayAverage: "Average today",
todayDriveTime: "Drive time today",
modeLabel: "View",
todayLaps: "Laps today",
todayBest: "Best today",
personalBest: "Personal best",
todayStints: "Stints today",
drivingOtherClass: "Your latest laps today are in {className}. The pass and the exercises only count the selected class.",
switchClass: "Switch to {className}",
layoutStats: "Track layout",
@@ -294,7 +324,7 @@ const messages = {
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.",
stintLapsHint: "Tap a stint to see every lap time. Green = fastest lap of the stint, purple = fastest of the day, 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",
@@ -413,6 +443,12 @@ function formatRaceResultTime(ms) {
return `${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}.${String(centiseconds).padStart(2, "0")}:${String(millis).padStart(3, "0")}`;
}
// "5:14" - how long a stint lasted.
function formatStintDuration(ms) {
const seconds = Math.max(0, Math.round(Number(ms || 0) / 1000));
return `${Math.floor(seconds / 60)}:${String(seconds % 60).padStart(2, "0")}`;
}
function formatTimer(ms) {
const seconds = Math.max(0, Math.ceil(ms / 1000));
return `${String(Math.floor(seconds / 60)).padStart(2, "0")}:${String(seconds % 60).padStart(2, "0")}`;
@@ -654,9 +690,11 @@ function renderProfile(data) {
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 proMode = profileMode === "pro";
root.classList.toggle("is-pro", proMode);
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") },
formatLap, formatDuration: formatStintDuration, escapeHtml, locale: language, openIds: openStintLapCardIds(root),
labels: { stint: t("stintNumber"), laps: t("stintLaps"), best: t("stintBest"), average: t("average"), duration: t("stintTotal"), consistency: t("stintConsistency"), 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>
@@ -677,6 +715,10 @@ function renderProfile(data) {
</header>
<section class="profile-hero">
<div class="profile-mode-switch" role="group" aria-label="${escapeHtml(t("modeLabel"))}">
<button type="button" data-profile-mode="standard" aria-pressed="${!proMode}">${escapeHtml(t("modeStandard"))}</button>
<button type="button" data-profile-mode="pro" aria-pressed="${proMode}">${escapeHtml(t("modePro"))}</button>
</div>
<span class="profile-eyebrow">${escapeHtml(t("development"))}</span>
<h1>${escapeHtml(profile.name)}</h1>
<div class="profile-meta">
@@ -688,6 +730,8 @@ function renderProfile(data) {
${drivingOtherClass ? `<p class="profile-class-switch">${escapeHtml(t("drivingOtherClass", { className: drivingOtherClass.className || drivingOtherClass.classId }))} <button type="button" class="profile-button" data-switch-class="${escapeHtml(drivingOtherClass.classId)}">${escapeHtml(t("switchClass", { className: drivingOtherClass.className || drivingOtherClass.classId }))}</button></p>` : ""}
</section>
${proMode ? renderProSection(stats, stintCards) : ""}
<section class="profile-stat-grid">
${renderStat(t("laps"), stats.totalLaps)}
${renderStat(t("days"), stats.trainingDays)}
@@ -897,7 +941,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>
${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>`}
${stintCards && !proMode ? `<p>${escapeHtml(t("stintLapsHint"))}</p>${stintCards}` : 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>
@@ -1003,11 +1047,49 @@ function renderProfile(data) {
lastTimerPhase = "";
renderProfile(profileData);
});
root.querySelectorAll("[data-profile-mode]").forEach((button) => button.addEventListener("click", () => setProfileMode(button.dataset.profileMode)));
bindTimerControls();
updateTimerDisplay();
bindExerciseControls();
}
function setProfileMode(mode) {
profileMode = mode === "pro" ? "pro" : "standard";
try { localStorage.setItem(MODE_STORAGE_KEY, profileMode); } catch { /* private mode: just this visit */ }
const nextUrl = new URL(window.location.href);
if (profileMode === "pro") nextUrl.searchParams.set("mode", "pro");
else nextUrl.searchParams.delete("mode");
// Stints are practice only, so Pro always reads practice laps.
const reload = profileMode === "pro" && selectedSource !== "practice";
if (reload) { selectedSource = "practice"; nextUrl.searchParams.delete("source"); }
window.history.replaceState({}, "", nextUrl);
if (reload) loadProfile();
else renderProfile(profileData);
}
// Pro: today's numbers and the fold-out stint cards, nothing else.
function renderProSection(stats, stintCards) {
const todayKey = getLocalDayKey(Date.now());
const today = (stats.dailySummaries || []).find((day) => day.dateKey === todayKey);
const todaysStints = (stats.stintSummaries || []).filter((stint) => getLocalDayKey(stint.startedAt) === todayKey);
const driveTimeMs = todaysStints.reduce((sum, stint) => sum + Number(stint.durationMs || 0), 0);
return `
<section class="profile-pro">
<div class="profile-stat-grid">
${renderStat(t("todayLaps"), Number(today?.laps || 0))}
${renderStat(t("todayStints"), todaysStints.length)}
${renderStat(t("todayDriveTime"), driveTimeMs ? formatStintDuration(driveTimeMs) : "-")}
${renderStat(t("todayBest"), formatLap(today?.bestLapMs))}
${renderStat(t("todayAverage"), formatLap(today?.averageLapMs))}
${renderStat(t("personalBest"), formatLap(stats.bestLapMs))}
</div>
<article class="profile-card profile-pro-stints">
<div class="profile-card-head"><h2>${escapeHtml(t("stintDetails"))}</h2></div>
<div class="profile-card-body"><p>${escapeHtml(t("stintLapsHint"))}</p>${stintCards || `<p>${escapeHtml(t("noStints"))}</p>`}</div>
</article>
</section>`;
}
function renderStat(label, value) {
return `<article class="profile-card profile-stat"><span>${escapeHtml(label)}</span><strong>${escapeHtml(value)}</strong></article>`;
}
+32 -8
View File
@@ -7,7 +7,8 @@ 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) {
// dayBestMs: the fastest lap that day over every stint - shown purple, as in timing apps.
export function buildStintLapRows(laps, { dayBestMs = 0 } = {}) {
const list = (Array.isArray(laps) ? laps : [])
.map((lap) => ({ lapMs: Math.round(Number(lap?.lapMs || 0)), excluded: Boolean(lap?.excluded) }))
.filter((lap) => lap.lapMs > 0)
@@ -20,6 +21,7 @@ export function buildStintLapRows(laps) {
lapMs: lap.lapMs,
excluded: lap.excluded,
best: Boolean(bestMs && !lap.excluded && lap.lapMs === bestMs),
dayBest: Boolean(dayBestMs && !lap.excluded && lap.lapMs === dayBestMs),
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.
@@ -28,21 +30,25 @@ export function buildStintLapRows(laps) {
}
// stints: [{ id, number, startedAt, lapCount, bestLapMs, averageLapMs, durationMs, laps }]
// labels: { stint, laps, best, average, duration, lap, excluded, empty }
// labels: { stint, laps, best, average, duration, consistency, lap, excluded, empty }
// consistency = spread between the 10% and 90% laps as % of the average (lower = steadier).
// 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() } = {}) {
// allStints: every stint known (not just the ones shown), for the day's fastest lap.
export function renderStintLapCards(stints, { formatLap, formatDuration, escapeHtml, labels, locale, openIds = new Set(), allStints = stints } = {}) {
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>`;
const dayBests = buildDayBests(allStints);
return `<div class="stint-laps">${items.map((stint) => {
const rows = buildStintLapRows(stint.laps);
const dayBestMs = dayBests.get(dayKey(stint.startedAt)) || 0;
const rows = buildStintLapRows(stint.laps, { dayBestMs });
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" : ""}">
<li class="stint-lap${row.dayBest ? " is-day-best" : 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>
<span class="stint-lap-delta">${row.excluded ? escapeHtml(labels.excluded) : row.best || row.dayBest ? "★" : `+${(row.deltaMs / 1000).toFixed(3)}`}</span>
</li>`).join("");
const id = String(stint.id ?? stint.startedAt ?? stint.number);
return `
@@ -50,9 +56,10 @@ export function renderStintLapCards(stints, { formatLap, formatDuration, escapeH
<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 class="${dayBestMs && Number(stint.bestLapMs) === dayBestMs ? "is-day-best" : "is-best"}"><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>
<span><small>${escapeHtml(labels.duration)}</small>${escapeHtml(formatDuration(stint.durationMs))}</span>
<span><small>${escapeHtml(labels.consistency)}</small>${stint.consistencyPct == null ? "-" : `${Number(stint.consistencyPct).toFixed(1)}%`}</span></span>
</summary>
<ol class="stint-lap-list" aria-label="${escapeHtml(labels.lap)}">${lapItems}</ol>
</details>`;
@@ -62,3 +69,20 @@ export function renderStintLapCards(stints, { formatLap, formatDuration, escapeH
export function openStintLapCardIds(container) {
return new Set([...(container?.querySelectorAll?.(".stint-laps-card[open]") || [])].map((card) => card.dataset.stintId));
}
function dayKey(timestamp) {
const date = new Date(Number(timestamp || 0));
return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;
}
function buildDayBests(stints) {
const bests = new Map();
(Array.isArray(stints) ? stints : []).forEach((stint) => {
const key = dayKey(stint?.startedAt);
(stint?.laps || []).forEach((lap) => {
const lapMs = Math.round(Number(lap?.lapMs || 0));
if (lapMs > 0 && !lap.excluded && (!bests.has(key) || lapMs < bests.get(key))) bests.set(key, lapMs);
});
});
return bests;
}
+8 -3
View File
@@ -4964,13 +4964,14 @@ tr:has(> td > .medal-3) { background: linear-gradient(90deg, rgba(205, 127, 60,
/* 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 { position: relative; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 18px; padding: 10px 36px 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 > summary::after { content: "▾"; position: absolute; top: 12px; right: 14px; 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 { display: grid; grid-template-columns: repeat(5, auto); gap: 6px 18px; }
@media (max-width: 520px) { .stint-laps-stats { width: 100%; grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.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; }
@@ -4982,6 +4983,10 @@ tr:has(> td > .medal-3) { background: linear-gradient(90deg, rgba(205, 127, 60,
.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-day-best .stint-lap-time, .stint-lap.is-day-best .stint-lap-delta, .stint-laps-stats .is-day-best { color: #b67cff; }
.stint-lap.is-day-best .stint-lap-bar i { background: #a259ff; }
.stint-laps-stats .is-best { color: var(--green, var(--ok)); }
.stint-laps-stats .is-best small, .stint-laps-stats .is-day-best small { color: var(--muted); }
.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; }
+2 -2
View File
@@ -424,8 +424,8 @@ export function renderTrainingView(deps) {
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") },
formatLap, formatDuration: formatRaceClock, escapeHtml, openIds: openStintLapCardIds(document), allStints: stintAnalysis.rows,
labels: { stint: t("training.stint"), laps: t("training.laps"), best: t("training.best_lap"), average: t("training.stint_average"), duration: t("training.stint_total_time"), consistency: t("training.consistency"), 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 = `
+19
View File
@@ -39,4 +39,23 @@ export async function runProfileClassSmoke({ evaluate, savedState, waitFor, base
assert.match(await evaluate(`location.search`), /class=pc_4wd/);
assert.equal(await evaluate(`Boolean(document.querySelector("[data-switch-class]"))`), false);
console.log("PASS on another class, the profile says the latest laps are in the 4WD and switches in one tap");
// Pro: a clean practice view with today's numbers and the stint cards only,
// remembered on the phone and kept in the link.
const visible = (selector) => evaluate(`(() => { const el = document.querySelector(${JSON.stringify(selector)}); return Boolean(el && el.offsetParent); })()`);
assert.equal(await visible(".profile-pro"), false, "Standard by default");
await evaluate(`document.querySelector('[data-profile-mode="pro"]').click()`);
await waitFor(() => visible(".profile-pro"), "Pro view shown");
assert.match(await evaluate(`location.search`), /mode=pro/);
assert.equal(await visible(".profile-performance"), false, "stint statistics, goals and exercises are hidden");
assert.equal(await visible(".profile-motivation-grid"), false);
assert.equal(await evaluate(`document.querySelectorAll(".profile-pro .stint-laps-card").length`), 1, "today's stint");
await evaluate(`document.querySelector(".profile-pro .stint-laps-card > summary").click()`);
assert.equal(await evaluate(`document.querySelectorAll(".profile-pro .stint-lap").length`), 2, "both laps listed");
await send("Page.navigate", { url: `${base}/public-training/${token}?lang=en` });
await waitFor(() => visible(".profile-pro"), "the phone remembers Pro");
await evaluate(`document.querySelector('[data-profile-mode="standard"]').click()`);
await waitFor(async () => !(await visible(".profile-pro")) && (await visible(".profile-motivation-grid")), "back to Standard");
assert.doesNotMatch(await evaluate(`location.search`), /mode=/);
console.log("PASS the mobile profile has a Standard / Pro switch: Pro shows only today's numbers and the fold-out stints, and is remembered");
}
+2 -2
View File
@@ -42,12 +42,12 @@ 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.
// The stint card folds out to every lap; the day's fastest is purple.
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");
assert.equal(await evaluate(`document.querySelectorAll(".stint-laps-card .stint-lap.is-day-best").length`), 2, "both 19.500 laps are the day's fastest (purple)");
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")); })()`);
+14
View File
@@ -34,3 +34,17 @@ test("buildTrainingStintAnalysis rows carry their laps for the fold-out list", (
assert.deepEqual(rows[0].laps.map((lap) => lap.lapMs), [10_000, 13_000, 13_500]);
assert.equal(rows[0].averageLapMs, 12_167);
});
test("the day's fastest lap is purple, over every stint that day", () => {
const day = new Date(2026, 10, 9, 18).getTime();
const stints = [
{ id: "a", number: 1, startedAt: day, lapCount: 2, bestLapMs: 13300, laps: [{ lapMs: 13500 }, { lapMs: 13300 }] },
{ id: "b", number: 2, startedAt: day + 3600000, lapCount: 2, bestLapMs: 13100, laps: [{ lapMs: 13100 }, { lapMs: 13400 }] },
];
const html = renderStintLapCards(stints.slice(0, 1), { formatLap: fmt, formatDuration: fmt, escapeHtml, labels, allStints: stints });
assert.doesNotMatch(html, /is-day-best/, "the shown stint's best is not the day's best");
assert.match(html, /class="stint-lap is-best"/);
const both = renderStintLapCards(stints, { formatLap: fmt, formatDuration: fmt, escapeHtml, labels });
assert.equal((both.match(/class="stint-lap is-day-best"/g) || []).length, 1);
assert.equal(buildStintLapRows([{ lapMs: 13100 }], { dayBestMs: 13100 })[0].dayBest, true);
});