diff --git a/CHANGELOG.md b/CHANGELOG.md index 1428766..12201f8 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.48.0 - 2026-11-01 + +### Added + +- Series: **✎ Result** on a round sets the day's finishing order by hand (move up and down, add, remove), for example when the qualifying went wrong and the club decided the order itself. It replaces the calculated result in the standings, and the round is marked "Corrected result". "Use the calculated result" goes back. + +### Fixed + +- A stand-alone overlay window (OBS) kept showing a heat as running after it was paused or finished (since 1.46.1). Only the browser that runs the race keeps its own data; an overlay window always follows the server. + ## 1.47.1 - 2026-11-01 ### Fixed diff --git a/README.md b/README.md index 8175087..ff6d2ab 100644 --- a/README.md +++ b/README.md @@ -190,6 +190,7 @@ Menu **Series / cup** runs a championship over any number of rounds, with freely 4. **Standings:** - The day placing comes from the final standings (A before B), then qualifying order. - No registered lap gives 0. Absence counts as 0 and can be dropped. + - **✎ Result** on a round sets the day's order by hand (▲▼, add, remove), e.g. when the qualifying went wrong. It replaces the calculated result in the standings, and the round is marked Corrected result. Use the calculated result goes back. - Ties go to most wins, then 2nd places, then the latest common round. - Print, or export as PDF (wide tables switch to landscape). diff --git a/README.sv.md b/README.sv.md index 9367f12..be08d26 100644 --- a/README.sv.md +++ b/README.sv.md @@ -203,6 +203,7 @@ Menyn **Serier / cup** kör ett mästerskap över valfritt antal deltävlingar, 4. **Ställning:** - Dagens placering kommer från slutresultatet (A före B), sedan kvalordningen. - Inget registrerat varv ger 0. Frånvaro räknas som 0 och kan strykas. + - **✎ Resultat** på en deltävling sätter dagens ordning för hand (▲▼, lägg till, ta bort), t.ex. när kvalet blev fel. Den ersätter appens uträkning i ställningen, och deltävlingen märks Rättat resultat. Använd appens resultat går tillbaka. - Lika poäng avgörs av flest segrar, sedan andraplatser, sedan senaste gemensamma deltävling. - Skriv ut eller exportera som PDF (breda tabeller blir liggande A4). diff --git a/package-lock.json b/package-lock.json index 80e6283..894d31f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "rc-racecore", - "version": "1.47.1", + "version": "1.48.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "rc-racecore", - "version": "1.47.1", + "version": "1.48.0", "hasInstallScript": true, "dependencies": { "better-sqlite3": "^12.11.1", diff --git a/package.json b/package.json index 89fe210..e1cd323 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rc-racecore", - "version": "1.47.1", + "version": "1.48.0", "private": true, "description": "RC RaceCore live timing and race control with AMMC ingest and SQLite persistence", "engines": { diff --git a/src/app.js b/src/app.js index e33780c..ee66a0e 100644 --- a/src/app.js +++ b/src/app.js @@ -9,7 +9,7 @@ import { recordTransponderSighting, buildWarmupCheck, createPrologue, getPrologu import { findTransponderConflict, getDriverProfileId } from "./driver_profile_logic.js"; import { renderRaceDayView, refreshRaceDayWarmup, refreshRaceDayPrologueClock, updateRaceDayStartDisplay, refreshRaceDayLive } from "./race_day_view.js"; import { beginSession as beginSessionControl, finishSession as finishSessionControl, pauseSession as pauseSessionControl, resumeSession as resumeSessionControl } from "./session_control.js"; -import { normalizeSeries, buildSeriesStandings, getSeriesRoundStatus, getSeriesRoundNextStep } from "./series_logic.js"; +import { normalizeSeries, buildSeriesStandings, getSeriesRoundStatus, getSeriesRoundNextStep, getSeriesDayResult } from "./series_logic.js"; import { renderSeriesView } from "./series_view.js"; import { RACE_AUDIO_EVENT_DEFINITIONS, createRaceAudioEngine, normalizeRaceAudioSettings, isSilencedDuringRace } from "./race_audio.js"; @@ -159,8 +159,9 @@ const hydrateFromBackend = ({ initial = false } = {}) => hydrateFromBackendHelpe // The first load at page start always takes the server's state. ...(initial ? {} : { getLocalStateVersion: () => localStateVersion, getLocalStateDirty: () => localStateDirty, keepLocal: isRunningRaceHere }), }); -// This browser is starting or timing a heat: its own state is the newest. -const isRunningRaceHere = () => Boolean(getPrologueSession() || pendingStartSessionId || startsInProgress > 0 +// This browser is starting or timing a heat: its own state is the newest. A stand-alone +// overlay window only shows the race, so it always follows the server. +const isRunningRaceHere = () => !overlayMode && Boolean(getPrologueSession() || pendingStartSessionId || startsInProgress > 0 || (state.decoder?.connected && state.sessions.some((session) => ["running", "paused"].includes(session.status)))); const scheduleBackendSync = () => scheduleBackendSyncHelper({ getBackendSyncTimer: () => backendSyncTimer, setBackendSyncTimer: (value) => { backendSyncTimer = value; }, syncStateToBackend }); const syncStateToBackend = () => syncStateToBackendHelper({ backend, t, getBackendUrl, buildPersistableState, getLocalStateVersion: () => localStateVersion, getSyncedStateVersion: () => syncedStateVersion, setSyncedStateVersion: (value) => { syncedStateVersion = value; }, getLocalStateDirty: () => localStateDirty, setLocalStateDirty: (value) => { localStateDirty = value; } }); @@ -589,9 +590,10 @@ const getEventDayResult = (event) => { buildQualifyingStandings(event).forEach(add); return order; }; +const getDriverNameById = (driverId) => state.drivers.find((driver) => driver.id === driverId)?.name || ""; const getSeriesStandings = (series) => buildSeriesStandings(series, { events: state.events, - dayResults: new Map(state.events.filter((event) => series.eventIds.includes(event.id)).map((event) => [event.id, getEventDayResult(event)])), + dayResults: new Map(state.events.filter((event) => series.eventIds.includes(event.id)).map((event) => [event.id, getSeriesDayResult(series, event.id, getEventDayResult(event), getDriverNameById)])), getDriverClub: (driverId) => state.drivers.find((driver) => driver.id === driverId)?.club || "", getDriverName: (driverId) => state.drivers.find((driver) => driver.id === driverId)?.name || "", classNames: new Map(state.classes.map((item) => [item.id, item.name])), @@ -642,6 +644,8 @@ const getSeriesRounds = (series) => state.events nextStep: getSeriesRoundNextStep(sessions), qualHeatCount: new Set(qualSessions.map((session) => String(session.name || "").split(" ").pop())).size, finalCount: sessions.filter((session) => session.type === "final").length, + calculatedResult: getEventDayResult(event), + manualResult: series.manualResults?.[event.id] || null, }; }); // Deleting a series can take its rounds along (races in another series are kept). @@ -1032,6 +1036,17 @@ const TRANSLATIONS = { "series.make_qualifying": "Skapa kval", "series.make_finals": "Skapa finaler", "series.open_race": "Öppna", + "series.result_button": "Resultat", + "series.result_title": "Rätta deltävlingens resultat", + "series.result_hint": "Sätt rätt slutordning för dagen, vinnaren först. Den ersätter appens uträkning i ställningen, t.ex. när kvalet blev fel. Förare som inte står med får inga poäng för deltävlingen.", + "series.result_up": "Flytta upp", + "series.result_down": "Flytta ned", + "series.result_remove": "Ta bort", + "series.result_add": "Lägg till förare", + "series.result_save": "Spara resultat", + "series.result_clear": "Använd appens resultat", + "series.result_clear_confirm": "Ta bort det rättade resultatet och räkna deltävlingen från heaten igen?", + "series.result_manual": "Rättat resultat", "series.remove_round": "Ta bort ur serien (racet finns kvar)", "series.remove_round_confirm": "Ta bort deltävlingen ur serien? Racet och dess resultat finns kvar.", "series.no_participants": "Välj minst en förare först (klicka på antalet förare).", @@ -1729,7 +1744,7 @@ const TRANSLATIONS = { "guide.series_day_3": "3. Ändra vid behov antal kval, finaler och max bilar per heat för just den deltävlingen - det kan skilja mellan deltävlingar och klasser.", "guide.series_day_4": "4. Knappen på raden visar nästa steg. Börja med ▶ Seedningsträning: den delar dagens förare i seedningsgrupper (max enligt kolumnen Max förare/seedgrupp, efter serieställningen - första deltävlingen i anmälningsordning), väljer första gruppen och öppnar Race Day - tryck Starta. Sedan ▶ Seedningsträning 2 osv. Grupperna delas om tills första gruppen startat, så efteranmälda kommer med.", "guide.series_day_5": "5. Skapa kval: heaten delas efter träningstiderna (lika snabba tillsammans, snabbaste heatet sist) och jämnt efter fältet (9 förare, max 6 -> 5 + 4). Sedan visar raden ▶ Kör Q1 H1, Q1 H2 ... och på Race Day väljer ▶ Nästa nästa heat. Reseeda kommande kval (i racet under Race Setup) delar om efter kvalrankingen.", - "guide.series_day_6": "6. När kvalet är klart: Skapa finaler, sedan ▶ Kör C Final 1, B Final 1, A Final 1, C Final 2 ... Status visar var deltävlingen är. Öppna tar dig till racet i Race Setup. Ställningen i steg 4 uppdateras av sig själv.", + "guide.series_day_6": "6. När kvalet är klart: Skapa finaler, sedan ▶ Kör C Final 1, B Final 1, A Final 1, C Final 2 ... Status visar var deltävlingen är. Öppna tar dig till racet i Race Setup. Ställningen i steg 4 uppdateras av sig själv. Blev något fel (t.ex. kvalet)? ✎ Resultat på raden sätter dagens slutordning för hand, och ställningen följer den.", "guide.series_points_title": "Poäng och ställning", "guide.series_points_1": "Dagens placering i en deltävling: slutresultatet (A-final före B-final), sedan förare utan final i kvalordning. Utan finaler används kvalordningen.", "guide.series_points_2": "Endast klubbmedlemmar: förare från andra klubbar kör och syns i dagens resultat men får inga poäng, och medlemmarna rangordnas om utan dem.", @@ -2916,6 +2931,17 @@ const TRANSLATIONS = { "series.make_qualifying": "Create qualifying", "series.make_finals": "Create finals", "series.open_race": "Open", + "series.result_button": "Result", + "series.result_title": "Correct the round's result", + "series.result_hint": "Set the right finishing order for the day, winner first. It replaces the calculated result in the standings, e.g. when the qualifying went wrong. Drivers not listed get no points for the round.", + "series.result_up": "Move up", + "series.result_down": "Move down", + "series.result_remove": "Remove", + "series.result_add": "Add driver", + "series.result_save": "Save result", + "series.result_clear": "Use the calculated result", + "series.result_clear_confirm": "Remove the corrected result and score the round from its heats again?", + "series.result_manual": "Corrected result", "series.remove_round": "Remove from the series (the race is kept)", "series.remove_round_confirm": "Remove the round from the series? The race and its results are kept.", "series.no_participants": "Pick at least one driver first (click the number of drivers).", @@ -3613,7 +3639,7 @@ const TRANSLATIONS = { "guide.series_day_3": "3. Change qualifying rounds, finals and max cars per heat for that round if needed - it can differ between rounds and classes.", "guide.series_day_4": "4. The button on the row shows the next step. Start with ▶ Seeding practice: it splits today's drivers into seeding groups (max per the Max drivers/seed group column, on the series standings - entry order in the first round), selects the first group and opens Race Day - press Start. Then ▶ Seeding practice 2 and so on. The groups are re-split until the first one has started, so late entries are included.", "guide.series_day_5": "5. Create qualifying: the heats are split on the practice times (equal pace together, fastest heat last) and evenly by the field (9 drivers, max 6 -> 5 + 4). The row then shows ▶ Run Q1 H1, Q1 H2 ... and on Race Day ▶ Next selects the next heat. Reseed upcoming qualifying (in the race under Race Setup) re-splits on the qualifying standings.", - "guide.series_day_6": "6. When qualifying is done: Create finals, then ▶ Run C Final 1, B Final 1, A Final 1, C Final 2 ... Status shows where the round is. Open goes to the race in Race Setup. The standings in step 4 update by themselves.", + "guide.series_day_6": "6. When qualifying is done: Create finals, then ▶ Run C Final 1, B Final 1, A Final 1, C Final 2 ... Status shows where the round is. Open goes to the race in Race Setup. The standings in step 4 update by themselves. Did something go wrong (e.g. the qualifying)? ✎ Result on the row sets the day's finishing order by hand, and the standings follow it.", "guide.series_points_title": "Points and standings", "guide.series_points_1": "A round's placing: the final standings (A final before B final), then drivers without a final in qualifying order. Without finals, the qualifying order is used.", "guide.series_points_2": "Members only: drivers from other clubs race and appear in the day result but get no points, and members are re-ranked without them.", diff --git a/src/series_logic.js b/src/series_logic.js index f3b7868..73d6fc8 100644 --- a/src/series_logic.js +++ b/src/series_logic.js @@ -49,9 +49,34 @@ export function normalizeSeries(series = {}, { uid } = {}) { countMode: series.countMode === "drop" ? "drop" : "best", countValue: clampInt(series.countValue, series.countMode === "drop" ? 0 : 9), createdAt: Number(series.createdAt) > 0 ? Number(series.createdAt) : Date.now(), + manualResults: normalizeManualResults(series.manualResults), }; } +// A round's result set by hand (eventId -> driver ids, winner first), e.g. when the +// qualifying went wrong and the club decided the order itself. +function normalizeManualResults(value) { + const out = {}; + if (!value || typeof value !== "object") return out; + Object.entries(value).forEach(([eventId, ids]) => { + const list = Array.isArray(ids) ? [...new Set(ids.map(String).filter(Boolean))] : []; + if (eventId && list.length) out[eventId] = list; + }); + return out; +} + +// The day result a round scores: the hand-set order when there is one, else the calculated. +export function getSeriesDayResult(series, eventId, calculated = [], getDriverName = () => "") { + const manual = series?.manualResults?.[eventId]; + if (!manual?.length) return calculated; + return manual.map((driverId) => ({ + driverId, + driverName: getDriverName(driverId) || calculated.find((row) => row.driverId === driverId)?.driverName || driverId, + hasLap: true, + manual: true, + })); +} + export function getSeriesPointsForPlace(series, place) { const table = series.pointsTable || []; if (!(place >= 1)) return 0; diff --git a/src/series_view.js b/src/series_view.js index 3bdcfbc..1b894c8 100644 --- a/src/series_view.js +++ b/src/series_view.js @@ -63,6 +63,33 @@ function renderSeriesForm(series, { t, escapeHtml, state }) { } let expandedRoundId = ""; +// The round whose result is being set by hand, and the order being edited (driver ids). +let resultRoundId = ""; +let resultDraft = []; + +function renderRoundResultEditor(round, { t, escapeHtml, state }) { + const name = (driverId) => state.drivers.find((driver) => driver.id === driverId)?.name + || round.calculatedResult.find((row) => row.driverId === driverId)?.driverName || driverId; + const others = round.classDrivers.filter((driver) => !resultDraft.includes(driver.id)); + return ` +
+ ${t("series.result_title")} +

