feat(series): run each round from the series page

Step 3 becomes a rounds table: pick drivers inline (copy from the
previous round, add a late entry), set qualifying rounds/finals/max
cars per heat per round, see the status, and create qualifying and
finals from there. Qualifying heats are now split evenly so nobody
drives alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
larssandandClaude Opus 5.5 committed 2026-10-11 18:55:36 +02:00
1 parent 581ec2c781
commit b5707f92d1
17 files changed
+447 -39

No files matched your search

+148 -5
View File
@@ -9,7 +9,7 @@ import { recordTransponderSighting, buildWarmupCheck, createPrologue, getPrologu
import { findTransponderConflict, getDriverProfileId } from "./driver_profile_logic.js";
import { renderRaceDayView, refreshRaceDayWarmup, refreshRaceDayPrologueClock, updateRaceDayStartDisplay } from "./race_day_view.js";
import { beginSession as beginSessionControl, finishSession as finishSessionControl, pauseSession as pauseSessionControl, resumeSession as resumeSessionControl } from "./session_control.js";
import { normalizeSeries, buildSeriesStandings } from "./series_logic.js";
import { normalizeSeries, buildSeriesStandings, getSeriesRoundStatus } from "./series_logic.js";
import { renderSeriesView } from "./series_view.js";
import { RACE_AUDIO_EVENT_DEFINITIONS, createRaceAudioEngine, normalizeRaceAudioSettings, isSilencedDuringRace } from "./race_audio.js";
@@ -518,7 +518,7 @@ const getSeriesStandings = (series) => buildSeriesStandings(series, {
classNames: new Map(state.classes.map((item) => [item.id, item.name])),
});
// One race per date and class, named "<series> #<round> <class>", with the chosen race format.
const createSeriesEvents = (series, dates, presetId) => {
const createSeriesEvents = (series, dates, presetId, format = {}) => {
const existingDates = new Set(state.events.filter((event) => series.eventIds.includes(event.id)).map((event) => event.date));
const allDates = [...new Set([...existingDates, ...dates])].sort();
let created = 0;
@@ -529,6 +529,7 @@ const createSeriesEvents = (series, dates, presetId) => {
const event = normalizeEvent({ id: uid("event"), name: `${series.name} #${round} ${getClassName(classId)}`, date, classId, mode: "race" });
applyRaceFormatPreset(event, presetId);
state.events.push(event);
if (Object.keys(format).length) setSeriesRoundFormat(event.id, format);
series.eventIds.push(event.id);
created += 1;
});
@@ -536,6 +537,84 @@ const createSeriesEvents = (series, dates, presetId) => {
saveState();
return created;
};
// --- Series hub: each round (one race) handled right from the series page ----------------
const byDriverName = (a, b) => String(a.name || "").localeCompare(String(b.name || ""), undefined, { sensitivity: "base" });
const getSeriesRounds = (series) => state.events
.filter((event) => series.eventIds.includes(event.id))
.sort((a, b) => String(a.date || "").localeCompare(String(b.date || "")) || getClassName(a.classId).localeCompare(getClassName(b.classId), undefined, { numeric: true }))
.map((event) => {
const sessions = getSessionsForEvent(event.id);
const qualSessions = sessions.filter((session) => session.type === "qualification");
return {
event,
className: getClassName(event.classId),
classDrivers: state.drivers.filter((driver) => driver.classId === event.classId).sort(byDriverName),
participantIds: getEventDrivers(event).map((driver) => driver.id),
status: getSeriesRoundStatus(sessions),
qualHeatCount: new Set(qualSessions.map((session) => String(session.name || "").split(" ").pop())).size,
finalCount: sessions.filter((session) => session.type === "final").length,
};
});
const findSeriesEvent = (eventId) => state.events.find((event) => event.id === eventId) || null;
// Format per round (can differ between rounds and classes); locked once qualifying exists.
const setSeriesRoundFormat = (eventId, values) => {
const event = findSeriesEvent(eventId);
if (!event) return;
const config = event.raceConfig;
config.qualifyingRounds = Math.max(1, Math.round(Number(values.qualifyingRounds ?? config.qualifyingRounds) || 1));
config.finalLegs = Math.max(1, Math.round(Number(values.finalLegs ?? config.finalLegs) || 1));
config.carsPerHeat = Math.max(2, Math.round(Number(values.carsPerHeat ?? config.carsPerHeat) || 2));
config.carsPerFinal = Math.max(2, Math.round(Number(values.carsPerHeat ?? config.carsPerFinal) || config.carsPerFinal || 2));
// Two of three finals count (or all, with fewer than three).
config.countedFinalLegs = config.finalLegs >= 3 ? config.finalLegs - 1 : config.finalLegs;
config.presetId = "custom";
saveState();
};
const setSeriesRoundParticipants = (eventId, driverIds) => {
const event = findSeriesEvent(eventId);
if (!event) return;
event.raceConfig.driverIds = [...new Set(driverIds)];
event.raceConfig.participantsConfigured = true;
saveState();
};
// Same starting field as the previous round of the same class in this series.
const copySeriesRoundParticipants = (series, eventId) => {
const rounds = getSeriesRounds(series);
const index = rounds.findIndex((round) => round.event.id === eventId);
const previous = rounds.slice(0, Math.max(0, index)).reverse().find((round) => round.event.classId === rounds[index]?.event.classId);
if (!previous) return false;
setSeriesRoundParticipants(eventId, previous.participantIds.filter((id) => rounds[index].classDrivers.some((driver) => driver.id === id)));
return true;
};
// A driver turning up on the day: registered in the round's class (and the series' club for a
// members-only series) and ticked for this round.
const addDriverToSeriesRound = (series, eventId, { name, transponder }) => {
const event = findSeriesEvent(eventId);
const cleanName = String(name || "").trim();
if (!event || !cleanName) return false;
const driver = normalizeDriver({ id: uid("driver"), name: cleanName, classId: event.classId, transponder: String(transponder || "").trim(), club: series.scoring === "club" ? series.club : "" });
state.drivers.push(driver);
setSeriesRoundParticipants(eventId, [...getEventDrivers(event).map((item) => item.id), driver.id]);
return true;
};
const generateSeriesRoundQualifying = (eventId) => {
const event = findSeriesEvent(eventId);
if (!event) return 0;
const created = generateQualifyingForRace(event);
saveState();
return created;
};
const generateSeriesRoundFinals = (eventId) => {
const event = findSeriesEvent(eventId);
if (!event) return 0;
const created = generateFinalsForRace(event);
saveState();
return created;
};
const openSeriesRound = (eventId) => {
selectedEventEditId = eventId;
navigateToView("race_setup");
};
const seriesCell = (table, row, event) => {
const result = row.results.find((item) => item.eventId === event.id);
if (!event.completed || !result) return "";
@@ -569,7 +648,7 @@ const exportSeriesPdf = async (series, tables) => {
)),
});
};
const renderSeries = () => renderSeriesView({ state, dom, t, escapeHtml, saveState, renderView, uid, getClassName, getSeriesStandings, createSeriesEvents, getRaceFormatPresets, exportSeriesPdf, printSeries });
const renderSeries = () => renderSeriesView({ state, dom, t, escapeHtml, saveState, renderView, uid, getClassName, getSeriesStandings, createSeriesEvents, getRaceFormatPresets, exportSeriesPdf, printSeries, getSeriesRounds, setSeriesRoundFormat, setSeriesRoundParticipants, copySeriesRoundParticipants, addDriverToSeriesRound, generateSeriesRoundQualifying, generateSeriesRoundFinals, openSeriesRound });
const renderArchive = () => renderResultsArchiveView({
state, dom, t, escapeHtml, formatLap, formatRaceClock, renderTable,
getClassName, getEventName, buildLeaderboard, getCompetitorPassings,
@@ -715,6 +794,38 @@ const TRANSLATIONS = {
"series.step3": "3 · Deltävlingar ({count})",
"series.step4": "4 · Ställning",
"series.classes_all": "Alla",
"series.round_participants": "Deltagare: {count} av {total} i klassen",
"series.copy_previous": "Kopiera från förra",
"series.no_previous_round": "Ingen tidigare deltävling i samma klass.",
"series.no_class_drivers": "Inga förare i klassen ännu - lägg till nedan.",
"series.new_driver_name": "Ny förare - namn",
"series.add_driver": "Lägg till",
"series.no_rounds": "Inga deltävlingar ännu - skapa dem ovan.",
"series.col_date": "Datum",
"series.col_race": "Race",
"series.col_drivers": "Förare",
"series.col_qual": "Kvalomgångar",
"series.col_qual_short": "Kval",
"series.col_qual_hint": "Antal kvalomgångar. Antalet heat per omgång räknas ut av antalet förare.",
"series.col_finals": "Finaler",
"series.col_per_heat": "Max bilar/heat",
"series.col_status": "Status",
"series.base_format": "Övrigt format (tider, starttyp)",
"series.make_qualifying": "Skapa kval",
"series.make_finals": "Skapa finaler",
"series.open_race": "Öppna",
"series.remove_round": "Ta bort ur serien (racet finns kvar)",
"series.remove_round_confirm": "Ta bort deltävlingen ur serien? Racet och dess resultat finns kvar.",
"series.no_participants": "Välj minst en förare först (klicka på antalet förare).",
"series.heats_made": "{heats} heat per omgång",
"series.status_not_started": "Ej startad",
"series.status_qual_ready": "Kval skapat",
"series.status_qual_running": "Kval pågår",
"series.status_qual_done": "Kval klart",
"series.status_finals": "Finaler",
"series.status_done": "Klar",
"series.add_existing": "Lägg till ett befintligt race",
"series.add_existing_pick": "Välj race ...",
"series.no_date": "utan datum",
"series.delete": "Ta bort serien",
"series.classes_none": "Inga",
@@ -749,7 +860,7 @@ const TRANSLATIONS = {
"series.count_best_value": "bästa {count}",
"series.count_drop_value": "alla utom {count} sämsta",
"series.events": "Deltävlingar ({count})",
"series.events_hint": "Bocka i racen som ingår, eller skapa dem på en gång: ett race per datum och klass. Lägg sedan till förare och generera heat i Race Setup som vanligt.",
"series.events_hint": "Skapa alla deltävlingar på en gång (ett race per datum och klass). Sedan sköts varje deltävling härifrån: välj förare, ändra antal kval och finaler, skapa kval - heaten delas in efter hur många som är med - och sedan finaler.",
"series.no_events": "Inga race i de valda klasserna ännu - skapa dem nedan.",
"series.create_dates": "Skapa deltävlingar för datum",
"series.create_dates_hint": "Ett datum per rad (ÅÅÅÅ-MM-DD). Ett race skapas per datum och vald klass.",
@@ -2453,6 +2564,38 @@ const TRANSLATIONS = {
"series.step3": "3 · Rounds ({count})",
"series.step4": "4 · Standings",
"series.classes_all": "All",
"series.round_participants": "Drivers: {count} of {total} in the class",
"series.copy_previous": "Copy from previous",
"series.no_previous_round": "No earlier round in the same class.",
"series.no_class_drivers": "No drivers in the class yet - add one below.",
"series.new_driver_name": "New driver - name",
"series.add_driver": "Add",
"series.no_rounds": "No rounds yet - create them above.",
"series.col_date": "Date",
"series.col_race": "Race",
"series.col_drivers": "Drivers",
"series.col_qual": "Qualifying rounds",
"series.col_qual_short": "Qualifying",
"series.col_qual_hint": "Number of qualifying rounds. The number of heats per round follows the number of drivers.",
"series.col_finals": "Finals",
"series.col_per_heat": "Max cars/heat",
"series.col_status": "Status",
"series.base_format": "Other format (times, start mode)",
"series.make_qualifying": "Create qualifying",
"series.make_finals": "Create finals",
"series.open_race": "Open",
"series.remove_round": "Remove from the series (the race is kept)",
"series.remove_round_confirm": "Remove the round from the series? The race and its results are kept.",
"series.no_participants": "Pick at least one driver first (click the number of drivers).",
"series.heats_made": "{heats} heats per round",
"series.status_not_started": "Not started",
"series.status_qual_ready": "Qualifying created",
"series.status_qual_running": "Qualifying running",
"series.status_qual_done": "Qualifying done",
"series.status_finals": "Finals",
"series.status_done": "Done",
"series.add_existing": "Add an existing race",
"series.add_existing_pick": "Pick a race ...",
"series.no_date": "no date",
"series.delete": "Delete series",
"series.classes_none": "None",
@@ -2487,7 +2630,7 @@ const TRANSLATIONS = {
"series.count_best_value": "best {count}",
"series.count_drop_value": "all but the {count} worst",
"series.events": "Rounds ({count})",
"series.events_hint": "Tick the races that belong to the series, or create them in one go: one race per date and class. Then add drivers and generate heats in Race Setup as usual.",
"series.events_hint": "Create all rounds in one go (one race per date and class). Then run each round from here: pick drivers, change the number of qualifying rounds and finals, create qualifying - heats are split by how many drivers take part - and then finals.",
"series.no_events": "No races in the selected classes yet - create them below.",
"series.create_dates": "Create rounds for dates",
"series.create_dates_hint": "One date per line (YYYY-MM-DD). One race is created per date and selected class.",