feat(audio): fewer personal best calls in Open Practice

On fresh packs every driver beats their best almost every lap early in
the day. No call for a driver's first 10 laps since the practice started
or was reset, at most one per driver a minute, and 0.1 s over the last
called time. Adjustable under Settings → Audio; 0 turns a rule off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
larssandandClaude Opus 5.5 committed 2026-10-19 15:40:24 +02:00
1 parent 633e0efa1f
commit cade201d5a
10 files changed
+135 -2

No files matched your search

+16 -1
View File
@@ -2,8 +2,12 @@ import { decoderDiagnostics } from "./decoder_diagnostics.js";
import { getControlledLapStreak } from "./training_logic.js";
import { usesPersonalClock, getLatestClockStartTs } from "./prologue_logic.js";
import { isSuspectLap, getSuspectReferenceLaps } from "./suspect_laps_logic.js";
import { shouldCallPracticePersonalBest } from "./practice_callouts_logic.js";
import { normalizeRaceAudioSettings } from "./race_audio.js";
const PRACTICE_SESSION_TYPES = new Set(["open_practice", "free_practice", "practice"]);
// Last personal best *called* per driver, per practice day and layout (practice_callouts_logic.js).
const lastPracticePbCall = new Map();
function getCurrentPracticePaceLaps(result, competitorKey) {
const laps = [];
@@ -271,6 +275,11 @@ export function disconnectDecoderHelper(options = {}, deps) {
updateConnectionBadge();
}
function getPracticePbRules(state) {
const audio = normalizeRaceAudioSettings(state.settings?.raceAudio);
return { warmupLaps: audio.practicePbWarmupLaps, cooldownSec: audio.practicePbCooldownSec, minGainMs: audio.practicePbMinGainMs };
}
export function processDecoderMessageHelper(msg, deps, decoderRole = "main") {
const {
state, t, getActiveSession, ensureSessionResult, normalizeStartMode, getSessionLapWindow,
@@ -555,7 +564,13 @@ export function processDecoderMessageHelper(msg, deps, decoderRole = "main") {
}
}
if (suspect) pushOverlayEvent("suspect", `${entry.displayName || entry.driverName} • ${formatLap(lapMs)} ⚠`);
if (!suspect && previousPersonalBest && lapMs < previousPersonalBest) triggerRaceAudio("personal_best", { variables: audioVariables, driverId: entry.driverId, competitorKey: key, logData: { raceId: session.eventId, driverId: entry.driverId, lapNumber: entry.laps, lapTime: lapMs } });
const isPracticeSession = PRACTICE_SESSION_TYPES.has(String(session.type || "").toLowerCase());
const pbCallKey = `${session.id}:${Number(session.resultsResetAt || 0)}:${layoutId}:${key}`;
const callPersonalBest = !suspect && (isPracticeSession
? shouldCallPracticePersonalBest({ lapNumber: entry.laps, lapMs, previousBestMs: previousPersonalBest, lastCall: lastPracticePbCall.get(pbCallKey), now: Date.now(), rules: getPracticePbRules(state) })
: Boolean(previousPersonalBest && lapMs < previousPersonalBest));
if (callPersonalBest && isPracticeSession) lastPracticePbCall.set(pbCallKey, { at: Date.now(), lapMs });
if (callPersonalBest) triggerRaceAudio("personal_best", { variables: audioVariables, driverId: entry.driverId, competitorKey: key, logData: { raceId: session.eventId, driverId: entry.driverId, lapNumber: entry.laps, lapTime: lapMs } });
if (!suspect && previousSessionFastest && lapMs < previousSessionFastest) triggerRaceAudio("fastest_lap", { variables: audioVariables, driverId: entry.driverId, competitorKey: key, logData: { raceId: session.eventId, driverId: entry.driverId, lapNumber: entry.laps, lapTime: lapMs } });
if (!suspect && previousTrackRecord && lapMs < previousTrackRecord) triggerRaceAudio("track_record", { variables: audioVariables, driverId: entry.driverId, competitorKey: key, logData: { raceId: session.eventId, driverId: entry.driverId, lapNumber: entry.laps, lapTime: lapMs } });
if (previousPosition >= 0 && currentPosition >= 0 && currentPosition < previousPosition) triggerRaceAudio("position_gain", { driverId: entry.driverId, competitorKey: key });