${t("series.result_hint")}

+
    ${resultDraft.map((driverId, index) => ` +
  1. ${index + 1}${escapeHtml(name(driverId))} + + + + +
  2. `).join("")}
+ ${others.length ? `` : ""} +
+ + ${round.manualResult ? `` : ""} + +
+
`; +} function renderRoundParticipants(round, { t, escapeHtml }) { return ` @@ -105,7 +132,7 @@ function renderNextStep(round, { t, escapeHtml }) { return ""; } -function renderRoundsTable(rounds, { t, escapeHtml }) { +function renderRoundsTable(rounds, { t, escapeHtml, state }) { if (!rounds.length) return `

${t("series.no_rounds")}

`; const number = (round, name, value, min) => ``; return ` @@ -123,10 +150,11 @@ function renderRoundsTable(rounds, { t, escapeHtml }) { ${number(round, "finalLegs", config.finalLegs || 1, 1)} ${number(round, "carsPerHeat", config.carsPerHeat || 8, 2)} ${number(round, "seedGroupSize", config.seedGroupSize || 0, 0)} - ${t(`series.status_${round.status}`)}${round.qualHeatCount ? `
${t("series.heats_made", { heats: round.qualHeatCount })}` : ""} -
${action}
+ ${t(`series.status_${round.status}`)}${round.manualResult ? `
${t("series.result_manual")}` : ""}${round.qualHeatCount ? `
${t("series.heats_made", { heats: round.qualHeatCount })}` : ""} +
${action}
- ${expandedRoundId === round.event.id ? `${renderRoundParticipants(round, { t, escapeHtml })}` : ""}`; + ${expandedRoundId === round.event.id ? `${renderRoundParticipants(round, { t, escapeHtml })}` : ""} + ${resultRoundId === round.event.id ? `${renderRoundResultEditor(round, { t, escapeHtml, state })}` : ""}`; }).join("")} `; } @@ -200,7 +228,7 @@ export function renderSeriesView(deps) {
${series.classIds.length ? "" : `

${t("series.pick_classes_first")}

`} -
${renderRoundsTable(rounds, { t, escapeHtml })}
+
${renderRoundsTable(rounds, { t, escapeHtml, state })}
${renderAddExistingRace(series, rounds, { t, escapeHtml, state, getClassName })} @@ -313,6 +341,13 @@ export function renderSeriesView(deps) { row.querySelectorAll("[data-round-action]").forEach((button) => button.addEventListener("click", () => { const action = button.dataset.roundAction; if (action === "toggle") expandedRoundId = expandedRoundId === eventId ? "" : eventId; + if (action === "result") { + // Starts from the hand-set order, else the calculated one, else the entry list. + const round = rounds.find((item) => item.event.id === eventId); + resultRoundId = resultRoundId === eventId ? "" : eventId; + resultDraft = [...(round?.manualResult || round?.calculatedResult.map((row) => row.driverId) || [])]; + if (!resultDraft.length) resultDraft = [...(round?.participantIds || [])]; + } if (action === "open") { openSeriesRound(eventId); return; } if (action === "run") { runSeriesSession(button.dataset.roundSession); return; } if (action === "seeding") { runSeriesSeeding(eventId); return; } @@ -326,6 +361,34 @@ export function renderSeriesView(deps) { renderView(); })); }); + const resultEditor = dom.view.querySelector("[data-round-result]"); + if (resultEditor) { + const eventId = resultEditor.dataset.roundResult; + resultEditor.querySelectorAll("[data-result-move]").forEach((button) => button.addEventListener("click", () => { + const index = resultDraft.indexOf(button.closest("[data-result-driver]").dataset.resultDriver); + const move = button.dataset.resultMove; + if (move === "remove") resultDraft.splice(index, 1); + const other = move === "up" ? index - 1 : move === "down" ? index + 1 : -1; + if (other >= 0 && other < resultDraft.length) [resultDraft[index], resultDraft[other]] = [resultDraft[other], resultDraft[index]]; + renderView(); + })); + resultEditor.querySelector("[data-result-add]")?.addEventListener("change", (event) => { + if (event.target.value) resultDraft.push(event.target.value); + renderView(); + }); + resultEditor.querySelectorAll("[data-result-action]").forEach((button) => button.addEventListener("click", () => { + const action = button.dataset.resultAction; + if (action === "save") series.manualResults = { ...(series.manualResults || {}), [eventId]: [...resultDraft] }; + if (action === "clear") { + if (!window.confirm(t("series.result_clear_confirm"))) return; + const { [eventId]: _removed, ...rest } = series.manualResults || {}; + series.manualResults = rest; + } + if (action !== "cancel") saveState(); + resultRoundId = ""; + renderView(); + })); + } const detail = dom.view.querySelector("[data-round-participants]"); if (detail) { const eventId = detail.dataset.roundParticipants; diff --git a/src/styles.css b/src/styles.css index 207ac39..a175fee 100644 --- a/src/styles.css +++ b/src/styles.css @@ -4755,3 +4755,11 @@ tr.is-removed td.lap-actions { .race-day-live-table { font-size: 1rem; } .race-day-live-table th:nth-child(7), .race-day-live-table td:nth-child(7) { display: none; } } + +/* Series: a round's result set by hand */ +.series-result-pill { background: rgba(245, 166, 35, 0.15); color: var(--warn); } +.series-round-result { display: grid; gap: 8px; } +.series-result-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; max-width: 520px; } +.series-result-list li { display: grid; grid-template-columns: 2em 1fr auto; align-items: center; gap: 8px; padding: 4px 8px; border: 1px solid var(--line); border-radius: 6px; } +.series-result-place { font-weight: 800; } +.series-result-add { display: flex; gap: 8px; align-items: center; max-width: 520px; } diff --git a/tests/browser_series.js b/tests/browser_series.js index 64604ee..6ee1d28 100644 --- a/tests/browser_series.js +++ b/tests/browser_series.js @@ -140,6 +140,26 @@ export async function runSeriesSmoke({ evaluate, navigate, savedState, waitFor, assert.deepEqual(rows, [["1", "SR Anna", "100", "", "1", "100"], ["2", "SR Bo", "90", "", "1", "90"]], "the guest races but doesn't score; Anna is re-ranked 1st; round 2 is empty"); console.log("PASS standings: only club drivers score, re-ranked without guests; unplayed rounds stay empty"); + // The club corrects round 1 by hand (the qualifying went wrong): Bo is moved up to win. + await inRound(round1.id, `row.querySelector('[data-round-action="result"]').click();`); + await waitFor(async () => Boolean(await evaluate(`document.querySelector("[data-round-result]")`)), "result editor open"); + const editorOrder = async () => evaluate(`[...document.querySelectorAll("[data-result-driver]")].map((item) => item.dataset.resultDriver)`); + assert.deepEqual(await editorOrder(), ["sr_guest", "sr_anna", "sr_bo"], "starts from the calculated result"); + await evaluate(`document.querySelector('[data-result-driver="sr_bo"] [data-result-move="up"]').click()`); + await waitFor(async () => (await editorOrder()).join() === "sr_guest,sr_bo,sr_anna", "moved up"); + await evaluate(`document.querySelector('[data-result-driver="sr_bo"] [data-result-move="up"]').click()`); + await waitFor(async () => (await editorOrder()).join() === "sr_bo,sr_guest,sr_anna", "moved to the top"); + await evaluate(`document.querySelector('[data-result-action="save"]').click()`); + await waitFor(async () => (await savedState()).series.find((item) => item.id === saved.id)?.manualResults?.[round1.id]?.join() === "sr_bo,sr_guest,sr_anna", "saved on the series"); + await waitFor(async () => (await evaluate(`[...document.querySelectorAll('[data-series-class="sr_2wd"] tbody tr')].map((tr) => tr.children[1].textContent.trim()).join()`)) === "SR Bo,SR Anna", "the standings follow the corrected order"); + assert.ok((await inRound(round1.id, `return row.textContent;`)).includes("Corrected result"), "the round is marked as corrected"); + // Back to the calculated result. + await inRound(round1.id, `row.querySelector('[data-round-action="result"]').click();`); + await waitFor(async () => Boolean(await evaluate(`document.querySelector('[data-result-action="clear"]')`)), "clear offered"); + await evaluate(`document.querySelector('[data-result-action="clear"]').click()`); + await waitFor(async () => !(await savedState()).series.find((item) => item.id === saved.id)?.manualResults?.[round1.id], "the corrected result is removed"); + console.log("PASS a round's result can be corrected by hand and the standings follow it"); + // Switch the same series to "every driver": the guest now scores and wins round 1. await evaluate(`(() => { const form = document.getElementById("seriesForm"); form.elements.scoring.value = "all"; form.elements.scoring.dispatchEvent(new Event("change")); form.requestSubmit(); })()`); await waitFor(async () => (await savedState()).series.find((series) => series.id === saved.id)?.scoring === "all", "open series saved"); diff --git a/tests/series_next_step.test.js b/tests/series_next_step.test.js index ed8c92d..f70cf65 100644 --- a/tests/series_next_step.test.js +++ b/tests/series_next_step.test.js @@ -42,3 +42,13 @@ test("seeding groups: even split by max size, top of the standings last with fas const fifty = Array.from({ length: 50 }, (_, index) => `x${index}`); assert.deepEqual(planSeedingGroups(fifty, 6, "fastest_first").map((group) => group.length), [6, 6, 6, 6, 6, 5, 5, 5, 5]); }); + +test("a round's hand-set result replaces the calculated one in the standings", async () => { + const { normalizeSeries, getSeriesDayResult } = await import("../src/series_logic.js"); + const series = normalizeSeries({ id: "s", manualResults: { e1: ["roy", "wilmer", "roy", ""], e2: [] } }); + assert.deepEqual(series.manualResults, { e1: ["roy", "wilmer"] }, "duplicates and empty lists are dropped"); + const calculated = [{ driverId: "patrik", driverName: "Patrik", hasLap: true }, { driverId: "roy", driverName: "Roy", hasLap: true }]; + const names = { roy: "Roy Gjemble", wilmer: "Wilmer Nilsson" }; + assert.deepEqual(getSeriesDayResult(series, "e1", calculated, (id) => names[id]).map((row) => row.driverName), ["Roy Gjemble", "Wilmer Nilsson"]); + assert.equal(getSeriesDayResult(series, "e2", calculated), calculated, "no hand-set order: the calculated result"); +});