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

+8
View File
@@ -337,6 +337,7 @@ export function processDecoderMessageHelper(msg, deps, decoderRole = "main") {
laps: 0,
lastLapMs: null,
bestLapMs: null,
bestLapLayoutId: String(session.trackLayoutId || ""),
startTimestamp: null,
lastTimestamp: null,
};
@@ -494,6 +495,7 @@ export function processDecoderMessageHelper(msg, deps, decoderRole = "main") {
stintBoundary: validationWarning === "above_max_stint",
strength: msg.strength,
loopId: String(msg.loop_id || ""),
trackLayoutId: String(session.trackLayoutId || ""),
resend: Boolean(msg.resend),
};
@@ -505,6 +507,12 @@ export function processDecoderMessageHelper(msg, deps, decoderRole = "main") {
return true;
}
// Best laps are per track layout: an open practice that runs all season moves onto a new
// layout when one is added (addTrackLayout resets every best lap then), and this catches a
// layout change made elsewhere. Entries from before this field existed adopt the current one.
const layoutId = String(session.trackLayoutId || "");
if (entry.bestLapLayoutId === undefined) entry.bestLapLayoutId = layoutId;
else if (entry.bestLapLayoutId !== layoutId) { entry.bestLapMs = null; entry.bestLapLayoutId = layoutId; }
const previousPersonalBest = Number(entry.bestLapMs || 0) || null;
const leaderboardBefore = buildLeaderboard(session);
const previousPosition = leaderboardBefore.findIndex((row) => row.key === key);