fix(lap): keep best laps per track layout and count the current session for records

A layout switch during a running open practice kept every driver's
old-layout best lap, blocking personal-best calls and skewing the
practice leaderboard. Best laps now restart on a new layout and each
lap records its layout. The track record baseline now includes the
current session so the same record isn't called twice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
larssandandClaude Opus 5.5 committed 2026-10-03 21:14:19 +02:00
1 parent ebd0f74f40
commit 8b63dd2372
12 files changed
+125 -8

No files matched your search

+3 -2
View File
@@ -165,9 +165,10 @@ export function ensureSessionResult(sessionId, { state }) {
export function getTrackRecordMs(session, { state }) {
const event = state.events.find((item) => item.id === session?.eventId);
if (!event?.classId) return null;
// The current session counts too: once someone beats the old record in this session, the
// next driver must beat that new time - not the old record again - to be called a record.
const candidates = state.sessions.filter((item) =>
item.id !== session?.id
&& String(item.trackLayoutId || "") === String(session?.trackLayoutId || "")
String(item.trackLayoutId || "") === String(session?.trackLayoutId || "")
&& state.events.find((race) => race.id === item.eventId)?.classId === event.classId);
const values = candidates
.flatMap((item) => Object.values(state.resultsBySession[item.id]?.competitors || {}).map((row) => Number(row.bestLapMs || 0)))