feat(day): breaks between rounds, before the finals and before any heat (1.89.9)

This commit is contained in:
larssand committed 2026-11-12 21:36:28 +01:00
1 parent 5e4e77ca7b
commit daed2ff790
10 files changed
+114 -16

No files matched your search

+38
View File
@@ -84,3 +84,41 @@ test("a heat is due for its call within callMin, once, and not while put off or
assert.equal(getDueCall(rows, { day, now: start - 5 * 60000, snoozedUntil: () => start - 3 * 60000 }), null, "put off");
assert.equal(getDueCall(rows, { day: { ...day, pausedAt: 1 }, now: start }), null);
});
test("breaks: between heats, between rounds, before the finals (lunch) and an extra break before one heat", () => {
const start = new Date("2026-11-08T09:00:00").getTime();
const list = [
s("p1", "e2", "practice", "Practice 1"), s("p2", "e2", "practice", "Practice 2"),
s("q1", "e2", "qualification", "Q1 H1"), s("q2", "e2", "qualification", "Q1 H2"),
s("q3", "e2", "qualification", "Q2 H1"),
s("f1", "e2", "final", "B Final 1"), s("f2", "e2", "final", "A Final 1"),
];
const at = (plan, id) => (plan.find((row) => row.session.id === id).start - start) / 60000;
const day = { date: "2026-11-08", startAt: start, gapMin: 2, roundGapMin: 10, finalsGapMin: 45, breaks: { q3: 15 } };
const plan = buildDaySchedule(list, day, start - 3600000);
// 5-minute heats: p1 0, p2 7, round gap -> q1 22, q2 29, round gap + 15 extra -> q3 59, lunch -> f1 109, f2 116.
assert.deepEqual(list.map((x) => at(plan, x.id)), [0, 7, 22, 29, 59, 109, 116]);
assert.equal(plan.find((row) => row.session.id === "q3").breakMin, 25);
// Without round / finals gaps every break is the heat gap, as before.
const flat = buildDaySchedule(list, { date: "2026-11-08", startAt: start, gapMin: 2 }, start - 3600000);
assert.deepEqual(list.map((x) => at(flat, x.id)), [0, 7, 14, 21, 28, 35, 42]);
// No finals gap: the round gap is used before the finals.
const noLunch = buildDaySchedule(list, { ...day, finalsGapMin: null, breaks: {} }, start - 3600000);
assert.equal(at(noLunch, "f1") - at(noLunch, "q3"), 15);
});
test("finals created after a finished qualifier wait for the finals break, measured from the end of qualifying", () => {
const start = new Date("2026-11-08T09:00:00").getTime();
const qualEnd = start + 5 * 60000;
const list = [s("q1", "e2", "qualification", "Q1 H1", { status: "finished", startedAt: start, endedAt: qualEnd }), s("f1", "e2", "final", "A Final 1")];
const plan = buildDaySchedule(list, { date: "2026-11-08", startAt: start, gapMin: 2, finalsGapMin: 45 }, qualEnd + 20 * 60000);
assert.equal(plan[1].start, qualEnd + 45 * 60000, "finals made 20 min later still start 45 min after qualifying");
assert.equal(getAutopilotAction(plan, { day: {}, now: qualEnd + 20 * 60000 }).reason, "until");
});
test("race day plan keeps the round and finals gaps and drops empty breaks", () => {
const [day] = normalizeRaceDays([{ date: "2026-11-08", gapMin: 2, roundGapMin: "10", finalsGapMin: "", breaks: { q3: 15, q4: 0, "": 5 } }]);
assert.equal(day.roundGapMin, 10);
assert.equal(day.finalsGapMin, null);
assert.deepEqual(day.breaks, { q3: 15 });
});