From b2e08db3d8946a594d73b618ed6abe9f80853030 Mon Sep 17 00:00:00 2001 From: larssand Date: Sun, 1 Nov 2026 22:25:43 +0100 Subject: [PATCH] feat(race-day): call the next heat - asked by hand, automatic with the autopilot (1.51.0) --- CHANGELOG.md | 10 ++++ README.md | 5 +- README.sv.md | 5 +- ROADMAP.md | 2 +- package-lock.json | 4 +- package.json | 2 +- rc-race-sound-pack/sound_manifest.json | 2 + src/app.js | 74 +++++++++++++++++++++++--- src/day_schedule_logic.js | 14 ++++- src/day_schedule_view.js | 41 +++++++++++--- src/race_audio.js | 1 + src/race_day_view.js | 4 +- src/styles.css | 8 ++- tests/browser_day_schedule.js | 23 ++++++-- tests/day_schedule.test.js | 14 +++++ 15 files changed, 178 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 27c7de6..4252188 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,16 @@ The application version is maintained in `package.json` and displayed in the adm No changes recorded yet. +## 1.51.0 - 2026-11-01 + +### Added + +- Calling a heat: when the next heat is 10 minutes away (set per day), Race Day asks the race controller to call it. Call now reads the heat and its drivers over the speakers and highlights it as Called on the drivers' board; Later asks again in 2 minutes. With the autopilot on, heats are called on their own. + +### Changed + +- The drivers' board highlights a heat once it has been called, instead of at a fixed 10 minutes before. + ## 1.50.0 - 2026-11-01 ### Added diff --git a/README.md b/README.md index 14c5b51..6c55d3e 100644 --- a/README.md +++ b/README.md @@ -109,8 +109,9 @@ The menu follows how a race day works: **Start** (Dashboard, Race Day), **Create - The **heat queue** shows the current, next and after-next heat in running order: practice, qualifying round by round (Q1 H1, Q1 H2, Q2 H1 …), then finals from the lowest (C, B, A). When a heat is done, **▶ Next** selects the next one in one click. The session lists in Race Setup and on Race Day follow the same order, so a heat deleted and made again lands in its right place; **▲▼** on a session in Race Setup moves it earlier or later. - **Today's schedule** (at the bottom) puts every class raced that day in one running order with times: practice, then each qualifying round with the classes taking turns, then the finals. Set the first start and the break between heats; **▲▼** change the order. A heat that starts late, runs long or is paused moves the rest of the day. - **🖨 Print running order** gives times, classes, heats and drivers for the board in the pits. - - **📺 Drivers' board** (`/public-overlay/schedule`, also under Overlay) shows what is on track, the next three heats with their drivers and a "get ready" heads-up 10 minutes before, then the rest of the day. It works on a phone or a TV in the pits. - - **▶ Run the day automatically** starts each heat's count-down on its own when the schedule says so, and waits (saying why) while a heat runs, the decoder is offline or a heat is not ready. It runs only in the browser where it was turned on. **⏸ Pause the day** pauses the heat on track (or holds the count-down) and the autopilot until **Resume the day**. + - **📺 Drivers' board** (`/public-overlay/schedule`, also under Overlay) shows what is on track, the next three heats with their drivers, then the rest of the day. A heat that has been called is highlighted "Called – get ready". It works on a phone or a TV in the pits. + - **Calling a heat:** when a heat is 10 minutes away (set under **Call**), Race Day asks the race controller: **📢 Call now** reads the heat and its drivers over the speakers and highlights it on the drivers' board; **Later** asks again in 2 minutes. With the autopilot on, heats are called on their own. + - **▶ Run the day automatically** starts each heat's count-down on its own when the schedule says so, and waits (saying why) while a heat runs, the decoder is offline or a heat is not ready. It runs only in the browser where it was turned on. **■ Stop autopilot** to run heats by hand; turning it on again carries on with the next heat not yet run. **⏸ Pause the day** pauses the heat on track (or holds the count-down) and the autopilot until **Resume the day**. - **Preflight** checks the decoder, participants, transponders (missing or duplicated), the lap window, the grid and audio. Blockers come first, each with a shortcut to the right setting. The min/max lap time can be edited right there. - **An automatic SQLite backup** is taken before every start. diff --git a/README.sv.md b/README.sv.md index 5c43cdb..f596f71 100644 --- a/README.sv.md +++ b/README.sv.md @@ -121,8 +121,9 @@ Gränssnittet finns på svenska och engelska. - **Live-race** för race controllern, direkt under klockan medan ett heat, kval eller final pågår: ordningen med varv, senaste varv, bästa varv, avstånd till bilen före och till ledaren, och beräknat slut (varv och tid när tiden går ut). Heatets snabbaste varv är lila, personbästa på senaste varvet grönt, och en stapel visar hur långt in på varvet varje bil är (röd = sen). Efter heatet visas resultatet. - **Dagens schema** (längst ned) lägger alla klasser som körs den dagen i en körordning med tider: träning, sedan varje kvalomgång där klasserna turas om, sist finalerna. Ange första start och paus mellan heaten; **▲▼** ändrar ordningen. Ett heat som startar sent, drar ut på tiden eller pausas flyttar resten av dagen. - **🖨 Skriv ut körordning** ger tider, klasser, heat och förare att sätta upp på tavlan i depån. - - **📺 Förarvy** (`/public-overlay/schedule`, finns även under Overlay) visar vad som körs, de tre nästa heaten med förare och en påminnelse "gör dig redo" 10 minuter innan, sedan resten av dagen. Den fungerar på mobilen eller en TV i depån. - - **▶ Kör dagen automatiskt** startar varje heats nedräkning själv när schemat säger det, och väntar (och säger varför) medan ett heat körs, decodern är frånkopplad eller ett heat inte är redo. Den körs bara i webbläsaren där den slogs på. **⏸ Pausa dagen** pausar heatet på banan (eller håller nedräkningen) och automatiken tills **Fortsätt dagen**. + - **📺 Förarvy** (`/public-overlay/schedule`, finns även under Overlay) visar vad som körs, de tre nästa heaten med förare, sedan resten av dagen. Ett uppropat heat markeras "Uppropad – gör dig redo". Den fungerar på mobilen eller en TV i depån. + - **Upprop:** när ett heat har 10 minuter kvar (ändras under **Upprop**) frågar Race Day race controllern: **📢 Ropa ut** läser upp heatet och förarna i högtalarna och markerar det i förarvyn; **Senare** frågar igen om 2 minuter. När automatiken är på ropas heaten upp av sig själva. + - **▶ Kör dagen automatiskt** startar varje heats nedräkning själv när schemat säger det, och väntar (och säger varför) medan ett heat körs, decodern är frånkopplad eller ett heat inte är redo. Den körs bara i webbläsaren där den slogs på. **■ Stoppa automatiken** för att köra för hand; slår du på den igen fortsätter den med nästa heat som inte är kört. **⏸ Pausa dagen** pausar heatet på banan (eller håller nedräkningen) och automatiken tills **Fortsätt dagen**. - **Heat-kön** visar aktuellt, nästa och därpå följande heat i körordning: träning, kval omgång för omgång (Q1 H1, Q1 H2, Q2 H1 …), sedan finaler från lägsta (C, B, A). När ett heat är klart väljer **▶ Nästa** nästa heat med ett klick. Sessionslistorna i Race Setup och på Race Day följer samma ordning, så ett heat som tagits bort och skapats om hamnar på rätt plats; **▲▼** på en session i Race Setup flyttar den tidigare eller senare. - **Förkontrollen** kontrollerar decoder, deltagare, transpondrar (saknade eller dubbletter), varvtidsgränser, grid och ljud. Blockerare visas först, var och en med en genväg till rätt inställning. Min/max-varvtid kan ändras direkt där. - **En automatisk SQLite-backup** tas före varje start. diff --git a/ROADMAP.md b/ROADMAP.md index aacb6bc..8f5d8e1 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -993,7 +993,7 @@ Asked for after the first ÖRC Winter round: a schedule for the whole day, one b - [x] Autopilot in the tab where it is turned on (sessionStorage): starts the next heat's count-down at planned start minus the count-down length; waits while anything runs, the decoder is offline or preflight fails. Pause the day pauses the heat on track or holds the count-down. - [x] Drivers' board at `/public-overlay/schedule` with the next three heats, drivers in grid order and a heads-up within 10 minutes. - [x] Race Setup's schedule follows the ▲▼ running order. -- [ ] Spoken heads-up ("Q2 H1 2WD starts in 10 minutes") - not asked for yet. +- [x] Calling a heat (1.51.0): the race controller is asked to call the next heat within `callMin` (Call now / Later), the autopilot calls on its own; `session.calledAt` highlights it on the drivers' board and the `heat_call` voice event reads heat and drivers. ## Documentation maintenance diff --git a/package-lock.json b/package-lock.json index f1a4f1f..42ab85a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "rc-racecore", - "version": "1.50.0", + "version": "1.51.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "rc-racecore", - "version": "1.50.0", + "version": "1.51.0", "hasInstallScript": true, "dependencies": { "better-sqlite3": "^12.11.1", diff --git a/package.json b/package.json index a50dc4e..ed46519 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rc-racecore", - "version": "1.50.0", + "version": "1.51.0", "private": true, "description": "RC RaceCore live timing and race control with AMMC ingest and SQLite persistence", "engines": { diff --git a/rc-race-sound-pack/sound_manifest.json b/rc-race-sound-pack/sound_manifest.json index 623ea64..241b94f 100644 --- a/rc-race-sound-pack/sound_manifest.json +++ b/rc-race-sound-pack/sound_manifest.json @@ -47,6 +47,7 @@ "race_1_minute": "Race starts in one minute.", "race_30_seconds": "Thirty seconds to start.", "race_10_seconds": "Ten seconds to start.", "drivers_ready": "Drivers, stand by.", "start_sequence": "Starting on the sound of the tone.", "false_start": "False start.", "restart_race": "Prepare to restart the race.", "staggered_release": "Car {tp}.", + "heat_call": "{heat} starts in {minutes} minutes. Drivers: {drivers}. Get ready.", "prologue_start": "{heat} starts in {time}. The track is open.", "prologue_minutes": "{minutes} minutes to the start.", "prologue_grid": "Thirty seconds to start. Cars to the grid.", @@ -77,6 +78,7 @@ "race_1_minute": "Start om en minut.", "race_30_seconds": "Trettio sekunder till start.", "race_10_seconds": "Tio sekunder till start.", "drivers_ready": "Förare, gör er redo.", "start_sequence": "Start på signalen.", "false_start": "Felaktig start.", "restart_race": "Förbered omstart.", "staggered_release": "Bil {tp}.", + "heat_call": "{heat} startar om {minutes} minuter. Förare: {drivers}. Gör er redo.", "prologue_start": "{heat} startar om {time}. Banan är öppen.", "prologue_minutes": "{minutes} minuter till start.", "prologue_grid": "Trettio sekunder till start. Bilarna till startplatsen.", diff --git a/src/app.js b/src/app.js index 205f293..52be02f 100644 --- a/src/app.js +++ b/src/app.js @@ -8,8 +8,8 @@ import { buildRaceDayQueue, buildRaceDayPreflight, getRaceDriverIds } from "./ra import { recordTransponderSighting, buildWarmupCheck, createPrologue, getPrologueRemainingMs, holdPrologue, resumePrologue, setPrologueRemaining, takeDuePrologueCall, formatPrologueTime, getPrologueHandoverMs, normalizePrologueSec } from "./prologue_logic.js"; import { findTransponderConflict, getDriverProfileId } from "./driver_profile_logic.js"; import { renderRaceDayView, refreshRaceDayWarmup, refreshRaceDayPrologueClock, updateRaceDayStartDisplay, refreshRaceDayLive } from "./race_day_view.js"; -import { normalizeRaceDays, getRaceDay, upsertRaceDay, orderDaySessions, buildDaySchedule, getAutopilotAction, moveInDayOrder, pickBoardDate } from "./day_schedule_logic.js"; -import { renderDaySchedulePanel, bindDaySchedulePanel, buildDaySchedulePrintHtml, renderDriverBoard, formatClockTime } from "./day_schedule_view.js"; +import { normalizeRaceDays, getRaceDay, upsertRaceDay, orderDaySessions, buildDaySchedule, getAutopilotAction, moveInDayOrder, pickBoardDate, getDueCall } from "./day_schedule_logic.js"; +import { renderDaySchedulePanel, bindDaySchedulePanel, buildDaySchedulePrintHtml, renderDriverBoard, formatClockTime, renderDayCallBanner, bindDayCallBanner } from "./day_schedule_view.js"; import { beginSession as beginSessionControl, finishSession as finishSessionControl, pauseSession as pauseSessionControl, resumeSession as resumeSessionControl } from "./session_control.js"; import { normalizeSeries, buildSeriesStandings, getSeriesRoundStatus, getSeriesRoundNextStep, getSeriesDayResult } from "./series_logic.js"; import { renderSeriesView } from "./series_view.js"; @@ -237,6 +237,7 @@ const startSessionWithAudio = (session, callbacks) => { const tickClock = () => { tickClockHelper({ dom, currentLanguage, handleSessionTimerTick, getActiveSession, getCurrentView: () => currentView, getOverlayMode: () => overlayMode, renderView, refreshTimingDynamics, updateHeaderState }); tickAutopilot(); + tickDayCalls(); // The drivers' board counts down to each heat. if (overlayMode && overlayViewMode === "schedule") renderView(); }; @@ -428,6 +429,52 @@ function tickAutopilot() { } void startOperationalSession(session, { requirePreflight: true }).finally(() => { autopilotLaunchingId = null; renderView(); }); } +// Calling a heat: the speaker says who drives it and the drivers' board highlights it. With the +// autopilot on it happens on its own; otherwise Race Day asks the race controller. +const callSnoozes = new Map(); +let shownCallId = null; +function callHeat(sessionId) { + const session = state.sessions.find((item) => item.id === sessionId); + if (!session || session.calledAt) return; + const event = state.events.find((item) => item.id === session.eventId); + const row = event ? buildDayRows(event.date).find((item) => item.session.id === sessionId) : null; + session.calledAt = Date.now(); + saveState(); + triggerRaceAudio("heat_call", { + force: true, + variables: { + heat: `${getDayClassLabel(session)} ${session.name}`.trim(), + minutes: Math.max(1, Math.round(((row?.start || Date.now()) - Date.now()) / 60000)), + drivers: getSessionGridEntries(session).map((entry) => entry.name).join(", "), + }, + logData: { raceId: session.eventId, sessionId: session.id }, + }); + renderView(); +} +function getDueCallFor(date) { + return getDueCall(buildDayRows(date), { day: getDayPlan(date), snoozedUntil: (id) => callSnoozes.get(id) || 0 }); +} +function tickDayCalls() { + if (overlayMode) return; + if (autopilotDate) { + const due = getDueCallFor(autopilotDate); + if (due) callHeat(due.session.id); + return; + } + if (currentView !== "race_day") return; + const due = getDueCallFor(getRaceDayDate()); + if ((due?.session.id || null) !== shownCallId) renderView(); +} +const renderDayCall = () => { + const date = getRaceDayDate(); + const row = autopilotDate ? null : getDueCallFor(date); + shownCallId = row?.session.id || null; + return renderDayCallBanner({ t, escapeHtml, row, getClassLabel: getDayClassLabel, driverNames: row ? getSessionGridEntries(row.session).map((entry) => entry.name) : [] }); +}; +const bindDayCall = (root) => bindDayCallBanner(root, { + onCall: (sessionId) => callHeat(sessionId), + onLater: (sessionId) => { callSnoozes.set(sessionId, Date.now() + 2 * 60000); renderView(); }, +}); // Pausing the day stops the autopilot and pauses whatever is on track (or holds the count-down). function pauseRaceDay(date) { saveDayPlan({ ...getDayPlan(date), pausedAt: Date.now() }); @@ -458,7 +505,7 @@ const bindDaySchedule = (root) => { const date = getRaceDayDate(); bindDaySchedulePanel(root, { date, - onSavePlan: ({ startAt, gapMin }) => { saveDayPlan({ ...getDayPlan(date), startAt, gapMin }); renderView(); }, + onSavePlan: ({ startAt, gapMin, callMin }) => { saveDayPlan({ ...getDayPlan(date), startAt, gapMin, callMin }); renderView(); }, onMove: (sessionId, step) => moveDaySession(date, sessionId, step), onPrint: () => openPrintWindow(t("day.print_title", { date }), buildDaySchedulePrintHtml({ t, escapeHtml, date, rows: buildDayRows(date), getClassLabel: getDayClassLabel, getSessionGridEntries })), onBoard: () => window.open(buildOverlayUrl("schedule", { public: true }), "_blank"), @@ -487,6 +534,7 @@ function resetSessionData(session) { session.resultsResetAt = Date.now(); delete state.resultsBySession[session.id]; session.followUpStartedAt = null; + session.calledAt = 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"; @@ -619,7 +667,7 @@ const renderRaceDay = () => renderRaceDayView({ getLiveSession, renderSuspectLapsPanel: (session) => renderSuspectLapsPanelWithRelease(session), buildLeaderboard, getSessionTargetMs, formatRaceClock, - renderDaySchedule, bindDaySchedule, + renderDaySchedule, bindDaySchedule, renderDayCall, bindDayCall, setCompetitorLapStatus, addTrackLayout, renderView, state, dom, t, escapeHtml, formatLap, formatCountdown, formatElapsedClock, getEventName, getSessionTypeLabel, getStatusLabel, getStartModeLabel, @@ -2743,7 +2791,7 @@ const TRANSLATIONS = { "guide.race_day_8": "8. Redan när du registrerar eller ändrar en förare under Förare varnar systemet om transpondern redan används av en annan förare (t.ex. i fel klass) och namnger vem - ett komplement till förkontrollens kontroll av dubbla transpondrar inom samma heat. Samma person som kör flera klasser med sin egen transponder flaggas aldrig.", "guide.race_day_9": "9. Kör ni på ett nät där fler har åtkomst (t.ex. arenans WiFi)? Slå på Admin-PIN under Inställningar -> System & backup. Då kräver alla ändringar PIN - resultat, inställningar och uppdatering - medan visning och publika overlay-/träningslänkar fungerar som vanligt. Varje webbläsare loggar in en gång och kommer ihåg det i 30 dagar.", "guide.race_day_10": "10. Start med nedräkning (som EFRA/IFMAR): välj längd (Go, 30 s, 1, 1:30, 2, 3 eller 5 min - standard per tävling under Race Setup) och tryck Starta. Banan är öppen, speakern ropar ut tiden (varje minut, 30 s, 10 s; vid gridstart även \"bilarna till startplatsen\" vid 30 s och 9..3). Pausa medan bilarna ställs upp, +1 min, Till 30 s (omstart av gridet), Till 10 s, Go nu eller Avbryt. När tiden går ut startar heatet av sig själv: gridstart får startljus och slumpad signal, flygande start ger signalen och \"Klockan går\". Transponderkontrollen visar grön bock för alla som passerat sedan nedräkningen började - saknas någon, byt transponder direkt i panelen eller välj en okänd transponder som passerat. Go nu varnar om någon inte setts.", - "guide.race_day_11": "11. Dagens schema (längst ned på Race Day) visar alla klasser den dagen i en körordning med tider. Ange första start och paus mellan heaten; ▲▼ ändrar ordningen. Ett heat som startar sent eller pausas flyttar resten av dagen. 🖨 Skriv ut körordning ger en lista med tider och förare att sätta upp på tavlan, och 📺 Förarvy (/public-overlay/schedule) visar förarna nästa heat med vilka som kör och en påminnelse när det är 10 minuter kvar. ▶ Kör dagen automatiskt startar varje heats nedräkning själv när det är dags (den här webbläsaren måste vara öppen); ⏸ Pausa dagen pausar heatet på banan och automatiken tills du fortsätter.", + "guide.race_day_11": "11. Dagens schema (längst ned på Race Day) visar alla klasser den dagen i en körordning med tider. Ange första start och paus mellan heaten; ▲▼ ändrar ordningen. Ett heat som startar sent eller pausas flyttar resten av dagen. 🖨 Skriv ut körordning ger en lista med tider och förare att sätta upp på tavlan, och 📺 Förarvy (/public-overlay/schedule) visar förarna nästa heat och vilka som kör. Upprop: när ett heat har 10 minuter kvar (ändras under Upprop) frågar Race Day om du vill ropa upp det – 📢 Ropa ut läser upp heatet och förarna i högtalarna och markerar det Uppropad i förarvyn; Senare frågar igen om 2 minuter. ▶ Kör dagen automatiskt startar varje heats nedräkning själv när det är dags och ropar då upp heaten själv (den här webbläsaren måste vara öppen); ■ Stoppa automatiken låter dig köra för hand och sedan slå på den igen; ⏸ Pausa dagen pausar heatet på banan och automatiken tills du fortsätter.", "guide.dashboard_title": "Schemaavvikelse på Översikt", "guide.dashboard_1": "Översikt visar nu skillnaden mellan planerad tid och faktisk körtid för alla startade sessioner.", "guide.dashboard_2": "Planerad tid räknar sessionstid plus follow-up. Faktisk tid räknar verklig tid från start till stopp eller nuvarande tid om heatet fortfarande kör.", @@ -2806,6 +2854,11 @@ const TRANSLATIONS = { "day.board": "Förarvy", "day.start_time": "Första start", "day.gap": "Paus mellan heat (min)", + "day.call_min": "Upprop (min innan)", + "day.call_title": "{name} startar {time} (om {min} min) – dags att ropa upp", + "day.call_now": "Ropa ut", + "day.call_later": "Senare", + "day.called_at": "Uppropad {time}", "day.autopilot_on": "Kör dagen automatiskt", "day.autopilot_off": "Stoppa automatiken", "day.autopilot_confirm": "Kör dagen automatiskt? Varje heat startar sin nedräkning själv när det är dags enligt schemat. Du kan pausa dagen eller ta över när som helst. Låt den här webbläsaren vara öppen.", @@ -2829,7 +2882,7 @@ const TRANSLATIONS = { "day.print_hint": "Tiderna är planerade och kan flyttas om något drar ut på tiden. Följ förarvyn för aktuella tider.", "day.board_title": "Dagens schema {date}", "day.board_now": "startar nu", - "day.board_heads_up": "Gör dig redo – snart dags!", + "day.board_heads_up": "Uppropad – gör dig redo!", "day.board_on_track": "På banan", "day.board_all_done": "Alla heat är körda för idag.", "day.board_none": "Inget schema för idag.", @@ -4675,7 +4728,7 @@ const TRANSLATIONS = { "guide.race_day_8": "8. Already when you register or edit a driver under Drivers, the system warns if the transponder is already used by a different driver (e.g. in the wrong class) and names who - a complement to the preflight's duplicate-transponder check within a single heat. The same person racing multiple classes on their own transponder is never flagged.", "guide.race_day_9": "9. Running on a network others can reach (e.g. the venue WiFi)? Turn on the Admin PIN under Settings -> System & backup. Every change then needs the PIN - results, settings and updates - while viewing and public overlay/training links work as usual. Each browser logs in once and is remembered for 30 days.", "guide.race_day_10": "10. Start with a count-down (as EFRA/IFMAR): pick a length (Go, 30 s, 1, 1:30, 2, 3 or 5 min - the default per event is set in Race Setup) and press Start. The track is open and the announcer calls the time (every minute, 30 s, 10 s; for a grid start also \"cars to the grid\" at 30 s and 9..3). Hold while cars are placed on the grid, +1 min, To 30 s (grid restart), To 10 s, Go now or Cancel. When the time runs out the heat starts by itself: a grid start gets the start lights and a random signal, a flying start gets the signal and \"Clock is running\". The transponder check shows a green tick for everyone who has crossed since the count-down began - if someone is missing, change their transponder right in the panel or pick an unknown transponder that crossed. Go now warns if someone wasn't seen.", - "guide.race_day_11": "11. Today's schedule (at the bottom of Race Day) shows every class that day in one running order with times. Set the first start and the break between heats; ▲▼ change the order. A heat that starts late or is paused moves the rest of the day. 🖨 Print running order gives a list with times and drivers for the board in the pits, and 📺 Drivers' board (/public-overlay/schedule) shows drivers the next heats, who drives them and a heads-up 10 minutes before. ▶ Run the day automatically starts each heat's count-down on its own when it is due (keep this browser open); ⏸ Pause the day pauses the heat on track and the autopilot until you resume.", + "guide.race_day_11": "11. Today's schedule (at the bottom of Race Day) shows every class that day in one running order with times. Set the first start and the break between heats; ▲▼ change the order. A heat that starts late or is paused moves the rest of the day. 🖨 Print running order gives a list with times and drivers for the board in the pits, and 📺 Drivers' board (/public-overlay/schedule) shows drivers the next heats and who drives them. Calls: when a heat is 10 minutes away (set under Call), Race Day asks whether to call it – 📢 Call now reads the heat and its drivers over the speakers and marks it Called on the drivers' board; Later asks again in 2 minutes. ▶ Run the day automatically starts each heat's count-down on its own when it is due and then calls the heats itself (keep this browser open); ■ Stop autopilot lets you run heats by hand and turn it back on later; ⏸ Pause the day pauses the heat on track and the autopilot until you resume.", "guide.dashboard_title": "Schedule drift on overview", "guide.dashboard_1": "Overview now shows the difference between planned time and actual elapsed time for all started sessions.", "guide.dashboard_2": "Planned time includes session duration plus follow-up. Actual time uses real time from start to stop, or the current time if the heat is still running.", @@ -4738,6 +4791,11 @@ const TRANSLATIONS = { "day.board": "Drivers' board", "day.start_time": "First start", "day.gap": "Break between heats (min)", + "day.call_min": "Call (min before)", + "day.call_title": "{name} starts at {time} (in {min} min) – time to call it", + "day.call_now": "Call now", + "day.call_later": "Later", + "day.called_at": "Called {time}", "day.autopilot_on": "Run the day automatically", "day.autopilot_off": "Stop autopilot", "day.autopilot_confirm": "Run the day automatically? Each heat starts its own count-down when the schedule says so. You can pause the day or take over at any time. Keep this browser open.", @@ -4761,7 +4819,7 @@ const TRANSLATIONS = { "day.print_hint": "Times are planned and can move if something runs long. Follow the drivers' board for current times.", "day.board_title": "Today's schedule {date}", "day.board_now": "starting now", - "day.board_heads_up": "Get ready – almost time!", + "day.board_heads_up": "Called – get ready!", "day.board_on_track": "On track", "day.board_all_done": "Every heat has been run today.", "day.board_none": "No schedule for today.", diff --git a/src/day_schedule_logic.js b/src/day_schedule_logic.js index 89c2ec0..a7160b8 100644 --- a/src/day_schedule_logic.js +++ b/src/day_schedule_logic.js @@ -4,14 +4,16 @@ import { applyManualOrder, orderSessionsForRunning, parseQualifyingHeatName } from "./event_race_logic.js"; export const DEFAULT_DAY_GAP_MIN = 3; -export const HEADS_UP_MS = 10 * 60000; +export const DEFAULT_CALL_MIN = 10; -// One plan per date: { date, startAt, gapMin, sessionOrder, autopilot, pausedAt }. +// One plan per date: { date, startAt, gapMin, callMin, sessionOrder, autopilot, pausedAt }. +// callMin = how long before its start a heat is called (drivers get ready). export function normalizeRaceDay(day = {}) { return { date: String(day.date || ""), startAt: Number(day.startAt) > 0 ? Number(day.startAt) : null, gapMin: Number.isFinite(Number(day.gapMin)) && day.gapMin !== null && day.gapMin !== "" ? Math.max(0, Number(day.gapMin)) : DEFAULT_DAY_GAP_MIN, + callMin: Number(day.callMin) > 0 ? Math.min(60, Number(day.callMin)) : DEFAULT_CALL_MIN, sessionOrder: [...new Set((Array.isArray(day.sessionOrder) ? day.sessionOrder : []).map(String).filter(Boolean))], autopilot: day.autopilot === true, pausedAt: Number(day.pausedAt) > 0 ? Number(day.pausedAt) : null, @@ -142,3 +144,11 @@ export function pickBoardDate({ events = [], sessions = [], today }) { .sort(); return pending[0] || today; } + +// The next heat to call: the first one not yet called that starts within callMin. A heat the +// race controller put off ("Later") is skipped until snoozedUntil(sessionId) has passed. +export function getDueCall(rows, { day, now = Date.now(), snoozedUntil = () => 0 }) { + if (day?.pausedAt) return null; + const callMs = Math.max(1, Number(day?.callMin || DEFAULT_CALL_MIN)) * 60000; + return rows.find((row) => row.state === "upcoming" && !row.session.calledAt && row.start - now <= callMs && Number(snoozedUntil(row.session.id) || 0) <= now) || null; +} diff --git a/src/day_schedule_view.js b/src/day_schedule_view.js index 65a81ac..30d5984 100644 --- a/src/day_schedule_view.js +++ b/src/day_schedule_view.js @@ -1,7 +1,6 @@ // The race day schedule on screen: the panel on Race Day (plan, order, autopilot, pause), the // printable running order for the board in the pits, and the drivers' board // (/public-overlay/schedule). Logic in day_schedule_logic.js, the autopilot runner in app.js. -import { HEADS_UP_MS } from "./day_schedule_logic.js"; export const formatClockTime = (ts) => (ts ? new Date(ts).toLocaleTimeString("sv-SE", { hour: "2-digit", minute: "2-digit" }) : "-"); const toTimeInput = (ts) => (ts ? formatClockTime(ts) : ""); @@ -14,7 +13,8 @@ function rowLabel(row, getClassLabel) { function stateLabel(row, t, now) { if (row.state === "done") return t("day.state_done"); if (row.state === "live") return t(row.session.status === "paused" ? "day.state_paused" : "day.state_live"); - if (row.start - now <= HEADS_UP_MS) return t("day.in_min", { min: minutesUntil(row.start, now) }); + if (row.session.calledAt) return `📢 ${t("day.called_at", { time: formatClockTime(row.session.calledAt) })}`; + if (row.start - now <= 15 * 60000) return t("day.in_min", { min: minutesUntil(row.start, now) }); return ""; } @@ -33,6 +33,7 @@ export function renderDaySchedulePanel({ t, escapeHtml, date, day, rows, autopil
+
@@ -64,13 +65,38 @@ export function renderDaySchedulePanel({ t, escapeHtml, date, day, rows, autopil `; } +// For the race controller when heats are started by hand: the next heat is due to be called. +// (With the autopilot on, the call is made on its own.) +export function renderDayCallBanner({ t, escapeHtml, row, getClassLabel, driverNames = [], now = Date.now() }) { + if (!row) return ""; + return ` +
+
+ 📢 ${escapeHtml(t("day.call_title", { name: rowLabel(row, getClassLabel), time: formatClockTime(row.start), min: minutesUntil(row.start, now) }))} + ${escapeHtml(driverNames.join(", ") || t("race_day.no_start_list"))} +
+
+ + +
+
`; +} + +export function bindDayCallBanner(root, { onCall, onLater }) { + const banner = root.querySelector("#dayCallBanner"); + if (!banner) return; + const sessionId = banner.dataset.dayCall; + root.querySelector("#dayCallNow")?.addEventListener("click", () => onCall(sessionId)); + root.querySelector("#dayCallLater")?.addEventListener("click", () => onLater(sessionId)); +} + export function bindDaySchedulePanel(root, { date, onSavePlan, onMove, onPrint, onBoard, onAutopilot, onPause, onResume }) { root.querySelector("#dayPlanForm")?.addEventListener("submit", (event) => { event.preventDefault(); const form = new FormData(event.currentTarget); const time = String(form.get("startTime") || "").trim(); const startAt = time ? new Date(`${date}T${time}`).getTime() : null; - onSavePlan({ startAt: Number.isFinite(startAt) ? startAt : null, gapMin: Math.max(0, Number(form.get("gapMin")) || 0) }); + onSavePlan({ startAt: Number.isFinite(startAt) ? startAt : null, gapMin: Math.max(0, Number(form.get("gapMin")) || 0), callMin: Math.max(1, Number(form.get("callMin")) || 10) }); }); root.querySelectorAll("[data-day-move]").forEach((button) => button.addEventListener("click", () => onMove(button.dataset.dayMove, Number(button.dataset.step)))); root.querySelector("#dayPrint")?.addEventListener("click", onPrint); @@ -109,23 +135,24 @@ export function buildDaySchedulePrintHtml({ t, escapeHtml, date, rows, getClassL
`; } -// The drivers' board: what is on track, the next heats with a heads-up and who drives them, +// The drivers' board: what is on track, the next heats with who drives them (highlighted once called), // then the rest of the day. export function renderDriverBoard({ t, escapeHtml, date, rows, getClassLabel, getSessionGridEntries, getRemainingLabel, now = Date.now() }) { const live = rows.find((row) => row.state === "live"); const next = rows.filter((row) => row.state === "upcoming").slice(0, 3); const later = rows.filter((row) => row.state === "upcoming").slice(3); const card = (row) => { - const soon = row.start - now <= HEADS_UP_MS; + // Highlighted once the race controller (or the autopilot) has called the heat. + const called = Boolean(row.session.calledAt); const minutes = minutesUntil(row.start, now); return ` -
+
${formatClockTime(row.start)} ${escapeHtml(minutes <= 0 ? t("day.board_now") : t("day.in_min", { min: minutes }))}

${escapeHtml(rowLabel(row, getClassLabel))}

- ${soon ? `

${escapeHtml(t("day.board_heads_up"))}

` : ""} + ${called ? `

📢 ${escapeHtml(t("day.board_heads_up"))}

` : ""}
    ${getSessionGridEntries(row.session).map((entry) => `
  1. ${escapeHtml(entry.name)}
  2. `).join("") || `
  3. ${escapeHtml(t("race_day.no_start_list"))}
  4. `}
`; }; diff --git a/src/race_audio.js b/src/race_audio.js index e5c969e..7f872af 100644 --- a/src/race_audio.js +++ b/src/race_audio.js @@ -14,6 +14,7 @@ export const RACE_AUDIO_EVENT_DEFINITIONS = Object.freeze([ event("prologue_grid", "start", "high"), event("prologue_count", "start", "high"), event("prologue_hold", "start", "high", true, "effects/warning.wav"), event("prologue_resumed", "start", "normal"), event("prologue_cancelled", "start", "normal"), event("clock_running", "start", "high"), + event("heat_call", "start", "normal"), event("transponder_pass", "race", "pass", false, "effects/transponder_pass.wav"), event("lap_completed", "race", "pass", false), event("personal_best", "race", "low", true, "effects/personal_best.wav", 1500), event("fastest_lap", "race", "normal", true, "effects/fastest_lap_trophy.wav", 1500), diff --git a/src/race_day_view.js b/src/race_day_view.js index 4f17c1e..349f905 100644 --- a/src/race_day_view.js +++ b/src/race_day_view.js @@ -263,7 +263,7 @@ export function renderRaceDayView(deps) { isStartPending, renderSuspectLapsPanel = () => "", setCompetitorLapStatus = () => false, getLiveSession = () => null, resetSessionData = () => false, startPracticeNow = async () => false, findOpenPracticeToContinue = () => null, buildLeaderboard = () => [], getSessionTargetMs = () => null, formatRaceClock = (ms) => String(ms), - renderDaySchedule = () => "", bindDaySchedule = () => {}, + renderDaySchedule = () => "", bindDaySchedule = () => {}, renderDayCall = () => "", bindDayCall = () => {}, } = deps; const queue = buildRaceDayQueue(state); const session = queue.current; @@ -308,6 +308,7 @@ export function renderRaceDayView(deps) { ${layoutAllowed ? `` : ""} + ${renderDayCall()} ${liveElsewhere ? `
⏱ ${escapeHtml(t("timing.live_elsewhere", { name: liveElsewhere.name }))}
` : ""}
@@ -442,6 +443,7 @@ export function renderRaceDayView(deps) { }); bindTrackLayoutBar(dom.view, { state, t, addTrackLayout, renderView }); bindDaySchedule(dom.view); + bindDayCall(dom.view); lastWarmupDeps = { t, escapeHtml, renderView, getRaceDayWarmupCheck, setDriverTransponder, getSession: () => buildRaceDayQueue(state).current }; paintWarmupPanel(); lastLiveDeps = { t, escapeHtml, formatLap, formatRaceClock, buildLeaderboard, getSessionTargetMs, getSession: () => buildRaceDayQueue(state).current }; diff --git a/src/styles.css b/src/styles.css index c80e73b..b254d1a 100644 --- a/src/styles.css +++ b/src/styles.css @@ -4790,8 +4790,12 @@ tr.is-removed td.lap-actions { .board-next h3 { margin: 6px 0; font-size: 1.3rem; } .board-time { font-size: 2rem; font-variant-numeric: tabular-nums; } .board-when { font-size: 1.1rem; color: var(--muted); } -.board-next.is-soon { border: 2px solid var(--warn); } -.board-next.is-soon .board-when { color: var(--warn); font-weight: 700; } +.board-next.is-called { border: 2px solid var(--warn); background: rgba(245, 166, 35, 0.12); } +.board-next.is-called .board-when { color: var(--warn); font-weight: 700; } +.day-call-banner { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px 16px; margin-bottom: 12px; border: 2px solid var(--warn); border-radius: 12px; background: rgba(245, 166, 35, 0.12); } +.day-call-banner > div:first-child { display: grid; gap: 4px; } +.day-call-banner strong { font-size: 1.15rem; } +.day-call-actions { display: flex; gap: 8px; } .board-heads-up { margin: 0 0 8px; font-weight: 700; color: var(--warn); } .board-next ol { margin: 0; padding-left: 24px; font-size: 1.15rem; line-height: 1.5; } .board-later { width: 100%; border-collapse: collapse; font-size: 1.05rem; } diff --git a/tests/browser_day_schedule.js b/tests/browser_day_schedule.js index df3874b..1a2250d 100644 --- a/tests/browser_day_schedule.js +++ b/tests/browser_day_schedule.js @@ -51,6 +51,9 @@ export async function runDayScheduleSmoke({ evaluate, navigate, savedState, wait await evaluate(`(() => { const form = document.getElementById("dayPlanForm"); form.elements.startTime.value = ${JSON.stringify(hhmm(new Date(Date.now() - 60000)))}; form.requestSubmit(); })()`); await waitFor(async () => (await evaluate(`document.querySelector("[data-autopilot-status]").textContent`)).includes("decoder is not connected"), "waits for the decoder"); assert.equal((await savedState()).sessions.find((session) => session.id === "ds_4wd_q1").status, "ready", "nothing started without a decoder"); + // With the autopilot on, a heat due within 10 minutes is called on its own. + await waitFor(async () => Boolean((await savedState()).sessions.find((session) => session.id === "ds_4wd_q1").calledAt), "the autopilot calls the next heat"); + assert.equal(await evaluate(`Boolean(document.getElementById("dayCallBanner"))`), false, "no question to the race controller while the autopilot runs"); await evaluate(`document.getElementById("dayPause").click()`); await waitFor(async () => Boolean(((await savedState()).raceDays || []).find((day) => day.date === today)?.pausedAt), "the day is paused"); await waitFor(async () => (await evaluate(`document.querySelector("[data-autopilot-status]").textContent`)) === "The day is paused", "the autopilot says the day is paused"); @@ -58,7 +61,20 @@ export async function runDayScheduleSmoke({ evaluate, navigate, savedState, wait await waitFor(async () => !((await savedState()).raceDays || []).find((day) => day.date === today)?.pausedAt, "the day is resumed"); await evaluate(`document.getElementById("dayAutopilotOff").click()`); await waitFor(async () => ((await savedState()).raceDays || []).find((day) => day.date === today)?.autopilot === false, "autopilot off"); - console.log("PASS the autopilot says what comes next, waits for the decoder, and the day can be paused and resumed"); + console.log("PASS the autopilot says what comes next, calls the heat, waits for the decoder, and the day can be paused and resumed"); + + // By hand: Race Day asks the race controller to call the next heat (here 20 min before). + await evaluate(`(() => { const form = document.getElementById("dayPlanForm"); form.elements.callMin.value = "20"; form.requestSubmit(); })()`); + // The autopilot may already have called the 2WD Q1 H1; the banner asks for each heat not yet called, in order. + for (let round = 0; round < 3; round += 1) { + await waitFor(async () => Boolean(await evaluate(`document.getElementById("dayCallBanner")?.dataset.dayCall`)), "Race Day asks to call the next heat not yet called"); + const asked = await evaluate(`document.getElementById("dayCallBanner").dataset.dayCall`); + await evaluate(`document.getElementById("dayCallNow").click()`); + await waitFor(async () => Boolean((await savedState()).sessions.find((session) => session.id === asked).calledAt), "Call now marks it called"); + if (asked === "ds_2wd_q2") break; + } + await waitFor(async () => !(await evaluate(`Boolean(document.getElementById("dayCallBanner"))`)), "and the question goes away once every heat is called"); + console.log("PASS heats started by hand: Race Day asks the race controller to call the next heat"); const printHtml = await evaluate(`(async () => { const { buildDaySchedulePrintHtml } = await import("/src/day_schedule_view.js"); @@ -70,9 +86,10 @@ export async function runDayScheduleSmoke({ evaluate, navigate, savedState, wait await send("Page.navigate", { url: base + "/public-overlay/schedule" }); await waitFor(async () => (await evaluate(`document.querySelectorAll(".board-next").length`)) === 3, "the board shows the next three heats"); const board = await evaluate(`document.querySelector(".driver-board").innerText`); - assert.ok(board.includes("Get ready"), "a heat due within 10 minutes gets a heads-up"); + assert.ok(board.includes("Called – get ready"), "a called heat is highlighted for the drivers"); + assert.equal(await evaluate(`document.querySelector(".board-next").classList.contains("is-called")`), true); assert.equal(await evaluate(`document.querySelector(".board-next").dataset.boardSession`), "ds_4wd_q1", "in the day's order"); - console.log("PASS the drivers' board shows the next heats with their drivers and a heads-up"); + console.log("PASS the drivers' board shows the next heats with their drivers, called heats highlighted"); } finally { const current = await savedState(); await patchState({ diff --git a/tests/day_schedule.test.js b/tests/day_schedule.test.js index b625cb0..580c4a9 100644 --- a/tests/day_schedule.test.js +++ b/tests/day_schedule.test.js @@ -68,3 +68,17 @@ test("race days are stored one per date, and the board shows today or the next d assert.equal(pickBoardDate({ events, sessions, today: "2026-11-01" }), "2026-11-08"); assert.equal(pickBoardDate({ events, sessions, today: "2026-12-01" }), "2026-12-01"); }); + +test("a heat is due for its call within callMin, once, and not while put off or the day is paused", async () => { + const { getDueCall } = await import("../src/day_schedule_logic.js"); + const start = Date.UTC(2026, 10, 8, 10, 0); + const rows = buildDaySchedule([s("one", "e2", "qualification", "Q1 H1"), s("two", "e2", "qualification", "Q1 H2")], { startAt: start, gapMin: 3 }, start - 3600000); + const day = { callMin: 10 }; + assert.equal(getDueCall(rows, { day, now: start - 11 * 60000 }), null); + assert.equal(getDueCall(rows, { day, now: start - 10 * 60000 }).session.id, "one"); + const called = rows.map((row, i) => (i === 0 ? { ...row, session: { ...row.session, calledAt: start - 600000 } } : row)); + assert.equal(getDueCall(called, { day, now: start - 5 * 60000 }), null, "the next heat is not due yet"); + assert.equal(getDueCall(called, { day, now: start }).session.id, "two"); + assert.equal(getDueCall(rows, { day, now: start - 5 * 60000, snoozedUntil: () => start - 3 * 60000 }), null, "put off"); + assert.equal(getDueCall(rows, { day: { ...day, pausedAt: 1 }, now: start }), null); +});