diff --git a/CHANGELOG.md b/CHANGELOG.md index aef21ad..9528092 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.57.1 - 2026-11-03 + +### Fixed + +- Results: when two drivers have the same number of laps, the lower total time now wins (EFRA/IFMAR). A finished heat used to rank the time closest to the set time first, so 10 laps in 4:52 beat 10 laps in 4:51. Heats already run are re-ranked on the fly. + ## 1.57.0 - 2026-11-03 ### Changed diff --git a/package-lock.json b/package-lock.json index 9d7fe30..785c751 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "rc-racecore", - "version": "1.57.0", + "version": "1.57.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "rc-racecore", - "version": "1.57.0", + "version": "1.57.1", "hasInstallScript": true, "dependencies": { "better-sqlite3": "^12.11.1", diff --git a/package.json b/package.json index 5980d61..c13c845 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rc-racecore", - "version": "1.57.0", + "version": "1.57.1", "private": true, "description": "RC RaceCore live timing and race control with AMMC ingest and SQLite persistence", "engines": { diff --git a/src/timing_logic.js b/src/timing_logic.js index 1b73247..4c024a8 100644 --- a/src/timing_logic.js +++ b/src/timing_logic.js @@ -197,7 +197,6 @@ export function buildLeaderboard(session, { ensureSessionResult, getSessionTarge const result = ensureSessionResult(session.id); const sessionType = String(session.type || "").toLowerCase(); const targetMs = getSessionTargetMs(session); - const useTargetTieBreak = session.status === "finished"; const useSeedRanking = ["practice", "qualification"].includes(sessionType) && Number(session.seedBestLapCount || 0) > 0; const isFreePractice = sessionType === "free_practice"; const isOpenPractice = sessionType === "open_practice"; @@ -330,9 +329,7 @@ export function buildLeaderboard(session, { ensureSessionResult, getSessionTarge if (b.laps !== a.laps) { return b.laps - a.laps; } - if (useTargetTieBreak && a.distanceToTargetMs !== b.distanceToTargetMs) { - return a.distanceToTargetMs - b.distanceToTargetMs; - } + // Same laps: the lower total time wins (EFRA/IFMAR) - also when it is further from the set time. return a.totalElapsedMs - b.totalElapsedMs; }); @@ -343,11 +340,10 @@ export function buildLeaderboard(session, { ensureSessionResult, getSessionTarge } return { ...row, - gap: formatLeaderboardGap(row, leader, { useSeedRanking, useTargetTieBreak, isFreePractice: isRollingPractice }), - leaderGap: formatLeaderboardGap(row, leader, { useSeedRanking, useTargetTieBreak, isFreePractice: isRollingPractice }), + gap: formatLeaderboardGap(row, leader, { useSeedRanking, isFreePractice: isRollingPractice }), + leaderGap: formatLeaderboardGap(row, leader, { useSeedRanking, isFreePractice: isRollingPractice }), gapAhead: formatLeaderboardGap(row, rows[index - 1], { useSeedRanking, - useTargetTieBreak, isFreePractice: isRollingPractice, selfLabel: t("status.leader"), }), @@ -395,9 +391,7 @@ export function formatLeaderboardGap(row, referenceRow, options = {}, { t }) { if (lapDiff > 0) { return `+${lapDiff}L`; } - const referenceValue = options.useTargetTieBreak ? referenceRow.distanceToTargetMs : referenceRow.totalElapsedMs; - const rowValue = options.useTargetTieBreak ? row.distanceToTargetMs : row.totalElapsedMs; - const timeGap = Math.max(0, rowValue - referenceValue); + const timeGap = Math.max(0, (row.totalElapsedMs || 0) - (referenceRow.totalElapsedMs || 0)); return `+${(timeGap / 1000).toFixed(3)}s`; } diff --git a/tests/race_timing_logic.test.js b/tests/race_timing_logic.test.js index f51f271..cd06f17 100644 --- a/tests/race_timing_logic.test.js +++ b/tests/race_timing_logic.test.js @@ -813,9 +813,9 @@ test("points tables, tie comparison, and leaderboard gaps remain deterministic", assert.equal(formatLeaderboardGap({ key: "second", laps: 16, totalElapsedMs: 290000 }, leader, {}, { t }), "+1L"); assert.equal( formatLeaderboardGap( - { key: "second", laps: 17, totalElapsedMs: 306000, distanceToTargetMs: 6000 }, + { key: "second", laps: 17, totalElapsedMs: 306000 }, leader, - { useTargetTieBreak: true }, + {}, { t } ), "+5.000s" @@ -1082,3 +1082,33 @@ test("ensureSessionResult backfills a missing passings array on an already-exist const brandNew = ensureSessionResult("session_2", { state }); assert.deepEqual(brandNew, { passings: [], splits: [], pitEvents: [], pitStops: [], competitors: {}, adjustments: [] }); }); + +// Race report: a finished heat, two cars on 10 laps - 4:51 must beat 4:52, even though 4:52 +// is closer to the 5:00 set time. +test("buildLeaderboard: same laps in a finished heat - the lower total time wins", () => { + const start = 1_000_000; + const competitors = { + slow: { key: "slow", driverName: "Slow", startTimestamp: start, laps: 10, lastTimestamp: start + 292000, manualLapAdjustment: 0, manualTimeAdjustmentMs: 0 }, + fast: { key: "fast", driverName: "Fast", startTimestamp: start, laps: 10, lastTimestamp: start + 291000, manualLapAdjustment: 0, manualTimeAdjustmentMs: 0 }, + }; + for (const type of ["qualification", "final"]) { + const rows = buildLeaderboard({ id: "h", type, startMode: "position", status: "finished", startedAt: start, durationMin: 5, totalPausedMs: 0 }, { + ensureSessionResult: () => ({ competitors }), + getSessionTargetMs: (s) => getSessionTargetMs(s, { isUntimedSession }), + getCompetitorPassings: () => [], + isCountedPassing: () => true, + getCompetitorElapsedMs, + getCompetitorSeedMetric: () => null, + getSessionLapWindow: () => ({ minLapMs: 0, maxLapMs: Infinity }), + getPassingValidationLabel: () => "", + formatSeedMetric: () => "", + formatRaceClock: (ms) => `${ms}`, + formatLeaderboardGap: (row, ref, options) => formatLeaderboardGap(row, ref, options, { t: (key) => key }), + formatLapDelta: () => "", + formatLap: (ms) => `${ms}`, + t: (key) => key, + }); + assert.deepEqual(rows.map((row) => row.key), ["fast", "slow"], type); + assert.equal(rows[1].gap, "+1.000s"); + } +});