Slots improvements. Fix rare bug in which some times the starting times would get completely messed up. Consecutive flex times are now guaranteed to be merged into a bigger one.

This commit is contained in:
vexorian 2021-03-26 09:59:00 -04:00
parent 91a5f6337e
commit 8d844f0ae3
3 changed files with 46 additions and 34 deletions

View File

@ -276,11 +276,11 @@ module.exports = async( programs, schedule ) => {
let s = schedule.slots;
let ts = (new Date() ).getTime();
let curr = ts - ts % DAY;
let t0 = ts;
let p = [];
let t = t0;
let wantedFinish = 0;
let hardLimit = t0 + schedule.maxDays * DAY;
let pushFlex = (d) => {
@ -297,6 +297,15 @@ module.exports = async( programs, schedule ) => {
}
}
let pushProgram = (item) => {
if ( item.isOffline && (item.type !== 'redirect') ) {
pushFlex(item.duration);
} else {
p.push(item);
t += item.duration;
}
};
let slotLastPlayed = {};
while ( (t < hardLimit) && (p.length < LIMIT) ) {
@ -338,15 +347,14 @@ module.exports = async( programs, schedule ) => {
if (item.isOffline) {
//flex or redirect. We can just use the whole duration
p.push(item);
t += remaining;
item.duration = remaining;
pushProgram(item);
slotLastPlayed[ slotIndex ] = t;
continue;
}
if (item.duration > remaining) {
// Slide
p.push(item);
t += item.duration;
pushProgram(item);
slotLastPlayed[ slotIndex ] = t;
advanceSlot(slot);
continue;
@ -412,8 +420,7 @@ module.exports = async( programs, schedule ) => {
}
// now unroll them all
for (let i = 0; i < pads.length; i++) {
p.push( pads[i].item );
t += pads[i].item.duration;
pushProgram( pads[i].item );
slotLastPlayed[ slotIndex ] = t;
pushFlex( pads[i].pad );
}
@ -421,15 +428,10 @@ module.exports = async( programs, schedule ) => {
while ( (t > hardLimit) || (p.length >= LIMIT) ) {
t -= p.pop().duration;
}
let m = t % schedule.period;
let rem = 0;
if (m > wantedFinish) {
rem = schedule.period + wantedFinish - m;
} else if (m < wantedFinish) {
rem = wantedFinish - m;
}
if (rem > constants.SLACK) {
pushFlex(rem);
let m = (t - t0) % schedule.period;
if (m != 0) {
//ensure the schedule is a multiple of period
pushFlex( schedule.period - m);
}

View File

@ -302,6 +302,15 @@ module.exports = async( programs, schedule ) => {
}
}
let pushProgram = (item) => {
if ( item.isOffline && (item.type !== 'redirect') ) {
pushFlex(item.duration);
} else {
p.push(item);
t += item.duration;
}
};
if (ts > t0) {
pushFlex( ts - t0 );
}
@ -355,14 +364,13 @@ module.exports = async( programs, schedule ) => {
if (item.isOffline) {
//flex or redirect. We can just use the whole duration
p.push(item);
t += remaining;
item.duration = remaining;
pushProgram(item);
continue;
}
if (item.duration > remaining) {
// Slide
p.push(item);
t += item.duration;
pushProgram(item);
advanceSlot(slot);
continue;
}
@ -373,7 +381,7 @@ module.exports = async( programs, schedule ) => {
let pads = [ padded ];
while(true) {
let item2 = getNextForSlot(slot);
let item2 = getNextForSlot(slot, remaining);
if (total + item2.duration > remaining) {
break;
}
@ -413,23 +421,17 @@ module.exports = async( programs, schedule ) => {
}
// now unroll them all
for (let i = 0; i < pads.length; i++) {
p.push( pads[i].item );
t += pads[i].item.duration;
pushProgram( pads[i].item );
pushFlex( pads[i].pad );
}
}
while ( (t > hardLimit) || (p.length >= LIMIT) ) {
t -= p.pop().duration;
}
let m = t % schedule.period;
let rem = 0;
if (m > wantedFinish) {
rem = schedule.period + wantedFinish - m;
} else if (m < wantedFinish) {
rem = wantedFinish - m;
}
if (rem > constants.SLACK) {
pushFlex(rem);
let m = (t - t0) % schedule.period;
if (m > 0) {
//ensure the schedule is a multiple of period
pushFlex( schedule.period - m);
}

View File

@ -163,7 +163,15 @@ module.exports = function ($timeout, $location, dizquetv, resolutionOptions, get
let t = Date.now();
let originalStart = scope.channel.startTime.getTime();
let n = scope.channel.programs.length;
let totalDuration = scope.channel.duration;
//scope.channel.totalDuration might not have been initialized
let totalDuration = 0;
for (let i = 0; i < n; i++) {
totalDuration += scope.channel.programs[i].duration;
}
if (totalDuration == 0) {
return;
}
let m = (t - originalStart) % totalDuration;
let x = 0;
let runningProgram = -1;