feat(race-day): call the next heat - asked by hand, automatic with the autopilot (1.51.0)
This commit is contained in:
1 parent
fdc6c179dc
commit
b2e08db3d8
15 files changed
+178
-31
No files matched your search
@@ -4,14 +4,16 @@
|
||||
import { applyManualOrder, orderSessionsForRunning, parseQualifyingHeatName } from "./event_race_logic.js";
|
||||
|
||||
export const DEFAULT_DAY_GAP_MIN = 3;
|
||||
export const HEADS_UP_MS = 10 * 60000;
|
||||
export const DEFAULT_CALL_MIN = 10;
|
||||
|
||||
// One plan per date: { date, startAt, gapMin, sessionOrder, autopilot, pausedAt }.
|
||||
// One plan per date: { date, startAt, gapMin, callMin, sessionOrder, autopilot, pausedAt }.
|
||||
// callMin = how long before its start a heat is called (drivers get ready).
|
||||
export function normalizeRaceDay(day = {}) {
|
||||
return {
|
||||
date: String(day.date || ""),
|
||||
startAt: Number(day.startAt) > 0 ? Number(day.startAt) : null,
|
||||
gapMin: Number.isFinite(Number(day.gapMin)) && day.gapMin !== null && day.gapMin !== "" ? Math.max(0, Number(day.gapMin)) : DEFAULT_DAY_GAP_MIN,
|
||||
callMin: Number(day.callMin) > 0 ? Math.min(60, Number(day.callMin)) : DEFAULT_CALL_MIN,
|
||||
sessionOrder: [...new Set((Array.isArray(day.sessionOrder) ? day.sessionOrder : []).map(String).filter(Boolean))],
|
||||
autopilot: day.autopilot === true,
|
||||
pausedAt: Number(day.pausedAt) > 0 ? Number(day.pausedAt) : null,
|
||||
@@ -142,3 +144,11 @@ export function pickBoardDate({ events = [], sessions = [], today }) {
|
||||
.sort();
|
||||
return pending[0] || today;
|
||||
}
|
||||
|
||||
// The next heat to call: the first one not yet called that starts within callMin. A heat the
|
||||
// race controller put off ("Later") is skipped until snoozedUntil(sessionId) has passed.
|
||||
export function getDueCall(rows, { day, now = Date.now(), snoozedUntil = () => 0 }) {
|
||||
if (day?.pausedAt) return null;
|
||||
const callMs = Math.max(1, Number(day?.callMin || DEFAULT_CALL_MIN)) * 60000;
|
||||
return rows.find((row) => row.state === "upcoming" && !row.session.calledAt && row.start - now <= callMs && Number(snoozedUntil(row.session.id) || 0) <= now) || null;
|
||||
}
|
||||
Reference in new issue
Block a user