Improve training statistics, achievements and stable pace audio

This commit is contained in:
larssand committed 2026-09-03 06:36:17 +02:00
1 parent 82d52ed6cd
commit 4f847610dc
16 files changed
+315 -50

No files matched your search

+31
View File
@@ -1,3 +1,21 @@
import { getControlledLapStreak } from "./training_logic.js";
const PRACTICE_SESSION_TYPES = new Set(["open_practice", "free_practice", "practice"]);
function getCurrentPracticePaceLaps(result, competitorKey) {
const laps = [];
const passings = Array.isArray(result?.passings) ? result.passings : [];
for (let index = passings.length - 1; index >= 0; index -= 1) {
const passing = passings[index];
if (String(passing?.competitorKey || "") !== String(competitorKey || "")) continue;
if (passing.validLap === false || passing.excludedFromPace || passing.stintBoundary) break;
const lapMs = Number(passing.lapMs || 0);
if (lapMs <= 500) break;
laps.unshift(lapMs);
}
return laps;
}
function parseRtcTime(value) {
if (!value || typeof value !== "string") {
return null;
@@ -469,6 +487,19 @@ export function processDecoderMessageHelper(msg, deps, decoderRole = "main") {
const leaderboard = buildLeaderboard(session);
const currentPosition = leaderboard.findIndex((row) => row.key === key);
const audioVariables = { driverName: entry.speechName || entry.displayName || entry.driverName, lapTime: formatLap(lapMs) };
if (entry.driverId && PRACTICE_SESSION_TYPES.has(String(session.type || "").toLowerCase()) && !validationWarning) {
const controlTargetMs = entry.bestLapMs ? Math.round(entry.bestLapMs * 1.08) : 0;
const controlledLapStreak = getControlledLapStreak(getCurrentPracticePaceLaps(result, key), controlTargetMs);
if (controlledLapStreak >= 5 && controlledLapStreak % 5 === 0) {
triggerRaceAudio("training_stable_pace", {
variables: { ...audioVariables, laps: controlledLapStreak },
driverId: entry.driverId,
competitorKey: key,
scope: entry.driverId,
logData: { raceId: session.eventId, sessionId: session.id, driverId: entry.driverId, lapNumber: entry.laps, lapTime: lapMs },
});
}
}
if (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 } });
if (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 (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 } });