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:
1 parent
73e1c0ccf3
commit
0caf50254a
13 files changed
+204
-28
No files matched your search
+4
-2
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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; }
|
||||
|
||||
@@ -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 = `
|
||||
|
||||
Reference in new issue
Block a user