mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-15 12:23:51 +00:00
chore: rename offset to offsetAbs and offsetRel (#1706)
This commit is contained in:
committed by
Carlos Valente
parent
df137402cf
commit
bcf80f9d77
@@ -12,8 +12,8 @@ const baseState: RuntimeState = {
|
||||
runtime: {
|
||||
selectedEventIndex: null,
|
||||
numEvents: 0,
|
||||
offset: 0,
|
||||
relativeOffset: 0,
|
||||
offsetAbs: 0,
|
||||
offsetRel: 0,
|
||||
plannedStart: 0,
|
||||
plannedEnd: 0,
|
||||
actualStart: null,
|
||||
|
||||
@@ -185,26 +185,26 @@ describe('mutation on runtimeState', () => {
|
||||
expect(newState.runtime.plannedStart).toBe(0);
|
||||
expect(newState.runtime.plannedEnd).toBe(1500);
|
||||
expect(newState.blockNow).toBeNull();
|
||||
expect(newState.runtime.offset).toBe(0);
|
||||
expect(newState.runtime.offsetAbs).toBe(0);
|
||||
|
||||
// 2. Start event
|
||||
start();
|
||||
newState = getState();
|
||||
const firstStart = newState.clock;
|
||||
if (newState.runtime.offset === null) {
|
||||
if (newState.runtime.offsetAbs === null) {
|
||||
throw new Error('Value cannot be null at this stage');
|
||||
}
|
||||
|
||||
expect(newState.runtime.actualStart).toBe(newState.clock);
|
||||
expect(newState.runtime.offset).toBe(entries.event1.timeStart - newState.clock);
|
||||
expect(newState.runtime.expectedEnd).toBe(entries.event2.timeEnd - newState.runtime.offset);
|
||||
expect(newState.runtime.offsetAbs).toBe(entries.event1.timeStart - newState.clock);
|
||||
expect(newState.runtime.expectedEnd).toBe(entries.event2.timeEnd - newState.runtime.offsetAbs);
|
||||
|
||||
// 3. Next event
|
||||
load(entries.event2, rundown, metadata);
|
||||
start();
|
||||
|
||||
newState = getState();
|
||||
if (newState.runtime.actualStart === null || newState.runtime.offset === null) {
|
||||
if (newState.runtime.actualStart === null || newState.runtime.offsetAbs === null) {
|
||||
throw new Error('Value cannot be null at this stage');
|
||||
}
|
||||
|
||||
@@ -214,26 +214,26 @@ describe('mutation on runtimeState', () => {
|
||||
expect(forgivingActualStart).toBeLessThanOrEqual(1);
|
||||
// we are over-under, the difference between the schedule and the actual start
|
||||
const delayBefore = entries.event2.timeStart - newState.clock;
|
||||
expect(newState.runtime.offset).toBe(delayBefore);
|
||||
expect(newState.runtime.offsetAbs).toBe(delayBefore);
|
||||
// finish is the difference between the runtime and the schedule
|
||||
expect(newState.runtime.expectedEnd).toBe(entries.event2.timeEnd - newState.runtime.offset);
|
||||
expect(newState.runtime.expectedEnd).toBe(entries.event2.timeEnd - newState.runtime.offsetAbs);
|
||||
expect(newState.blockNow).toBeNull();
|
||||
|
||||
// 4. Add time
|
||||
addTime(10);
|
||||
newState = getState();
|
||||
if (newState.runtime.offset === null) {
|
||||
if (newState.runtime.offsetAbs === null) {
|
||||
throw new Error('Value cannot be null at this stage');
|
||||
}
|
||||
|
||||
expect(newState.runtime.offset).toBe(delayBefore - 10);
|
||||
expect(newState.runtime.expectedEnd).toBe(entries.event2.timeEnd - newState.runtime.offset);
|
||||
expect(newState.runtime.offsetAbs).toBe(delayBefore - 10);
|
||||
expect(newState.runtime.expectedEnd).toBe(entries.event2.timeEnd - newState.runtime.offsetAbs);
|
||||
|
||||
// 5. Stop event
|
||||
stop();
|
||||
newState = getState();
|
||||
expect(newState.runtime.actualStart).toBeNull();
|
||||
expect(newState.runtime.offset).toBe(0);
|
||||
expect(newState.runtime.offsetAbs).toBe(0);
|
||||
expect(newState.runtime.expectedEnd).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -325,7 +325,7 @@ describe('roll mode', () => {
|
||||
start();
|
||||
const result = roll(rundown, metadata);
|
||||
expect(result).toStrictEqual({ eventId: '1', didStart: false });
|
||||
expect(getState().runtime.offset).toBe(1000);
|
||||
expect(getState().runtime.offsetAbs).toBe(1000);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -349,21 +349,21 @@ describe('roll mode', () => {
|
||||
load(rundown.entries[1] as PlayableEvent, rundown, metadata);
|
||||
start();
|
||||
// the current offset after manual play
|
||||
const currentOffset = getState().runtime.offset;
|
||||
let result = roll(rundown, metadata, getState().runtime.offset);
|
||||
const currentOffset = getState().runtime.offsetAbs;
|
||||
let result = roll(rundown, metadata, getState().runtime.offsetAbs);
|
||||
expect(result).toStrictEqual({ eventId: '1', didStart: false });
|
||||
// the current offset should be maintain by roll mode whn taking over from play
|
||||
expect(getState().runtime.offset).toBe(currentOffset);
|
||||
expect(getState().runtime.offsetAbs).toBe(currentOffset);
|
||||
|
||||
vi.setSystemTime('jan 1 00:00:01');
|
||||
result = roll(rundown, metadata, getState().runtime.offset);
|
||||
result = roll(rundown, metadata, getState().runtime.offsetAbs);
|
||||
expect(result).toStrictEqual({ eventId: '2', didStart: true });
|
||||
expect(getState().runtime.offset).toBe(1000);
|
||||
expect(getState().runtime.offsetAbs).toBe(1000);
|
||||
|
||||
vi.setSystemTime('jan 1 00:00:02');
|
||||
result = roll(rundown, metadata, getState().runtime.offset);
|
||||
result = roll(rundown, metadata, getState().runtime.offsetAbs);
|
||||
expect(result).toStrictEqual({ eventId: '3', didStart: true });
|
||||
expect(getState().runtime.offset).toBe(1000);
|
||||
expect(getState().runtime.offsetAbs).toBe(1000);
|
||||
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
@@ -91,8 +91,8 @@ export function clearEventData() {
|
||||
runtimeState.eventNow = null;
|
||||
runtimeState.eventNext = null;
|
||||
|
||||
runtimeState.runtime.offset = 0;
|
||||
runtimeState.runtime.relativeOffset = 0;
|
||||
runtimeState.runtime.offsetAbs = 0;
|
||||
runtimeState.runtime.offsetRel = 0;
|
||||
runtimeState.runtime.expectedEnd = null;
|
||||
runtimeState.runtime.selectedEventIndex = null;
|
||||
|
||||
@@ -117,8 +117,8 @@ export function clearState() {
|
||||
runtimeState.blockNext = null;
|
||||
runtimeState.nextFlag = null;
|
||||
|
||||
runtimeState.runtime.offset = 0;
|
||||
runtimeState.runtime.relativeOffset = 0;
|
||||
runtimeState.runtime.offsetAbs = 0;
|
||||
runtimeState.runtime.offsetRel = 0;
|
||||
runtimeState.runtime.actualStart = null;
|
||||
runtimeState.runtime.expectedEnd = null;
|
||||
runtimeState.runtime.selectedEventIndex = null;
|
||||
@@ -214,9 +214,9 @@ export function load(
|
||||
const firstStart = initialData?.firstStart;
|
||||
if (firstStart === null || typeof firstStart === 'number') {
|
||||
runtimeState.runtime.actualStart = firstStart;
|
||||
const { absoluteOffset, relativeOffset } = getRuntimeOffset(runtimeState);
|
||||
runtimeState.runtime.offset = absoluteOffset;
|
||||
runtimeState.runtime.relativeOffset = relativeOffset;
|
||||
const { offsetAbs, offsetRel } = getRuntimeOffset(runtimeState);
|
||||
runtimeState.runtime.offsetAbs = offsetAbs;
|
||||
runtimeState.runtime.offsetRel = offsetRel;
|
||||
runtimeState.runtime.expectedEnd = getExpectedEnd(runtimeState);
|
||||
}
|
||||
if (typeof initialData.blockStartAt === 'number' && runtimeState.blockNow) {
|
||||
@@ -298,7 +298,7 @@ export function updateLoaded(event?: PlayableEvent): string | undefined {
|
||||
|
||||
// handle edge cases with roll
|
||||
if (runtimeState.timer.playback === Playback.Roll) {
|
||||
const offsetClock = runtimeState.clock + runtimeState.runtime.offset;
|
||||
const offsetClock = runtimeState.clock + runtimeState.runtime.offsetAbs;
|
||||
// if waiting to roll, we update the targets and potentially start the timer
|
||||
if (runtimeState._timer.secondaryTarget !== null) {
|
||||
if (runtimeState.eventNow.timeStart < offsetClock && offsetClock < runtimeState.eventNow.timeEnd) {
|
||||
@@ -385,9 +385,9 @@ export function start(state: RuntimeState = runtimeState): boolean {
|
||||
runtimeState.timer.phase = getTimerPhase(runtimeState);
|
||||
|
||||
// update offset
|
||||
const { absoluteOffset, relativeOffset } = getRuntimeOffset(runtimeState);
|
||||
runtimeState.runtime.offset = absoluteOffset;
|
||||
runtimeState.runtime.relativeOffset = relativeOffset;
|
||||
const { offsetAbs, offsetRel } = getRuntimeOffset(runtimeState);
|
||||
runtimeState.runtime.offsetAbs = offsetAbs;
|
||||
runtimeState.runtime.offsetRel = offsetRel;
|
||||
|
||||
// as long as there is a timer, we need an planned end
|
||||
// eslint-disable-next-line no-unused-labels -- dev code path
|
||||
@@ -397,7 +397,7 @@ export function start(state: RuntimeState = runtimeState): boolean {
|
||||
}
|
||||
}
|
||||
|
||||
state.runtime.expectedEnd = state.runtime.plannedEnd - state.runtime.offset;
|
||||
state.runtime.expectedEnd = state.runtime.plannedEnd - state.runtime.offsetAbs;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -457,9 +457,9 @@ export function addTime(amount: number) {
|
||||
runtimeState.timer.current += amount;
|
||||
|
||||
// update runtime delays: over - under
|
||||
const { absoluteOffset, relativeOffset } = getRuntimeOffset(runtimeState);
|
||||
runtimeState.runtime.offset = absoluteOffset;
|
||||
runtimeState.runtime.relativeOffset = relativeOffset;
|
||||
const { offsetAbs, offsetRel } = getRuntimeOffset(runtimeState);
|
||||
runtimeState.runtime.offsetAbs = offsetAbs;
|
||||
runtimeState.runtime.offsetRel = offsetRel;
|
||||
runtimeState.runtime.expectedEnd = getExpectedEnd(runtimeState);
|
||||
|
||||
return true;
|
||||
@@ -504,9 +504,9 @@ export function update(): UpdateResult {
|
||||
runtimeState.timer.elapsed = runtimeState.timer.duration - runtimeState.timer.current;
|
||||
|
||||
// update runtime, needs up-to-date timer state
|
||||
const { absoluteOffset, relativeOffset } = getRuntimeOffset(runtimeState);
|
||||
runtimeState.runtime.offset = absoluteOffset;
|
||||
runtimeState.runtime.relativeOffset = relativeOffset;
|
||||
const { offsetAbs, offsetRel } = getRuntimeOffset(runtimeState);
|
||||
runtimeState.runtime.offsetAbs = offsetAbs;
|
||||
runtimeState.runtime.offsetRel = offsetRel;
|
||||
runtimeState.runtime.expectedEnd = getExpectedEnd(runtimeState);
|
||||
|
||||
const finishedNow =
|
||||
@@ -541,7 +541,7 @@ export function update(): UpdateResult {
|
||||
}
|
||||
|
||||
// account for offset
|
||||
const offsetClock = runtimeState.clock + runtimeState.runtime.offset;
|
||||
const offsetClock = runtimeState.clock + runtimeState.runtime.offsetAbs;
|
||||
runtimeState.timer.phase = TimerPhase.Pending;
|
||||
|
||||
if (hasCrossedMidnight) {
|
||||
@@ -575,7 +575,7 @@ export function roll(
|
||||
}
|
||||
}
|
||||
|
||||
runtimeState.runtime.offset = offset;
|
||||
runtimeState.runtime.offsetAbs = offset;
|
||||
runtimeState.timer.playback = Playback.Roll;
|
||||
|
||||
// account for event that finishes the day after
|
||||
@@ -586,7 +586,7 @@ export function roll(
|
||||
runtimeState.timer.expectedFinish = normalisedEndTime;
|
||||
|
||||
//account for offset
|
||||
const offsetClock = runtimeState.clock + runtimeState.runtime.offset;
|
||||
const offsetClock = runtimeState.clock + runtimeState.runtime.offsetAbs;
|
||||
|
||||
// state catch up
|
||||
runtimeState.timer.duration = calculateDuration(runtimeState.eventNow.timeStart, normalisedEndTime);
|
||||
@@ -624,8 +624,8 @@ export function roll(
|
||||
clearEventData();
|
||||
|
||||
//account for offset but we only keep it if passed to us
|
||||
runtimeState.runtime.offset = offset;
|
||||
const offsetClock = runtimeState.clock + runtimeState.runtime.offset;
|
||||
runtimeState.runtime.offsetAbs = offset;
|
||||
const offsetClock = runtimeState.clock + runtimeState.runtime.offsetAbs;
|
||||
|
||||
const { index, isPending } = loadRoll(rundown, metadata, offsetClock);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user