// 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; }