fix(race): finish the lap you are on, one clock owner, edits survive refresh, participants editable (1.59.0)
This commit is contained in:
1 parent
afb8829b16
commit
db6a9f19e4
16 files changed
+313
-39
No files matched your search
+56
-3
@@ -584,13 +584,43 @@ export function getEventDrivers(event, { state }) {
|
||||
// from this list (a fallback qualifying/finals grid with no practice data yet, a
|
||||
// staggered heat's start-order announcement) should follow the order a club admin
|
||||
// actually built the entry list in, not an unrelated internal array order.
|
||||
const classDriverIds = new Set(classDrivers.map((driver) => driver.id));
|
||||
const byId = new Map(classDrivers.map((driver) => [driver.id, driver]));
|
||||
// A chosen entry may come from another class (one driver, two classes).
|
||||
const byId = new Map(state.drivers.map((driver) => [driver.id, driver]));
|
||||
return (event.raceConfig.driverIds || [])
|
||||
.filter((id) => classDriverIds.has(id))
|
||||
.filter((id) => byId.has(id))
|
||||
.map((id) => byId.get(id));
|
||||
}
|
||||
|
||||
// The entry list changed: sessions not run yet follow it. A removed driver leaves them; an
|
||||
// added one joins each practice that holds the whole entry list, and the qualifying heat with
|
||||
// the fewest drivers (the same heat number in every round still to run). Run sessions and
|
||||
// finals are left alone.
|
||||
export function syncParticipantsToSessions(sessions, beforeIds = [], afterIds = []) {
|
||||
const removed = new Set(beforeIds.filter((id) => !afterIds.includes(id)));
|
||||
const added = afterIds.filter((id) => !beforeIds.includes(id));
|
||||
const pending = sessions.filter((session) => session.status === "ready" && !session.startedAt && ["practice", "qualification"].includes(session.type));
|
||||
const without = (list) => (list || []).filter((id) => !removed.has(id));
|
||||
pending.forEach((session) => {
|
||||
session.driverIds = without(session.driverIds);
|
||||
session.manualGridIds = without(session.manualGridIds);
|
||||
});
|
||||
if (!added.length) return;
|
||||
const join = (session, id) => {
|
||||
if (!(session.driverIds || []).includes(id)) session.driverIds = [...(session.driverIds || []), id];
|
||||
if (Array.isArray(session.manualGridIds) && !session.manualGridIds.includes(id)) session.manualGridIds = [...session.manualGridIds, id];
|
||||
};
|
||||
const keep = new Set(beforeIds.filter((id) => !removed.has(id)));
|
||||
pending.filter((session) => session.type === "practice" && [...keep].every((id) => (session.driverIds || []).includes(id)))
|
||||
.forEach((session) => added.forEach((id) => join(session, id)));
|
||||
const heats = pending.map((session) => ({ session, parsed: parseQualifyingHeatName(session.name) })).filter((item) => item.parsed);
|
||||
added.forEach((id) => {
|
||||
if (!heats.length) return;
|
||||
const size = (heat) => heats.filter((item) => item.parsed.heat === heat).reduce((max, item) => Math.max(max, (item.session.driverIds || []).length), 0);
|
||||
const heatNumbers = [...new Set(heats.map((item) => item.parsed.heat))].sort((a, b) => size(a) - size(b) || a - b);
|
||||
heats.filter((item) => item.parsed.heat === heatNumbers[0]).forEach((item) => join(item.session, id));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
export function getEventTeams(event, { normalizeRaceTeam }) {
|
||||
@@ -1114,3 +1144,26 @@ export function buildEventSchedule(event, sessions) {
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
// A changed race format reaches the sessions not run yet: when e.g. "qualifying time" goes
|
||||
// 5 -> 3 min, every ready practice/qualifying session gets 3 min. Only fields whose format
|
||||
// value changed are applied, so a heat edited by hand keeps its own other values.
|
||||
export function applyFormatToPendingSessions(sessions, before = {}, after = {}) {
|
||||
const fields = {
|
||||
practice: [["qualDurationMin", "durationMin"]],
|
||||
qualification: [["qualDurationMin", "durationMin"], ["qualStartMode", "startMode"], ["followUpSec", "followUpSec"], ["qualSeedLapCount", "seedBestLapCount"], ["qualSeedMethod", "seedMethod"]],
|
||||
final: [["finalDurationMin", "durationMin"], ["finalStartMode", "startMode"], ["followUpSec", "followUpSec"]],
|
||||
};
|
||||
let changed = 0;
|
||||
sessions.forEach((session) => {
|
||||
if (session.status !== "ready" || session.startedAt) return;
|
||||
let touched = false;
|
||||
(fields[session.type] || []).forEach(([configKey, sessionKey]) => {
|
||||
if (after[configKey] === undefined || after[configKey] === before[configKey]) return;
|
||||
session[sessionKey] = after[configKey];
|
||||
touched = true;
|
||||
});
|
||||
if (touched) changed += 1;
|
||||
});
|
||||
return changed;
|
||||
}
|
||||
Reference in new issue
Block a user