fix(race-day): reset a heat to ready with its clock at zero, keep recent races listed (1.45.2)

This commit is contained in:
larssand committed 2026-11-01 10:49:17 +01:00
1 parent 7376595001
commit ab1c26a89b
7 files changed
+62 -14

No files matched your search

+7
View File
@@ -8,6 +8,13 @@ The application version is maintained in `package.json` and displayed in the adm
No changes recorded yet. No changes recorded yet.
## 1.45.2 - 2026-11-01
### Fixed
- **Restarting a heat: "Reset data" now resets the clock too.** It cleared the laps but left the heat finished with its old clock, so it couldn't be started again. A reset heat (and a race's seeding practice) is back to "ready" - clock at zero, Start offered again. The cleared result is also written straight to the server, so a reset right after the last lap is no longer undone. Open Practice keeps "Reset – new practice day", which clears the laps and keeps running.
- **Race Day: a finished heat could not be picked again.** The session list hid finished heats of a race dated another day - e.g. after midnight - and of races without a date. A race now stays listed when anything in it ran in the last 12 hours, and undated races are always listed in full.
## 1.45.1 - 2026-10-31 ## 1.45.1 - 2026-10-31
### Changed ### Changed
+2 -2
View File
@@ -1,12 +1,12 @@
{ {
"name": "rc-racecore", "name": "rc-racecore",
"version": "1.45.1", "version": "1.45.2",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "rc-racecore", "name": "rc-racecore",
"version": "1.45.1", "version": "1.45.2",
"hasInstallScript": true, "hasInstallScript": true,
"dependencies": { "dependencies": {
"better-sqlite3": "^12.11.1", "better-sqlite3": "^12.11.1",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "rc-racecore", "name": "rc-racecore",
"version": "1.45.1", "version": "1.45.2",
"private": true, "private": true,
"description": "RC RaceCore live timing and race control with AMMC ingest and SQLite persistence", "description": "RC RaceCore live timing and race control with AMMC ingest and SQLite persistence",
"engines": { "engines": {
+14 -4
View File
@@ -357,11 +357,21 @@ function resetSessionData(session) {
session.resultsResetAt = Date.now(); session.resultsResetAt = Date.now();
delete state.resultsBySession[session.id]; delete state.resultsBySession[session.id];
session.followUpStartedAt = null; session.followUpStartedAt = null;
// A heat (anything but an Open/Free Practice that runs all evening) goes back to "ready":
// the clock is back at zero and it can be started again.
const rerunHeat = !isPracticeSessionType(session.type) && session.status !== "running";
if (rerunHeat) {
// An empty result, also written straight to the server: a plain delete was put back by
// the server's live-results protection when the reset came right after the last lap.
ensureSessionResult(session.id);
Object.assign(session, { status: "ready", startedAt: null, endedAt: null, finishedByTimer: false, pausedAt: null, totalPausedMs: 0, followUpPausedMs: 0, audioAnnouncements: [] });
}
lastFinishAnnouncementSessionId = null; lastFinishAnnouncementSessionId = null;
delete lastOverlayLeaderKeyBySession[session.id]; delete lastOverlayLeaderKeyBySession[session.id];
delete lastOverlayTop3BySession[session.id]; delete lastOverlayTop3BySession[session.id];
overlayEvents = []; overlayEvents = [];
saveState(); saveState();
if (rerunHeat) void persistSessionResultToBackend(session.id);
renderView(); renderView();
return true; return true;
} }
@@ -953,8 +963,8 @@ const TRANSLATIONS = {
"race_day.show_all_sessions": "Visa alla sessioner", "race_day.show_all_sessions": "Visa alla sessioner",
"race_day.go_next": "Nästa: {name}", "race_day.go_next": "Nästa: {name}",
"race_day.hidden_sessions": "({count} från andra dagar dolda)", "race_day.hidden_sessions": "({count} från andra dagar dolda)",
"race_day.reset_session_hint": "Nollställer sessionens varv och resultat, t.ex. vid omstart. Pausa först om heatet körs.", "race_day.reset_session_hint": "Nollställer sessionens varv, resultat och klocka så att den kan köras om. Pausa först om heatet körs.",
"race_day.reset_session_confirm": "Nollställ alla varv och resultat i \"{name}\"?\n\nDet går inte att ångra.", "race_day.reset_session_confirm": "Nollställ alla varv och resultat i \"{name}\" och ställ klockan på noll så att den kan startas om?\n\nDet går inte att ångra.",
"race_day.new_practice_day": "Nollställ – ny träningsdag", "race_day.new_practice_day": "Nollställ – ny träningsdag",
"race_day.new_practice_day_hint": "Nollställer dagens varv i tidtagningen. Alla varv finns kvar i träningsstatistiken.", "race_day.new_practice_day_hint": "Nollställer dagens varv i tidtagningen. Alla varv finns kvar i träningsstatistiken.",
"race_day.new_practice_day_confirm": "Starta en ny träningsdag i \"{name}\"?\n\nDagens varv nollställs i tidtagningen (topplistan börjar om). Alla varv finns kvar i träningsstatistiken.", "race_day.new_practice_day_confirm": "Starta en ny träningsdag i \"{name}\"?\n\nDagens varv nollställs i tidtagningen (topplistan börjar om). Alla varv finns kvar i träningsstatistiken.",
@@ -2822,8 +2832,8 @@ const TRANSLATIONS = {
"race_day.show_all_sessions": "Show all sessions", "race_day.show_all_sessions": "Show all sessions",
"race_day.go_next": "Next: {name}", "race_day.go_next": "Next: {name}",
"race_day.hidden_sessions": "({count} from other days hidden)", "race_day.hidden_sessions": "({count} from other days hidden)",
"race_day.reset_session_hint": "Clears the session's laps and results, e.g. for a restart. Pause first if the heat is running.", "race_day.reset_session_hint": "Clears the session's laps, results and clock so it can be run again. Pause first if the heat is running.",
"race_day.reset_session_confirm": "Clear every lap and result in \"{name}\"?\n\nThis cannot be undone.", "race_day.reset_session_confirm": "Clear every lap and result in \"{name}\" and set its clock back to zero so it can be started again?\n\nThis cannot be undone.",
"race_day.new_practice_day": "Reset – new practice day", "race_day.new_practice_day": "Reset – new practice day",
"race_day.new_practice_day_hint": "Clears today's laps in timing. Every lap stays in the training statistics.", "race_day.new_practice_day_hint": "Clears today's laps in timing. Every lap stays in the training statistics.",
"race_day.new_practice_day_confirm": "Start a new practice day in \"{name}\"?\n\nToday's laps are cleared in timing (the leaderboard starts over). Every lap stays in the training statistics.", "race_day.new_practice_day_confirm": "Start a new practice day in \"{name}\"?\n\nToday's laps are cleared in timing (the leaderboard starts over). Every lap stays in the training statistics.",
+11 -5
View File
@@ -70,14 +70,17 @@ const localDateKey = (date = new Date()) => `${date.getFullYear()}-${String(date
// The session picker lists today's races by default (plus whatever is live or selected), // The session picker lists today's races by default (plus whatever is live or selected),
// grouped per race in the order they were set up. Old races, practices and other series' // grouped per race in the order they were set up. Old races, practices and other series'
// rounds stay out of the way until "Show all" is ticked. Undated races show unrun sessions. // rounds stay out of the way until "Show all" is ticked.
export function buildRaceDaySessionGroups({ sessions, events, selectedId = "", showAll = false, today = localDateKey() }) { export function buildRaceDaySessionGroups({ sessions, events, selectedId = "", showAll = false, today = localDateKey(), now = Date.now() }) {
const eventById = new Map((events || []).map((event) => [event.id, event])); const eventById = new Map((events || []).map((event) => [event.id, event]));
const isLive = (session) => ["running", "paused"].includes(session.status); const isLive = (session) => ["running", "paused"].includes(session.status);
// A race is "today's" by its date, or when something in it ran in the last 12 hours (a
// race day going past midnight, a date set wrong). Undated races are always listed.
const recentEventIds = new Set((sessions || []).filter((session) => Number(session.startedAt) > now - 12 * 3600 * 1000).map((session) => session.eventId));
const visible = (session) => { const visible = (session) => {
if (showAll || isLive(session) || session.id === selectedId) return true; if (showAll || isLive(session) || session.id === selectedId || recentEventIds.has(session.eventId)) return true;
const date = eventById.get(session.eventId)?.date; const date = eventById.get(session.eventId)?.date;
return date ? date === today : session.status === "ready"; return !date || date === today;
}; };
const groups = new Map(); const groups = new Map();
let hidden = 0; let hidden = 0;
@@ -240,6 +243,9 @@ export function renderRaceDayView(deps) {
const sessionChoices = buildRaceDaySessionGroups({ sessions: state.sessions, events: state.events, selectedId: session?.id, showAll: showAllSessions }); const sessionChoices = buildRaceDaySessionGroups({ sessions: state.sessions, events: state.events, selectedId: session?.id, showAll: showAllSessions });
const isPracticeSession = Boolean(session && (isPracticeSessionType(session.type) || session.type === "practice")); const isPracticeSession = Boolean(session && (isPracticeSessionType(session.type) || session.type === "practice"));
const isLiveSession = ["running", "paused"].includes(session?.status); const isLiveSession = ["running", "paused"].includes(session?.status);
// Open/Free Practice runs all evening and is reset per day; a race's practice (seeding) is
// reset like a heat.
const isOpenPractice = Boolean(session && isPracticeSessionType(session.type));
// Layouts are a practice thing: never offered while a race session is in focus. // Layouts are a practice thing: never offered while a race session is in focus.
const layoutAllowed = !session || isPracticeSessionType(session.type); const layoutAllowed = !session || isPracticeSessionType(session.type);
dom.view.innerHTML = ` dom.view.innerHTML = `
@@ -289,7 +295,7 @@ export function renderRaceDayView(deps) {
${session?.status === "running" ? `<button id="raceDayPause" class="btn btn-danger" type="button">⏸ ${t(isPracticeSession ? "race_day.pause_practice" : "audio.race_pause")}</button>` : ""} ${session?.status === "running" ? `<button id="raceDayPause" class="btn btn-danger" type="button">⏸ ${t(isPracticeSession ? "race_day.pause_practice" : "audio.race_pause")}</button>` : ""}
${session?.status === "paused" ? `<button id="raceDayResume" class="btn btn-go" type="button">${t(isPracticeSession ? "race_day.resume_practice" : "audio.race_resume")}</button>` : ""} ${session?.status === "paused" ? `<button id="raceDayResume" class="btn btn-go" type="button">${t(isPracticeSession ? "race_day.resume_practice" : "audio.race_resume")}</button>` : ""}
${isLiveSession ? `<button id="raceDayFinish" class="btn btn-checkered" type="button">🏁 ${t(isPracticeSession ? "race_day.finish_practice" : "race_day.finish")}</button>` : ""} ${isLiveSession ? `<button id="raceDayFinish" class="btn btn-checkered" type="button">🏁 ${t(isPracticeSession ? "race_day.finish_practice" : "race_day.finish")}</button>` : ""}
${isPracticeSession ? `<button id="raceDayNewPracticeDay" class="btn" type="button" title="${escapeHtml(t("race_day.new_practice_day_hint"))}">${t("race_day.new_practice_day")}</button>` ${isOpenPractice ? `<button id="raceDayNewPracticeDay" class="btn" type="button" title="${escapeHtml(t("race_day.new_practice_day_hint"))}">${t("race_day.new_practice_day")}</button>`
: session && session.status !== "running" ? `<button id="raceDayResetSession" class="btn" type="button" title="${escapeHtml(t("race_day.reset_session_hint"))}">${t("timing.reset")}</button>` : ""}`} : session && session.status !== "running" ? `<button id="raceDayResetSession" class="btn" type="button" title="${escapeHtml(t("race_day.reset_session_hint"))}">${t("timing.reset")}</button>` : ""}`}
</div> </div>
${isPracticeSession ? "" : `<div id="raceDayStartLights" class="race-start-lights" data-state="${escapeHtml(getStartLightState())}"> ${isPracticeSession ? "" : `<div id="raceDayStartLights" class="race-start-lights" data-state="${escapeHtml(getStartLightState())}">
+18
View File
@@ -47,6 +47,24 @@ export async function runRaceDayQuickSmoke({ evaluate, navigate, savedState, wai
await waitFor(async () => Boolean(await evaluate(`document.getElementById("raceDayResetSession")`)), "Reset data is on Race Day for a heat that is not running"); await waitFor(async () => Boolean(await evaluate(`document.getElementById("raceDayResetSession")`)), "Reset data is on Race Day for a heat that is not running");
console.log("PASS Race Day's session picker switches the selected session"); console.log("PASS Race Day's session picker switches the selected session");
// A finished heat can be picked again and reset to run again: clock back to zero, no laps.
const ranAt = Date.now() - 600000;
await patchState({
sessions: [...(await savedState()).sessions, { id: "rq_done", eventId: "rq_event", name: "RQ Heat 2", type: "qualification", status: "finished", durationMin: 5, startedAt: ranAt, endedAt: ranAt + 300000, finishedByTimer: true }],
resultsBySession: { ...(await savedState()).resultsBySession, rq_done: { passings: [{ id: "p1", timestamp: ranAt + 20000, lapMs: 20000 }], competitors: {}, adjustments: [] } },
});
await navigate("race_day", "raceDaySessionSelect");
assert.ok(await evaluate(`[...document.getElementById("raceDaySessionSelect").options].some((option) => option.value === "rq_done")`), "the finished heat is in the list");
await evaluate(`(() => { const select = document.getElementById("raceDaySessionSelect"); select.value = "rq_done"; select.dispatchEvent(new Event("change")); })()`);
await waitFor(async () => Boolean(await evaluate(`document.getElementById("raceDayResetSession")`)), "Reset data for the finished heat");
await evaluate(`document.getElementById("raceDayResetSession").click()`);
await waitFor(async () => (await savedState()).sessions.find((session) => session.id === "rq_done")?.status === "ready", "the heat is ready to run again");
const reset = (await savedState()).sessions.find((session) => session.id === "rq_done");
assert.deepEqual([reset.startedAt || null, reset.endedAt || null, reset.finishedByTimer], [null, null, false], "the clock is back at zero");
assert.equal((await savedState()).resultsBySession.rq_done?.passings?.length || 0, 0, "its laps are cleared");
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");
await navigate("timing", "activeSessionSelect"); await navigate("timing", "activeSessionSelect");
assert.equal(await evaluate(`Boolean(document.getElementById("startSession") || document.getElementById("resetSession") || document.getElementById("stopSession"))`), false, "no run controls on Timing"); 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()`); await evaluate(`document.getElementById("timingOpenRaceDay").click()`);
+9 -2
View File
@@ -25,9 +25,16 @@ test("Race Day picker: today's races, live and selected sessions, grouped per ra
["old", ["old_practice"]], ["old", ["old_practice"]],
["next", ["n_practice"]], ["next", ["n_practice"]],
["today", ["t_practice", "t_q1"]], ["today", ["t_practice", "t_q1"]],
["undated", ["u_ready"]], ["undated", ["u_ready", "u_done"]],
]); ]);
assert.equal(result.hidden, 2); assert.equal(result.hidden, 1);
});
test("Race Day picker: a race run in the last 12 hours stays listed after midnight", () => {
const now = Date.parse("2026-11-09T00:30:00");
const ran = sessions.map((session) => session.id === "t_practice" ? { ...session, startedAt: now - 3600 * 1000 } : session);
const result = buildRaceDaySessionGroups({ sessions: ran, events, today: "2026-11-09", now });
assert.deepEqual(ids(result).find(([id]) => id === "today"), ["today", ["t_practice", "t_q1"]], "yesterday's race, finished heats included");
}); });
test("Race Day picker: show all lists every session", () => { test("Race Day picker: show all lists every session", () => {