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

+18 -1
View File
@@ -27,6 +27,7 @@ function createHarness(options = {}) {
],
cars: [],
resultsBySession: {},
...(options.raceAudio ? { settings: { raceAudio: options.raceAudio } } : {}),
};
let saveCount = 0;
const overlayEvents = [];
@@ -137,7 +138,8 @@ test("flying start: a car first seen after the latest clock start gets that cloc
});
test("personal best is per session and track layout - not per stint, and an old layout's time doesn't count", () => {
const harness = createHarness({ sessionType: "open_practice" });
// The practice call rules (warm-up, cooldown) are tested on their own below.
const harness = createHarness({ sessionType: "open_practice", raceAudio: { practicePbWarmupLaps: 0, practicePbCooldownSec: 0, practicePbMinGainMs: 0 } });
harness.session.trackLayoutId = "layout_a";
const entry = () => Object.values(harness.state.resultsBySession.session_1.competitors)[0];
const pbs = () => harness.audioEvents.filter((event) => event === "personal_best").length;
@@ -157,6 +159,21 @@ test("personal best is per session and track layout - not per stint, and an old
assert.equal(harness.state.resultsBySession.session_1.passings.at(-1).trackLayoutId, "layout_b", "each lap remembers its layout");
});
test("practice on a fresh pack: no personal best calls for the first ten laps, then one a minute", () => {
const harness = createHarness({ sessionType: "open_practice" });
const pbs = () => harness.audioEvents.filter((event) => event === "personal_best").length;
let ts = 1_000;
// Every lap 0.3 s quicker than the one before: a personal best each lap.
for (let lap = 0; lap < 10; lap += 1) { ts += 25_000 - lap * 300; harness.passing(ts, "main"); }
assert.equal(Object.values(harness.state.resultsBySession.session_1.competitors)[0].laps, 10);
assert.equal(pbs(), 0, "laps 1-10 are warm-up");
ts += 21_000; harness.passing(ts, "main"); // lap 11
assert.equal(pbs(), 1, "the first best after the warm-up is called");
ts += 20_500; harness.passing(ts, "main");
assert.equal(pbs(), 1, "the next best 20 s later is inside the cooldown");
assert.equal(Object.values(harness.state.resultsBySession.session_1.competitors)[0].bestLapMs, 20_500, "but it is still the best lap");
});
test("practice: a shortcut lap is flagged suspect - counted, but no best lap, personal best or record", () => {
const harness = createHarness({ sessionType: "open_practice" });
const entry = () => Object.values(harness.state.resultsBySession.session_1.competitors)[0];