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

+22
View File
@@ -66,6 +66,28 @@ export async function runRaceDayQuickSmoke({ evaluate, navigate, savedState, wai
await waitFor(async () => Boolean(await evaluate(`document.getElementById("raceDayStart")`)), "Start is offered again");
console.log("PASS a finished heat can be picked and reset: clock to zero, laps cleared, Start again");
// The race controller follows the heat on Race Day: order, laps, last/best lap, estimate.
const liveAt = Date.now() - 60000;
const competitor = (key, name, laps, lastLapMs, bestLapMs, elapsedMs) => ({ key, driverName: name, displayName: name, laps, lastLapMs, bestLapMs, startTimestamp: liveAt, lastTimestamp: liveAt + elapsedMs });
await patchState({
sessions: [...(await savedState()).sessions.filter((session) => session.status !== "running"), { id: "rq_live", eventId: "rq_event", name: "RQ Heat 3", type: "heat", status: "running", durationMin: 5, startMode: "mass", startedAt: liveAt }],
resultsBySession: { ...(await savedState()).resultsBySession, rq_live: { passings: [], adjustments: [], competitors: {
slow: competitor("slow", "Slow Sam", 2, 26000, 25000, 52000),
fast: competitor("fast", "Fast Fia", 3, 19000, 18500, 57000),
} } },
activeSessionId: "rq_live",
});
await navigate("race_day", "raceDayLive");
const liveRows = await evaluate(`JSON.stringify([...document.querySelectorAll("#raceDayLive tbody tr")].map((row) => [...row.cells].map((cell) => cell.textContent.trim())))`);
const [first, second] = JSON.parse(liveRows);
assert.deepEqual([first[0], first[1], first[2], second[1], second[2]], ["1", "Fast Fia", "3", "Slow Sam", "2"], "the running order with laps");
assert.match(first[3], /19\.0/, "last lap");
assert.match(first[4], /18\.5/, "best lap");
assert.match(first[7], /^16 · /, "estimated laps when the time is up");
assert.equal(await evaluate(`document.querySelector("#raceDayLive .is-fastest")?.closest("tr").cells[1].textContent.includes("Fast Fia")`), true, "the heat's fastest lap is marked");
await patchState({ sessions: (await savedState()).sessions.map((session) => (session.id === "rq_live" ? { ...session, status: "finished", endedAt: Date.now() } : session)) });
console.log("PASS Race Day shows the live race: order, laps, last and best lap, gaps and estimated finish");
await navigate("timing", "activeSessionSelect");
assert.equal(await evaluate(`Boolean(document.getElementById("startSession") || document.getElementById("resetSession") || document.getElementById("stopSession"))`), false, "no run controls on Timing");
await evaluate(`document.getElementById("timingOpenRaceDay").click()`);
+14
View File
@@ -0,0 +1,14 @@
import test from "node:test";
import assert from "node:assert/strict";
import { estimateFinish } from "../src/timing_logic.js";
test("estimated finish: laps and time when a 5-minute heat is up, at the car's recent pace", () => {
// 10 laps in 3:00, last two laps 18 s: 120 s left = 7 more laps (the 7th crosses after 5:00).
assert.deepEqual(estimateFinish({ laps: 10, totalElapsedMs: 180000, lastLapMs: 18000, previousLapMs: 18000 }, 300000), { laps: 17, timeMs: 306000, paceMs: 18000 });
// No recent laps known: the average lap.
assert.equal(estimateFinish({ laps: 4, totalElapsedMs: 80000 }, 300000).paceMs, 20000);
// Over time: the laps it has are its result.
assert.deepEqual(estimateFinish({ laps: 16, totalElapsedMs: 301000, lastLapMs: 19000 }, 300000), { laps: 16, timeMs: 301000, paceMs: 19000 });
assert.equal(estimateFinish({ laps: 0, totalElapsedMs: 0 }, 300000), null, "no lap yet");
assert.equal(estimateFinish({ laps: 5, totalElapsedMs: 90000 }, null), null, "untimed session");
});
+1
View File
@@ -1,4 +1,5 @@
import "./auth.test.js";
import "./race_day_live.test.js";
import "./series_next_step.test.js";
import "./race_day_sessions.test.js";
import "./overlay_leaderboard.test.js";