feat(series): ÖRC Winter format, seeding practice and heat order when creating rounds (1.43.0)

This commit is contained in:
larssand committed 2026-10-31 07:58:40 +01:00
1 parent 40c3737925
commit 74dbbf6ae0
10 files changed
+173 -11

No files matched your search

+45 -2
View File
@@ -102,6 +102,34 @@ export function getRaceFormatPresets({ state, t, uid, normalizeStoredRacePreset
bumpCount: 0,
},
},
{
// ÖRC Winter Championship: 3 x 5 min qualifying (own clock), the best of two rounds
// compared, max 6 per heat and final, 3 finals of which 2 count, slowest heat first.
id: "orc_winter",
label: t("events.preset_orc_winter"),
values: {
qualifyingScoring: "best",
qualifyingRounds: 3,
carsPerHeat: 6,
qualDurationMin: 5,
qualStartMode: "flying",
qualSeedLapCount: 3,
qualSeedMethod: "consecutive",
countedQualRounds: 2,
qualifyingPointsTable: "rank_low",
qualifyingTieBreak: "rounds",
carsPerFinal: 6,
finalLegs: 3,
countedFinalLegs: 2,
finalDurationMin: 5,
finalStartMode: "position",
followUpSec: 15,
minLapMs: 12000,
maxLapMs: 60000,
bumpCount: 0,
heatOrder: "fastest_last",
},
},
{
id: "endurance",
label: t("events.preset_endurance"),
@@ -187,6 +215,7 @@ export function buildRaceFormatConfigFromForm(form, event, { normalizeStartMode,
maxLapMs: Math.max(1000, Math.round((Number(form.get("maxLapSec") || 60) || 60) * 1000)),
bumpCount: Math.max(0, Number(form.get("bumpCount") || 0) || 0),
reserveBumpSlots: form.get("reserveBumpSlots") === "on",
heatOrder: normalizeHeatOrder(form.get("heatOrder") ?? event.raceConfig.heatOrder),
driverIds: event.raceConfig.driverIds || [],
participantsConfigured: event.raceConfig.participantsConfigured !== false,
finalsSource: String(form.get("finalsSource") || "qualifying") === "practice" ? "practice" : "qualifying",
@@ -231,6 +260,7 @@ export function normalizeEvent(event, { normalizeBrandingConfig, normalizeStartM
maxLapMs: Math.max(0, Number(event?.raceConfig?.maxLapMs || 60000) || 60000),
bumpCount: Math.max(0, Number(event?.raceConfig?.bumpCount || 0) || 0),
reserveBumpSlots: event?.raceConfig?.reserveBumpSlots !== false,
heatOrder: normalizeHeatOrder(event?.raceConfig?.heatOrder),
driverIds: Array.isArray(event?.raceConfig?.driverIds) ? event.raceConfig.driverIds : [],
participantsConfigured: Boolean(event?.raceConfig?.participantsConfigured),
finalsSource: event?.raceConfig?.finalsSource === "practice" ? "practice" : "qualifying",
@@ -625,6 +655,19 @@ export function findEventTeamForPassing(event, driverId, carId, { getEventTeams
// Qualifying heats as even as possible: 9 drivers with max 8 per heat -> 5 + 4, never 8 + 1
// (someone driving alone). The number of heats follows the number of participants. Order is
// kept; earlier heats get the extra driver.
// Which qualifying heat runs first. Seeded heats are built fastest-first; most club races
// run the fastest heat last. Races saved before this option keep fastest first.
export const HEAT_ORDERS = ["fastest_first", "fastest_last"];
export function normalizeHeatOrder(value) {
return HEAT_ORDERS.includes(String(value || "")) ? String(value) : "fastest_first";
}
// Seeded rows (fastest first) split into heats in running order (heat 1 first).
export function buildSeededHeats(rows, carsPerHeat, heatOrder) {
const heats = splitIntoBalancedGroups(rows, carsPerHeat);
return normalizeHeatOrder(heatOrder) === "fastest_last" ? heats.reverse() : heats;
}
export function splitIntoBalancedGroups(items, maxSize) {
const list = Array.isArray(items) ? items : [];
if (!list.length) return [];
@@ -667,7 +710,7 @@ export function generateQualifyingForRace(event, { buildPracticeStandings, getEv
? String(event.raceConfig.qualSeedMethod).toLowerCase()
: "best_sum";
const followUpSec = Math.max(0, Number(event.raceConfig?.followUpSec || 0) || 0);
const heats = splitIntoBalancedGroups(fallbackRows, carsPerHeat);
const heats = buildSeededHeats(fallbackRows, carsPerHeat, event.raceConfig?.heatOrder);
let created = 0;
heats.forEach((heatRows, heatIndex) => {
@@ -738,7 +781,7 @@ export function reseedUpcomingQualifying(event, { buildQualifyingStandings, buil
const carsPerHeat = Math.max(2, Number(event.raceConfig?.carsPerHeat || 8) || 8);
// Same even split as generateQualifyingForRace, so reseeded heats line up with the generated ones.
const heats = splitIntoBalancedGroups(sourceRows, carsPerHeat);
const heats = buildSeededHeats(sourceRows, carsPerHeat, event.raceConfig?.heatOrder);
const sessionsByRound = new Map();
getSessionsForEvent(event.id)
.filter((session) => session.type === "qualification" && session.generated && session.status === "ready")