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:
1 parent
633e0efa1f
commit
cade201d5a
10 files changed
+135
-2
No files matched your search
@@ -57,6 +57,15 @@ export async function runSettingsTabsSmoke({ evaluate, navigate, waitFor, savedS
|
||||
assert.equal(await callouts(), "passing");
|
||||
console.log("PASS the legacy audio panel is gone and race calls default to passing tone only");
|
||||
|
||||
// Open Practice personal best calls: 10 warm-up laps, 60 s, 0.1 s by default, and they save.
|
||||
const pbFields = () => evaluate(`["raceAudioPbWarmup", "raceAudioPbCooldown", "raceAudioPbMinGain"].map((name) => document.querySelector('[name="' + name + '"]').value).join("|")`);
|
||||
assert.equal(await pbFields(), "10|60|0.1");
|
||||
await evaluate(`(() => { document.querySelector('[name="raceAudioPbWarmup"]').value = "5"; document.querySelector('[name="raceAudioPbCooldown"]').value = "120"; document.querySelector('[name="raceAudioPbMinGain"]').value = "0.25"; document.getElementById("settingsForm").requestSubmit(); })()`);
|
||||
await waitFor(async () => { const audio = (await savedState()).settings.raceAudio; return audio.practicePbWarmupLaps === 5 && audio.practicePbCooldownSec === 120 && audio.practicePbMinGainMs === 250; }, "practice personal best rules saved");
|
||||
assert.equal(await pbFields(), "5|120|0.25");
|
||||
await evaluate(`(() => { document.querySelector('[name="raceAudioPbWarmup"]').value = "10"; document.querySelector('[name="raceAudioPbCooldown"]').value = "60"; document.querySelector('[name="raceAudioPbMinGain"]').value = "0.1"; document.getElementById("settingsForm").requestSubmit(); })()`);
|
||||
console.log("PASS the practice personal best call rules default to 10 laps / 60 s / 0.1 s and are saved");
|
||||
|
||||
// The sidebar "update available" link opens Settings on System & backup at Updates, even
|
||||
// when another tab was the last one used.
|
||||
await evaluate(`document.querySelector('[data-settings-tab="connection"]').click()`);
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { shouldCallPracticePersonalBest, PRACTICE_PB_DEFAULTS } from "../src/practice_callouts_logic.js";
|
||||
import { normalizeRaceAudioSettings } from "../src/race_audio.js";
|
||||
|
||||
// Run a driver's laps (lapMs at 20 s intervals) through the rules and return the called laps.
|
||||
function calledLaps(laps, rules = PRACTICE_PB_DEFAULTS) {
|
||||
let best = null;
|
||||
let lastCall = null;
|
||||
const called = [];
|
||||
laps.forEach((lapMs, index) => {
|
||||
const now = (index + 1) * 20000;
|
||||
if (shouldCallPracticePersonalBest({ lapNumber: index + 1, lapMs, previousBestMs: best, lastCall, now, rules })) {
|
||||
lastCall = { at: now, lapMs };
|
||||
called.push(index + 1);
|
||||
}
|
||||
if (!best || lapMs < best) best = lapMs;
|
||||
});
|
||||
return called;
|
||||
}
|
||||
|
||||
test("fresh pack: no personal best calls during the first ten laps of the day", () => {
|
||||
const laps = [24000, 23000, 22500, 22000, 21600, 21300, 21000, 20800, 20600, 20500];
|
||||
assert.deepEqual(calledLaps(laps), []);
|
||||
assert.equal(calledLaps(laps, { warmupLaps: 0, cooldownSec: 0, minGainMs: 0 }).length, 9, "without the rules every lap is a call");
|
||||
});
|
||||
|
||||
test("after the warm-up a real improvement is called, then at most once a minute per driver", () => {
|
||||
const laps = [...Array(10).fill(21000), 20500, 20300, 20100, 21000];
|
||||
// Lap 11 is called; laps 12-13 (20 and 40 s later) fall inside the cooldown.
|
||||
assert.deepEqual(calledLaps(laps), [11]);
|
||||
const later = [...Array(10).fill(21000), 20500, 21000, 21000, 21000, 20300];
|
||||
assert.deepEqual(calledLaps(later), [11, 15], "a better lap after the minute is called again");
|
||||
});
|
||||
|
||||
test("tiny improvements are called once they add up to the minimum gain", () => {
|
||||
const rules = { warmupLaps: 0, cooldownSec: 0, minGainMs: 100 };
|
||||
// 19.95 is the first best (called); 19.88 is only 0.07 better than that; 19.84 adds up to 0.11.
|
||||
assert.deepEqual(calledLaps([20000, 19950, 19880, 19840, 19770], rules), [2, 4]);
|
||||
});
|
||||
|
||||
test("a lap that is not a best is never called", () => {
|
||||
assert.equal(shouldCallPracticePersonalBest({ lapNumber: 20, lapMs: 20000, previousBestMs: 19000, now: 0, rules: { warmupLaps: 0, cooldownSec: 0, minGainMs: 0 } }), false);
|
||||
assert.equal(shouldCallPracticePersonalBest({ lapNumber: 20, lapMs: 20000, previousBestMs: null, now: 0 }), false, "the first timed lap is no personal best");
|
||||
});
|
||||
|
||||
test("the settings default to 10 laps, 60 s and 0.1 s and clamp what is typed", () => {
|
||||
const defaults = normalizeRaceAudioSettings({});
|
||||
assert.deepEqual([defaults.practicePbWarmupLaps, defaults.practicePbCooldownSec, defaults.practicePbMinGainMs], [10, 60, 100]);
|
||||
const typed = normalizeRaceAudioSettings({ practicePbWarmupLaps: 99, practicePbCooldownSec: -5, practicePbMinGainMs: 0 });
|
||||
assert.deepEqual([typed.practicePbWarmupLaps, typed.practicePbCooldownSec, typed.practicePbMinGainMs], [30, 0, 0]);
|
||||
});
|
||||
@@ -1,4 +1,5 @@
|
||||
import "./auth.test.js";
|
||||
import "./practice_callouts_logic.test.js";
|
||||
import "./local_cache.test.js";
|
||||
import "./prologue_logic.test.js";
|
||||
import "./suspect_laps_logic.test.js";
|
||||
|
||||
Reference in new issue
Block a user