fix: account for skip in rundown calculations

This commit is contained in:
Carlos Valente
2024-05-20 21:30:31 +02:00
committed by Carlos Valente
parent 7cefe07594
commit 036d4051fc
2 changed files with 18 additions and 14 deletions
@@ -161,12 +161,13 @@ describe('generate()', () => {
const testRundown: OntimeRundown = [ const testRundown: OntimeRundown = [
{ type: SupportedEvent.Event, id: '1', timeStart: 100, timeEnd: 200 } as OntimeEvent, { type: SupportedEvent.Event, id: '1', timeStart: 100, timeEnd: 200 } as OntimeEvent,
{ type: SupportedEvent.Event, id: '2', timeStart: 200, timeEnd: 300 } as OntimeEvent, { type: SupportedEvent.Event, id: '2', timeStart: 200, timeEnd: 300 } as OntimeEvent,
{ type: SupportedEvent.Event, id: '3', timeStart: 300, timeEnd: 400 } as OntimeEvent, { type: SupportedEvent.Event, id: 'skipped', skip: true, timeStart: 300, timeEnd: 400 } as OntimeEvent,
{ type: SupportedEvent.Event, id: '3', timeStart: 400, timeEnd: 500 } as OntimeEvent,
]; ];
const initResult = generate(testRundown); const initResult = generate(testRundown);
expect(initResult.order.length).toBe(3); expect(initResult.order.length).toBe(4);
expect(initResult.totalDuration).toBe(400 - 100); expect(initResult.totalDuration).toBe(500 - 100);
}); });
it('calculates total duration across days with gap', () => { it('calculates total duration across days with gap', () => {
@@ -102,6 +102,8 @@ export function generate(
// update the persisted event // update the persisted event
initialRundown[i] = updatedEvent; initialRundown[i] = updatedEvent;
// we need to generate the skip event, but dont want to use its times
if (!updatedEvent.skip) {
// update rundown duration // update rundown duration
if (firstStart === null) { if (firstStart === null) {
firstStart = updatedEvent.timeStart; firstStart = updatedEvent.timeStart;
@@ -115,12 +117,13 @@ export function generate(
daySpan++; daySpan++;
} }
} }
}
// calculate delays // calculate delays
// !!! this must happen after handling the links // !!! this must happen after handling the links
if (isOntimeDelay(updatedEvent)) { if (isOntimeDelay(updatedEvent)) {
accumulatedDelay += updatedEvent.duration; accumulatedDelay += updatedEvent.duration;
} else if (isOntimeEvent(updatedEvent)) { } else if (isOntimeEvent(updatedEvent) && !updatedEvent.skip) {
const eventStart = updatedEvent.timeStart; const eventStart = updatedEvent.timeStart;
// we only affect positive delays (time forwards) // we only affect positive delays (time forwards)