feat(race-day): live race for the race controller with order, laps, gaps and estimated finish (1.47.0)

This commit is contained in:
larssand committed 2026-11-01 16:38:08 +01:00
1 parent c4163441fc
commit 54487a18a6
12 files changed
+169 -7

No files matched your search

+54 -1
View File
@@ -1,6 +1,7 @@
import { isPracticeSessionType } from "./track_layouts_logic.js";
import { renderTrackLayoutBar, bindTrackLayoutBar } from "./track_layout_bar.js";
import { PROLOGUE_OPTIONS_SEC, formatPrologueOption } from "./prologue_logic.js";
import { estimateFinish } from "./timing_logic.js";
export function getRaceDayCheckAction(item, session) {
if (item.level === "ok") return null;
if (["backend", "decoder", "split_decoder", "pit_decoders", "audio"].includes(item.id)) {
@@ -167,6 +168,54 @@ function bindWarmupPanel(panel, deps, session) {
});
}
// --- Live race for the race controller ------------------------------------------------
// The running order with laps, last and best lap, gaps and where each car will end, right on
// Race Day. Repainted once a second (refreshRaceDayLive) and on every passing (full render).
let lastLiveDeps = null;
const showsLivePanel = (session) => Boolean(session && !isPracticeSessionType(session.type)
&& (["running", "paused"].includes(session.status) || (["finished", "stopped"].includes(session.status) && session.startedAt)));
function renderLivePanelInner({ t, escapeHtml, formatLap, formatRaceClock, buildLeaderboard, getSessionTargetMs }, session) {
const rows = buildLeaderboard(session);
const seedRanked = ["practice", "qualification"].includes(session.type) && Number(session.seedBestLapCount || 0) > 0;
const targetMs = seedRanked ? null : getSessionTargetMs(session);
const fastestMs = Math.min(...rows.map((row) => Number(row.bestLapMs) || Infinity));
const done = ["finished", "stopped"].includes(session.status);
const lap = (ms) => (ms > 0 ? formatLap(ms) : "-");
const body = rows.map((row, index) => {
const estimate = !done && targetMs ? estimateFinish(row, targetMs) : null;
const bestIsFastest = row.bestLapMs > 0 && row.bestLapMs === fastestMs;
const lastIsBest = row.lastLapMs > 0 && row.lastLapMs === row.bestLapMs;
const flag = done || row.personalTimeUp ? " 🏁" : "";
const progress = Math.round(Math.min(1, row.predictedProgress || 0) * 100);
return `<tr class="${row.invalidPending ? "is-invalid" : ""}">
<td class="live-pos">${index + 1}</td>
<td class="live-driver"><strong>${escapeHtml(row.displayName || row.driverName || row.transponder || "-")}${flag}</strong>${row.invalidPending ? ` <span class="live-warn" title="${escapeHtml(row.invalidLabel || "")}">⚠</span>` : ""}
${done ? "" : `<span class="live-lap-bar" aria-hidden="true"><span class="is-${escapeHtml(row.predictionTone || "good")}" style="width:${progress}%"></span></span>`}</td>
<td class="live-num">${row.laps}</td>
<td class="live-num ${lastIsBest ? "is-pb" : ""}">${lap(row.lastLapMs)}</td>
<td class="live-num ${bestIsFastest ? "is-fastest" : ""}">${lap(row.bestLapMs)}</td>
<td class="live-num">${escapeHtml(index === 0 ? "-" : row.gapAhead || "-")}</td>
<td class="live-num">${escapeHtml(index === 0 ? "-" : row.leaderGap || "-")}</td>
<td class="live-num">${seedRanked ? escapeHtml(row.resultDisplay || "-") : done ? escapeHtml(`${row.laps} · ${formatRaceClock(row.totalElapsedMs)}`) : estimate ? escapeHtml(`${estimate.laps} · ${formatRaceClock(estimate.timeMs)}`) : "-"}</td>
</tr>`;
}).join("");
const lastColumn = seedRanked ? t("race_day.live_seed") : done ? t("race_day.live_result") : t("race_day.live_estimate");
return `<div class="panel-header"><div><h3>${escapeHtml(t(done ? "race_day.live_title_done" : "race_day.live_title", { name: session.name }))}</h3><p class="hint">${escapeHtml(t("race_day.live_hint"))}</p></div><span class="pill ${done ? "" : "pill-green"}">${rows.length}</span></div>
<div class="panel-body">${rows.length ? `<div class="table-wrap"><table class="race-day-live-table">
<thead><tr><th>${t("race_day.live_pos")}</th><th>${t("race_day.live_driver")}</th><th>${t("race_day.live_laps")}</th><th>${t("race_day.live_last")}</th><th>${t("race_day.live_best")}</th><th>${t("race_day.live_gap")}</th><th>${t("race_day.live_leader")}</th><th>${lastColumn}</th></tr></thead>
<tbody>${body}</tbody></table></div>` : `<p class="hint">${t("race_day.live_empty")}</p>`}</div>`;
}
// Called once a second by the clock tick in app.js; touches only the live panel.
export function refreshRaceDayLive() {
const panel = document.getElementById("raceDayLive");
if (!panel || !lastLiveDeps) return;
const session = lastLiveDeps.getSession();
if (!showsLivePanel(session)) return;
panel.innerHTML = renderLivePanelInner(lastLiveDeps, session);
}
// Called by the prologue timer in app.js (5x a second) - touches only the clock text.
export function refreshRaceDayPrologueClock(remainingMs) {
document.querySelectorAll("[data-prologue-clock]").forEach((node) => { node.textContent = formatMmSs(remainingMs); });
@@ -210,6 +259,7 @@ export function renderRaceDayView(deps) {
startRacePrologue, holdRacePrologue, resumeRacePrologue, setRacePrologueRemaining, cancelRacePrologue, goRacePrologue,
isStartPending, renderSuspectLapsPanel = () => "", setCompetitorLapStatus = () => false, getLiveSession = () => null,
resetSessionData = () => false, startPracticeNow = async () => false, findOpenPracticeToContinue = () => null,
buildLeaderboard = () => [], getSessionTargetMs = () => null, formatRaceClock = (ms) => String(ms),
} = deps;
const queue = buildRaceDayQueue(state);
const session = queue.current;
@@ -266,6 +316,7 @@ export function renderRaceDayView(deps) {
? `<div class="race-day-clock is-prologue"><strong data-prologue-clock>${formatMmSs(warmupForChecks.remainingMs)}</strong><span>${t("prologue.to_start")}</span></div>`
: `<div class="race-day-clock"><strong data-race-day-clock>${clock}</strong><span>${session ? escapeHtml(getStatusLabel(session.status)) : t("race_day.none")}</span></div>`}
</section>
${showsLivePanel(session) ? `<section class="panel race-day-live" id="raceDayLive"></section>` : ""}
<div class="race-day-layout">
<div class="race-day-main">
@@ -313,7 +364,7 @@ export function renderRaceDayView(deps) {
${showsWarmupPanel(session) ? `<section class="panel mt-16" id="raceDayWarmup"></section>` : ""}
${session ? renderSuspectLapsPanel(session) : ""}
<section class="panel">
<section class="panel" ${isLiveSession ? "hidden" : ""}>
<div class="panel-header"><h3>${t("race_day.start_list")}</h3><span class="pill">${grid.length}</span></div>
<div class="panel-body race-day-grid-list">
${grid.length ? grid.map((entry) => `<article><span>${entry.slot}</span><strong>${escapeHtml(entry.name)}</strong><small>${escapeHtml(entry.meta || "-")}</small></article>`).join("") : `<p class="hint">${t("race_day.no_start_list")}</p>`}
@@ -387,6 +438,8 @@ export function renderRaceDayView(deps) {
bindTrackLayoutBar(dom.view, { state, t, addTrackLayout, renderView });
lastWarmupDeps = { t, escapeHtml, renderView, getRaceDayWarmupCheck, setDriverTransponder, getSession: () => buildRaceDayQueue(state).current };
paintWarmupPanel();
lastLiveDeps = { t, escapeHtml, formatLap, formatRaceClock, buildLeaderboard, getSessionTargetMs, getSession: () => buildRaceDayQueue(state).current };
refreshRaceDayLive();
document.getElementById("raceDayStart")?.addEventListener("click", async () => {
if (!session || !preflight.ready) return;
if (!isSelected) selectSession(session.id, { render: false });