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
@@ -8,6 +8,8 @@ The application version is maintained in `package.json` and displayed in the adm
|
|||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
- **Fewer personal best calls in Open Practice.** On fresh packs everyone beats their own best almost every lap early in the day, so the speaker never stopped. Now: no personal best call for a driver's first 10 laps of the day (since the practice started or was reset), at most one call per driver per minute, and the next call needs a best at least 0.1 s better than the last one called. The best lap is still shown on screen and in the overlay. The three values are under Settings → Audio (0 turns a rule off). Races are unaffected, and fastest lap of the session and track record calls stay as before.
|
||||||
|
|
||||||
- The practice reset button on Race Day is now called **Reset – new practice day** (it was "New practice day", which didn't say that it resets).
|
- The practice reset button on Race Day is now called **Reset – new practice day** (it was "New practice day", which didn't say that it resets).
|
||||||
|
|
||||||
## 1.41.1 - 2026-10-18
|
## 1.41.1 - 2026-10-18
|
||||||
|
|||||||
@@ -2130,6 +2130,10 @@ const TRANSLATIONS = {
|
|||||||
"audio.max_delay": "Största fördröjning (sek)",
|
"audio.max_delay": "Största fördröjning (sek)",
|
||||||
"audio.per_competitor": "Olika passing-ton per förare/bil",
|
"audio.per_competitor": "Olika passing-ton per förare/bil",
|
||||||
"audio.race_callouts": "Utrop under race",
|
"audio.race_callouts": "Utrop under race",
|
||||||
|
"audio.practice_pb_warmup": "Träning: tyst personbästa första varven",
|
||||||
|
"audio.practice_pb_cooldown": "Träning: sekunder mellan PB-utrop per förare",
|
||||||
|
"audio.practice_pb_min_gain": "Träning: minsta förbättring för utrop (s)",
|
||||||
|
"audio.practice_pb_hint": "Gäller open practice. På nyladdade ackar slår alla sin bästa tid nästan varje varv i början av dagen. Bästa varvet visas ändå på skärm och overlay. 0 stänger av regeln.",
|
||||||
"audio.race_callouts_passing": "Bara passeringsljud (som tidtagningssystem)",
|
"audio.race_callouts_passing": "Bara passeringsljud (som tidtagningssystem)",
|
||||||
"audio.race_callouts_full": "Speaker - namn, bästa varv, ny ledare",
|
"audio.race_callouts_full": "Speaker - namn, bästa varv, ny ledare",
|
||||||
"audio.test": "Testa",
|
"audio.test": "Testa",
|
||||||
@@ -3963,6 +3967,10 @@ const TRANSLATIONS = {
|
|||||||
"audio.max_delay": "Maximum delay (seconds)",
|
"audio.max_delay": "Maximum delay (seconds)",
|
||||||
"audio.per_competitor": "Different passing tone per driver/car",
|
"audio.per_competitor": "Different passing tone per driver/car",
|
||||||
"audio.race_callouts": "Calls during a race",
|
"audio.race_callouts": "Calls during a race",
|
||||||
|
"audio.practice_pb_warmup": "Practice: silent personal best for first laps",
|
||||||
|
"audio.practice_pb_cooldown": "Practice: seconds between PB calls per driver",
|
||||||
|
"audio.practice_pb_min_gain": "Practice: minimum improvement to call (s)",
|
||||||
|
"audio.practice_pb_hint": "Open Practice. On fresh packs everyone beats their best almost every lap early in the day. The best lap is still shown on screen and in the overlay. 0 turns a rule off.",
|
||||||
"audio.race_callouts_passing": "Passing tone only (like timing systems)",
|
"audio.race_callouts_passing": "Passing tone only (like timing systems)",
|
||||||
"audio.race_callouts_full": "Speaker - names, best laps, new leader",
|
"audio.race_callouts_full": "Speaker - names, best laps, new leader",
|
||||||
"audio.test": "Test",
|
"audio.test": "Test",
|
||||||
|
|||||||
+16
-1
@@ -2,8 +2,12 @@ import { decoderDiagnostics } from "./decoder_diagnostics.js";
|
|||||||
import { getControlledLapStreak } from "./training_logic.js";
|
import { getControlledLapStreak } from "./training_logic.js";
|
||||||
import { usesPersonalClock, getLatestClockStartTs } from "./prologue_logic.js";
|
import { usesPersonalClock, getLatestClockStartTs } from "./prologue_logic.js";
|
||||||
import { isSuspectLap, getSuspectReferenceLaps } from "./suspect_laps_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"]);
|
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) {
|
function getCurrentPracticePaceLaps(result, competitorKey) {
|
||||||
const laps = [];
|
const laps = [];
|
||||||
@@ -271,6 +275,11 @@ export function disconnectDecoderHelper(options = {}, deps) {
|
|||||||
updateConnectionBadge();
|
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") {
|
export function processDecoderMessageHelper(msg, deps, decoderRole = "main") {
|
||||||
const {
|
const {
|
||||||
state, t, getActiveSession, ensureSessionResult, normalizeStartMode, getSessionLapWindow,
|
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) 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 && 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 (!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 });
|
if (previousPosition >= 0 && currentPosition >= 0 && currentPosition < previousPosition) triggerRaceAudio("position_gain", { driverId: entry.driverId, competitorKey: key });
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
// 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;
|
||||||
|
}
|
||||||
@@ -85,6 +85,10 @@ export function normalizeRaceAudioSettings(value = {}) {
|
|||||||
maxStartDelay,
|
maxStartDelay,
|
||||||
perCompetitorPassingTone: source.perCompetitorPassingTone === true,
|
perCompetitorPassingTone: source.perCompetitorPassingTone === true,
|
||||||
raceCallouts: source.raceCallouts === "full" ? "full" : "passing",
|
raceCallouts: source.raceCallouts === "full" ? "full" : "passing",
|
||||||
|
// Open Practice personal best calls (practice_callouts_logic.js); 0 turns a rule off.
|
||||||
|
practicePbWarmupLaps: Math.round(clamp(source.practicePbWarmupLaps, 10, 0, 30)),
|
||||||
|
practicePbCooldownSec: Math.round(clamp(source.practicePbCooldownSec, 60, 0, 600)),
|
||||||
|
practicePbMinGainMs: Math.round(clamp(source.practicePbMinGainMs, 100, 0, 2000)),
|
||||||
events,
|
events,
|
||||||
templates: source.templates && typeof source.templates === "object" ? { ...source.templates } : {},
|
templates: source.templates && typeof source.templates === "object" ? { ...source.templates } : {},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -251,6 +251,9 @@ export function renderSettings(deps) {
|
|||||||
<label class="toggle"><input type="checkbox" name="raceAudioEnabled" form="settingsForm" ${raceAudio.enabled ? "checked" : ""} /><span>${t("audio.enabled")}</span></label>
|
<label class="toggle"><input type="checkbox" name="raceAudioEnabled" form="settingsForm" ${raceAudio.enabled ? "checked" : ""} /><span>${t("audio.enabled")}</span></label>
|
||||||
<label class="toggle"><input type="checkbox" name="raceAudioMuted" form="settingsForm" ${raceAudio.muted ? "checked" : ""} /><span>${t("audio.mute")}</span></label>
|
<label class="toggle"><input type="checkbox" name="raceAudioMuted" form="settingsForm" ${raceAudio.muted ? "checked" : ""} /><span>${t("audio.mute")}</span></label>
|
||||||
<label><span>${t("audio.race_callouts")}</span><select name="raceAudioRaceCallouts" form="settingsForm"><option value="passing" ${raceAudio.raceCallouts === "passing" ? "selected" : ""}>${t("audio.race_callouts_passing")}</option><option value="full" ${raceAudio.raceCallouts === "full" ? "selected" : ""}>${t("audio.race_callouts_full")}</option></select></label>
|
<label><span>${t("audio.race_callouts")}</span><select name="raceAudioRaceCallouts" form="settingsForm"><option value="passing" ${raceAudio.raceCallouts === "passing" ? "selected" : ""}>${t("audio.race_callouts_passing")}</option><option value="full" ${raceAudio.raceCallouts === "full" ? "selected" : ""}>${t("audio.race_callouts_full")}</option></select></label>
|
||||||
|
<label title="${t("audio.practice_pb_hint")}"><span>${t("audio.practice_pb_warmup")}</span><input type="number" min="0" max="30" step="1" name="raceAudioPbWarmup" form="settingsForm" value="${raceAudio.practicePbWarmupLaps}" /></label>
|
||||||
|
<label title="${t("audio.practice_pb_hint")}"><span>${t("audio.practice_pb_cooldown")}</span><input type="number" min="0" max="600" step="10" name="raceAudioPbCooldown" form="settingsForm" value="${raceAudio.practicePbCooldownSec}" /></label>
|
||||||
|
<label title="${t("audio.practice_pb_hint")}"><span>${t("audio.practice_pb_min_gain")}</span><input type="number" min="0" max="2" step="0.05" name="raceAudioPbMinGain" form="settingsForm" value="${raceAudio.practicePbMinGainMs / 1000}" /></label>
|
||||||
<label><span>${t("audio.language")}</span><select name="raceAudioLanguage" form="settingsForm"><option value="sv" ${raceAudio.language === "sv" ? "selected" : ""}>Svenska</option><option value="en" ${raceAudio.language === "en" ? "selected" : ""}>English</option></select></label>
|
<label><span>${t("audio.language")}</span><select name="raceAudioLanguage" form="settingsForm"><option value="sv" ${raceAudio.language === "sv" ? "selected" : ""}>Svenska</option><option value="en" ${raceAudio.language === "en" ? "selected" : ""}>English</option></select></label>
|
||||||
<label><span>${t("audio.voice_select")}</span><select name="raceAudioVoiceUri" form="settingsForm"><option value="">${t("audio.voice_auto")}</option>${raceAudioVoiceOptions}</select></label>
|
<label><span>${t("audio.voice_select")}</span><select name="raceAudioVoiceUri" form="settingsForm"><option value="">${t("audio.voice_auto")}</option>${raceAudioVoiceOptions}</select></label>
|
||||||
<label><span>${t("audio.voice_rate")}</span><input type="range" min="0.65" max="1.35" step="0.05" name="raceAudioVoiceRate" form="settingsForm" value="${raceAudio.voiceRate}" /></label>
|
<label><span>${t("audio.voice_rate")}</span><input type="range" min="0.65" max="1.35" step="0.05" name="raceAudioVoiceRate" form="settingsForm" value="${raceAudio.voiceRate}" /></label>
|
||||||
@@ -629,6 +632,9 @@ Erik Eriksson;654321;4WD;Associated;;</code></pre>
|
|||||||
randomStartDelay: form.get("raceAudioRandomDelay") === "on", minStartDelay: Number(form.get("raceAudioMinDelay")),
|
randomStartDelay: form.get("raceAudioRandomDelay") === "on", minStartDelay: Number(form.get("raceAudioMinDelay")),
|
||||||
maxStartDelay: Number(form.get("raceAudioMaxDelay")), perCompetitorPassingTone: form.get("raceAudioPerCompetitor") === "on",
|
maxStartDelay: Number(form.get("raceAudioMaxDelay")), perCompetitorPassingTone: form.get("raceAudioPerCompetitor") === "on",
|
||||||
raceCallouts: String(form.get("raceAudioRaceCallouts") || "passing"),
|
raceCallouts: String(form.get("raceAudioRaceCallouts") || "passing"),
|
||||||
|
practicePbWarmupLaps: Number(form.get("raceAudioPbWarmup")),
|
||||||
|
practicePbCooldownSec: Number(form.get("raceAudioPbCooldown")),
|
||||||
|
practicePbMinGainMs: Math.round(Number(form.get("raceAudioPbMinGain")) * 1000),
|
||||||
events,
|
events,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -57,6 +57,15 @@ export async function runSettingsTabsSmoke({ evaluate, navigate, waitFor, savedS
|
|||||||
assert.equal(await callouts(), "passing");
|
assert.equal(await callouts(), "passing");
|
||||||
console.log("PASS the legacy audio panel is gone and race calls default to passing tone only");
|
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
|
// The sidebar "update available" link opens Settings on System & backup at Updates, even
|
||||||
// when another tab was the last one used.
|
// when another tab was the last one used.
|
||||||
await evaluate(`document.querySelector('[data-settings-tab="connection"]').click()`);
|
await evaluate(`document.querySelector('[data-settings-tab="connection"]').click()`);
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ function createHarness(options = {}) {
|
|||||||
],
|
],
|
||||||
cars: [],
|
cars: [],
|
||||||
resultsBySession: {},
|
resultsBySession: {},
|
||||||
|
...(options.raceAudio ? { settings: { raceAudio: options.raceAudio } } : {}),
|
||||||
};
|
};
|
||||||
let saveCount = 0;
|
let saveCount = 0;
|
||||||
const overlayEvents = [];
|
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", () => {
|
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";
|
harness.session.trackLayoutId = "layout_a";
|
||||||
const entry = () => Object.values(harness.state.resultsBySession.session_1.competitors)[0];
|
const entry = () => Object.values(harness.state.resultsBySession.session_1.competitors)[0];
|
||||||
const pbs = () => harness.audioEvents.filter((event) => event === "personal_best").length;
|
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");
|
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", () => {
|
test("practice: a shortcut lap is flagged suspect - counted, but no best lap, personal best or record", () => {
|
||||||
const harness = createHarness({ sessionType: "open_practice" });
|
const harness = createHarness({ sessionType: "open_practice" });
|
||||||
const entry = () => Object.values(harness.state.resultsBySession.session_1.competitors)[0];
|
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 "./auth.test.js";
|
||||||
|
import "./practice_callouts_logic.test.js";
|
||||||
import "./local_cache.test.js";
|
import "./local_cache.test.js";
|
||||||
import "./prologue_logic.test.js";
|
import "./prologue_logic.test.js";
|
||||||
import "./suspect_laps_logic.test.js";
|
import "./suspect_laps_logic.test.js";
|
||||||
|
|||||||
Reference in new issue
Block a user