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>
20 lines
1.3 KiB
JavaScript
20 lines
1.3 KiB
JavaScript
// Open Practice "personal best" calls. On a fresh pack every driver beats their own best almost
|
||
// every lap for the first laps of the day (the results start empty after a new practice or
|
||
// "Reset – new practice day"), so with a few drivers on track the speaker never stops. The
|
||
// rules below only decide what is *called*; the best lap itself is still shown everywhere.
|
||
// - warm-up: nothing for a driver's first N laps of the day,
|
||
// - cooldown: at most one call per driver per N seconds,
|
||
// - minimum gain: after a call, the next one needs a best that beats the *called* time by this
|
||
// much, so a run of tiny improvements is called once they add up. The first personal best
|
||
// after the warm-up is always called.
|
||
// Each rule is off at 0.
|
||
export const PRACTICE_PB_DEFAULTS = Object.freeze({ warmupLaps: 10, cooldownSec: 60, minGainMs: 100 });
|
||
|
||
export function shouldCallPracticePersonalBest({ lapNumber, lapMs, previousBestMs, lastCall = null, now, rules = PRACTICE_PB_DEFAULTS }) {
|
||
if (!previousBestMs || !(lapMs < previousBestMs)) return false;
|
||
if (rules.warmupLaps && lapNumber <= rules.warmupLaps) return false;
|
||
if (!lastCall) return true;
|
||
if (rules.cooldownSec && now - lastCall.at < rules.cooldownSec * 1000) return false;
|
||
return lastCall.lapMs - lapMs >= rules.minGainMs;
|
||
}
|