fix(race): finish the lap you are on, one clock owner, edits survive refresh, participants editable (1.59.0)

This commit is contained in:
larssand committed 2026-11-04 21:34:06 +01:00
1 parent afb8829b16
commit db6a9f19e4
16 files changed
+313 -39

No files matched your search

+17 -4
View File
@@ -19,7 +19,7 @@ import { renderRaceFormatField, renderRaceFormatContextCard, getRaceSummaryItems
import { normalizeRaceTeam as normalizeRaceTeamLogic, normalizeStoredRacePreset as normalizeStoredRacePresetLogic, getRaceFormatPresets as getRaceFormatPresetsLogic, applyRaceFormatPreset as applyRaceFormatPresetLogic, buildRaceFormatConfigFromForm as buildRaceFormatConfigFromFormLogic, normalizeEvent as normalizeEventLogic, normalizeBrandingConfig as normalizeBrandingConfigLogic, resolveEventBranding as resolveEventBrandingLogic, getRaceManageStatuses as getRaceManageStatusesLogic, buildDefaultRaceWizardDraft as buildDefaultRaceWizardDraftLogic, getRaceWizardPreset as getRaceWizardPresetLogic, applyRaceWizardPresetDefaults as applyRaceWizardPresetDefaultsLogic, ensureRaceParticipantsConfigured as ensureRaceParticipantsConfiguredLogic, buildRaceSession as buildRaceSessionLogic, buildOpenPracticeBundle as buildOpenPracticeBundleLogic, buildTrackSession as buildTrackSessionLogic, createSponsorRounds as createSponsorRoundsLogic, buildRaceSessionsFromWizard as buildRaceSessionsFromWizardLogic, getRaceWizardSessionPlan as getRaceWizardSessionPlanLogic, getEventDrivers as getEventDriversLogic, getEventTeams as getEventTeamsLogic, getTeamDriverPool as getTeamDriverPoolLogic, reassignTeamMembers as reassignTeamMembersLogic, findEventTeamForPassing as findEventTeamForPassingLogic, generateQualifyingForRace as generateQualifyingForRaceLogic, reseedUpcomingQualifying as reseedUpcomingQualifyingLogic, moveDriversIntoQualifyingHeat as moveDriversIntoQualifyingHeatLogic, parseQualifyingHeatName as parseQualifyingHeatNameLogic, generateFinalsForRace as generateFinalsForRaceLogic, applyBumpsForRace as applyBumpsForRaceLogic, buildEventSchedule as buildEventScheduleLogic, normalizeHeatOrder, planSeedingGroups } from "./event_race_logic.js";
import { getSessionTypeLabel as getSessionTypeLabelLogic, getStatusLabel as getStatusLabelLogic, isUntimedSession as isUntimedSessionLogic, getActiveSession as getActiveSessionLogic, getLiveSession as getLiveSessionLogic, getSessionTargetMs as getSessionTargetMsLogic, getSessionLapWindow as getSessionLapWindowLogic, isCountedPassing as isCountedPassingLogic, getVisiblePassings as getVisiblePassingsLogic, getPassingValidationLabel as getPassingValidationLabelLogic, getSessionTiming as getSessionTimingLogic, ensureSessionResult as ensureSessionResultLogic, buildLeaderboard as buildLeaderboardLogic, formatLapDelta as formatLapDeltaLogic, formatLeaderboardGap as formatLeaderboardGapLogic, getCompetitorElapsedMs as getCompetitorElapsedMsLogic, getCompetitorPassings as getCompetitorPassingsLogic, getCompetitorSeedMetric as getCompetitorSeedMetricLogic, getSessionEntrants as getSessionEntrantsLogic, buildPracticeStandings as buildPracticeStandingsLogic, getQualifyingPointsValue as getQualifyingPointsValueLogic, isHighPointsTable as isHighPointsTableLogic, compareNumberSet as compareNumberSetLogic, buildQualifyingTieBreakNote as buildQualifyingTieBreakNoteLogic, hasQualifyingPrimaryTie as hasQualifyingPrimaryTieLogic, buildQualifyingStandings as buildQualifyingStandingsLogic, formatTeamActiveMemberLabel as formatTeamActiveMemberLabelLogic, buildTeamRaceStandings as buildTeamRaceStandingsLogic, buildSessionChannelStats as buildSessionChannelStatsLogic, buildTeamStintLog as buildTeamStintLogLogic, getSessionGridEntries as getSessionGridEntriesLogic, getSessionGridOrder as getSessionGridOrderLogic, ensureSessionDriverOrder as ensureSessionDriverOrderLogic, buildFinalStandings as buildFinalStandingsLogic, getTrackRecordMs as getTrackRecordMsLogic } from "./timing_logic.js";
import { getFinishWait as getFinishWaitLogic, getSessionTypeLabel as getSessionTypeLabelLogic, getStatusLabel as getStatusLabelLogic, isUntimedSession as isUntimedSessionLogic, getActiveSession as getActiveSessionLogic, getLiveSession as getLiveSessionLogic, getSessionTargetMs as getSessionTargetMsLogic, getSessionLapWindow as getSessionLapWindowLogic, isCountedPassing as isCountedPassingLogic, getVisiblePassings as getVisiblePassingsLogic, getPassingValidationLabel as getPassingValidationLabelLogic, getSessionTiming as getSessionTimingLogic, ensureSessionResult as ensureSessionResultLogic, buildLeaderboard as buildLeaderboardLogic, formatLapDelta as formatLapDeltaLogic, formatLeaderboardGap as formatLeaderboardGapLogic, getCompetitorElapsedMs as getCompetitorElapsedMsLogic, getCompetitorPassings as getCompetitorPassingsLogic, getCompetitorSeedMetric as getCompetitorSeedMetricLogic, getSessionEntrants as getSessionEntrantsLogic, buildPracticeStandings as buildPracticeStandingsLogic, getQualifyingPointsValue as getQualifyingPointsValueLogic, isHighPointsTable as isHighPointsTableLogic, compareNumberSet as compareNumberSetLogic, buildQualifyingTieBreakNote as buildQualifyingTieBreakNoteLogic, hasQualifyingPrimaryTie as hasQualifyingPrimaryTieLogic, buildQualifyingStandings as buildQualifyingStandingsLogic, formatTeamActiveMemberLabel as formatTeamActiveMemberLabelLogic, buildTeamRaceStandings as buildTeamRaceStandingsLogic, buildSessionChannelStats as buildSessionChannelStatsLogic, buildTeamStintLog as buildTeamStintLogLogic, getSessionGridEntries as getSessionGridEntriesLogic, getSessionGridOrder as getSessionGridOrderLogic, ensureSessionDriverOrder as ensureSessionDriverOrderLogic, buildFinalStandings as buildFinalStandingsLogic, getTrackRecordMs as getTrackRecordMsLogic } from "./timing_logic.js";
import { normalizeTrackLayouts, getTrackLayoutIdAt, getTrackLayoutLabel, nextTrackLayoutLabel, findRaceSessionBlockingLayoutChange, isPracticeSessionType, isTrackLayoutInUse } from "./track_layouts_logic.js";
import { renderDashboardView, renderClassesView, renderDriversView, renderCarsView } from "./core_views.js";
@@ -219,7 +219,13 @@ const announceRaceFinished = (finished = null) => {
if (podium.length > 1) triggerRaceAudio("podium", { variables: { podium: podium.map((row) => row.displayName || row.driverName).join(", ") } });
};
const announceRaceClockEvent = (eventKey, session) => triggerRaceAudio(eventKey, { logData: { raceId: session.eventId, sessionId: session.id } });
const handleSessionTimerTick = () => handleSessionTimerTickHelper({ getActiveSession: getLiveSession, isUntimedSession, getSessionTiming, saveState, getLastFinishAnnouncementSessionId: () => lastFinishAnnouncementSessionId, setLastFinishAnnouncementSessionId: (value) => { lastFinishAnnouncementSessionId = value; }, announceRaceFinished, announceRaceClockEvent });
const handleSessionTimerTick = () => handleSessionTimerTickHelper({ getActiveSession: getLiveSession, isUntimedSession, getSessionTiming, saveState, getLastFinishAnnouncementSessionId: () => lastFinishAnnouncementSessionId, setLastFinishAnnouncementSessionId: (value) => { lastFinishAnnouncementSessionId = value; }, announceRaceFinished, announceRaceClockEvent,
// The race browser: the one on the decoder, or with no decoder anywhere, the one that started the heat.
isClockOwner: (session) => !overlayMode && (Boolean(state.decoder?.connected) || readClockOwner() === session.id),
getFinishWait: (session) => getFinishWaitLogic(session, state.resultsBySession[session.id]?.competitors, { maxLapMs: getSessionLapWindow(session).maxLapMs }) });
const CLOCK_OWNER_KEY = "rc_clock_owner";
const readClockOwner = () => { try { return sessionStorage.getItem(CLOCK_OWNER_KEY) || ""; } catch { return ""; } };
const writeClockOwner = (sessionId) => { try { sessionStorage.setItem(CLOCK_OWNER_KEY, sessionId); } catch { /* private mode */ } };
const cancelRaceStart = () => raceAudioEngine.cancelStartSequence();
const startSessionWithAudio = (session, callbacks) => {
// Only the casual, come-and-go practice modes (open_practice - the standalone "Quick
@@ -554,6 +560,7 @@ function resetSessionData(session) {
session.resultsResetAt = Date.now();
delete state.resultsBySession[session.id];
session.followUpStartedAt = null;
session.finishWaitUntil = null;
session.calledAt = null;
// A heat (anything but an Open/Free Practice that runs all evening) goes back to "ready":
// the clock is back at zero and it can be started again.
@@ -1794,6 +1801,8 @@ const TRANSLATIONS = {
"events.edit": "Redigera",
"events.sessions": "Sessioner",
"events.participants": "Deltagare",
"events.other_class_participants": "Förare från andra klasser ({count})",
"events.participants_sync_hint": "Ändringar här följer med till practice och kvalheat som inte körts än. En ny förare hamnar i kvalheatet med minst förare.",
"events.select_participants": "Välj racedeltagare",
"events.select_all_participants": "Markera alla",
"events.clear_participants": "Rensa deltagare",
@@ -2796,7 +2805,7 @@ const TRANSLATIONS = {
"guide.race_format_5": "Finaltid och Final-start styr varje finalleg, ofta med positionsstart.",
"guide.race_format_6": "Bump-up per final och Reservera bump-platser används om förare ska kunna flyttas från lägre final till nästa main.",
"guide.race_format_7": "Källa för finaler avgör om finalerna seedas från practice eller kvalrankingen.",
"guide.race_format_8": "Follow-up tid ger en extra uppsamlingsperiod efter ordinarie racetid innan heatet verkligen stängs.",
"guide.race_format_8": "När tiden är slut säger speakern \"Tiden är slut, slutför pågående varv\". Varje förare är i mål vid sin första passering efter sin egen tid, och passeringar efter det räknas inte. Heatet stängs så fort alla gått i mål, eller senast när den som är kvar ute fått cirka 1,5 av sin egen varvtid på sig (aldrig mer än Max varvtid). Follow-up tid är den kortaste väntetiden.",
"guide.race_format_9": "Min varvtid filtrerar bort shortcuts och felträffar. Exempel: på en 16-sekundersbana kan du sätta 11 sekunder som min-gräns.",
"guide.race_format_10": "Max varvtid är en statistikgräns. En längre passering avslutar stinten och utesluts ur pace-snittet, men varvet räknas fortfarande i race. Exempel: 120 sekunder ger en ny stint efter två minuters uppehåll.",
"guide.race_format_11": "Preset låter dig snabbt fylla raceformat med vettiga grundvärden för kort teknisk bana, klubbrace, IFMAR-liknande upplägg eller endurance.",
@@ -3773,6 +3782,8 @@ const TRANSLATIONS = {
"events.edit": "Edit",
"events.sessions": "Sessions",
"events.participants": "Participants",
"events.other_class_participants": "Drivers from other classes ({count})",
"events.participants_sync_hint": "Changes here carry over to practice and qualifying heats not run yet. A new driver joins the qualifying heat with the fewest drivers.",
"events.select_participants": "Select race participants",
"events.select_all_participants": "Select all",
"events.clear_participants": "Clear participants",
@@ -4775,7 +4786,7 @@ const TRANSLATIONS = {
"guide.race_format_5": "Final duration and Final start control each final leg, often with position start.",
"guide.race_format_6": "Bump-up per main and Reserve bump slots are used if drivers should move from a lower final into the next main.",
"guide.race_format_7": "Source for finals decides whether finals are seeded from practice or qualifying standings.",
"guide.race_format_8": "Follow-up time adds an extra collection period after the scheduled race time before the heat is actually closed.",
"guide.race_format_8": "When time is up the announcer says \"Time has expired, finish the lap you are on\". Each driver finishes at their first crossing after their own time, and crossings after that do not count. The heat closes as soon as everyone has finished, or at the latest when a car still out has had about 1.5 of its own lap time (never more than Max lap time). Follow-up time is the shortest wait.",
"guide.race_format_9": "Min lap time filters out shortcuts and false hits. Example: on a 16-second track you can set 11 seconds as the minimum.",
"guide.race_format_10": "Max lap time is a statistics boundary. A longer passing ends the stint and is excluded from pace averages, but the lap still counts in the race. Example: 120 seconds starts a new stint after a two-minute break.",
"guide.race_format_11": "Preset lets you quickly fill the race format with sensible defaults for a short technical track, club race, IFMAR-like setup or endurance.",
@@ -5179,6 +5190,7 @@ function normalizeSession(session = {}) {
pausedAt: Number.isFinite(Number(session?.pausedAt)) ? Number(session.pausedAt) : null,
totalPausedMs: Math.max(0, Number(session?.totalPausedMs || 0) || 0),
followUpPausedMs: Math.max(0, Number(session?.followUpPausedMs || 0) || 0),
finishWaitUntil: Number(session?.finishWaitUntil || 0) || null,
audioAnnouncements: Array.isArray(session?.audioAnnouncements) ? session.audioAnnouncements.map(String).filter(Boolean) : [],
assignments,
driverIds: Array.isArray(session?.driverIds) ? session.driverIds.map(String).filter(Boolean) : [],
@@ -5725,6 +5737,7 @@ async function runOperationalStart(session, sequenceCallbacks, onTone) {
session = state.sessions.find((item) => item.id === session.id) || session;
state.activeSessionId = session.id;
beginSessionControl(session);
writeClockOwner(session.id);
session.trackLayoutId = getTrackLayoutIdAt(state.trackLayouts);
lastFinishAnnouncementSessionId = null;
lastOverlayLeaderKeyBySession[session.id] = null;