From 6142bceca9cf327dd037c417bf8ce05fd5dbf77a Mon Sep 17 00:00:00 2001 From: larssand Date: Sun, 1 Nov 2026 19:03:25 +0100 Subject: [PATCH] fix(archive): name the winner from the session result, not the raw lap count (1.47.1) --- CHANGELOG.md | 6 ++++++ package-lock.json | 4 ++-- package.json | 2 +- src/results_archive_view.js | 10 +++++----- tests/race_day_live.test.js | 15 +++++++++++++++ 5 files changed, 29 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5189c8d..1428766 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,12 @@ The application version is maintained in `package.json` and displayed in the adm No changes recorded yet. +## 1.47.1 - 2026-11-01 + +### Fixed + +- The Winner column in the results archive could name the wrong driver: with equal laps it named whoever crossed the line first after the start, not who finished first. It now uses the session's result, the same as Show and the series standings. + ## 1.47.0 - 2026-11-01 ### Added diff --git a/package-lock.json b/package-lock.json index 07baa0d..80e6283 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "rc-racecore", - "version": "1.47.0", + "version": "1.47.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "rc-racecore", - "version": "1.47.0", + "version": "1.47.1", "hasInstallScript": true, "dependencies": { "better-sqlite3": "^12.11.1", diff --git a/package.json b/package.json index e57379c..89fe210 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rc-racecore", - "version": "1.47.0", + "version": "1.47.1", "private": true, "description": "RC RaceCore live timing and race control with AMMC ingest and SQLite persistence", "engines": { diff --git a/src/results_archive_view.js b/src/results_archive_view.js index 3258256..7b99ab0 100644 --- a/src/results_archive_view.js +++ b/src/results_archive_view.js @@ -1,15 +1,15 @@ import { sortableTable, sortValuesAttribute } from "./list_sorting.js"; -function buildArchiveRows(state, { getEventName, getClassName, getTrackLayoutLabel }) { +export function buildArchiveRows(state, { getEventName, getClassName, getTrackLayoutLabel, buildLeaderboard }) { return (state.sessions || []) .filter((session) => session.status === "finished") .map((session) => { const event = state.events.find((item) => item.id === session.eventId) || null; const result = state.resultsBySession?.[session.id] || null; const competitors = result ? Object.values(result.competitors || {}) : []; - const winner = competitors - .slice() - .sort((left, right) => (Number(right.laps || 0) - Number(left.laps || 0)) || (Number(left.totalElapsedMs || 0) - Number(right.totalElapsedMs || 0)))[0] || null; + // The same order as the session's result (laps, then time, penalties, seeding). The raw + // laps alone named whoever crossed the line first when laps were equal. + const winner = result ? buildLeaderboard(session)[0] || null : null; return { session, event, @@ -121,7 +121,7 @@ export function renderResultsArchiveView(deps) { } = deps; const filters = getArchiveFilters(); - const allRows = buildArchiveRows(state, { getEventName, getClassName, getTrackLayoutLabel }); + const allRows = buildArchiveRows(state, { getEventName, getClassName, getTrackLayoutLabel, buildLeaderboard }); const filteredRows = allRows.filter((row) => matchesArchiveFilters(row, filters)); const selectedSessionId = getSelectedSessionId(); const selectedRow = selectedSessionId ? allRows.find((row) => row.session.id === selectedSessionId) : null; diff --git a/tests/race_day_live.test.js b/tests/race_day_live.test.js index 2867413..bd69445 100644 --- a/tests/race_day_live.test.js +++ b/tests/race_day_live.test.js @@ -12,3 +12,18 @@ test("estimated finish: laps and time when a 5-minute heat is up, at the car's r assert.equal(estimateFinish({ laps: 0, totalElapsedMs: 0 }, 300000), null, "no lap yet"); assert.equal(estimateFinish({ laps: 5, totalElapsedMs: 90000 }, null), null, "untimed session"); }); + +test("results archive: the winner is the session's result order, not who has a lap stored first", async () => { + const { buildArchiveRows } = await import("../src/results_archive_view.js"); + const state = { + sessions: [{ id: "a1", eventId: "e1", name: "A final 1", status: "finished", endedAt: 1 }], + events: [{ id: "e1", classId: "c1", date: "2026-11-01" }], + resultsBySession: { a1: { competitors: { first_over_line: { driverName: "Crossed first", laps: 14 }, winner: { driverName: "Finished first", laps: 14 } } } }, + trackLayouts: [], + }; + const rows = buildArchiveRows(state, { + getEventName: () => "Race", getClassName: () => "2WD", getTrackLayoutLabel: () => "", + buildLeaderboard: () => [{ driverName: "Finished first" }, { driverName: "Crossed first" }], + }); + assert.equal(rows[0].winnerName, "Finished first"); +});