Skip to content
Snippets Groups Projects
Commit 755aba8f authored by David Trattnig's avatar David Trattnig
Browse files

refactor: make next ts method window aware

parent bf2b1a08
No related branches found
No related tags found
1 merge request!35ORM-less scheduling
......@@ -205,17 +205,30 @@ class TimetableService:
return current_timeslot
def get_next_timeslots(self, max_count: int = 0) -> [Timeslot]:
def get_next_timeslots(self, max_count: int = 0, window_aware=False) -> [Timeslot]:
"""
Retrieve the timeslots to be played after the current one.
The method allows to return only a max count of timeslots. Also, timeslots which are
not within the scheduling window can be optionally omitted.
The scheduling window behaviour has these effects, when scheduling timeslots:
- Before the scheduling window: Timeslots can still be deleted in Steering and the
playout will respect this.
- During the scheduling window: Timeslots and it's playlists are queued as timed
commands.
- After the scheduling window: Such timeslots are ignored, because it doesn't make
sense anymore to schedule them before the next timeslot starts.
Args:
max_count (Integer): Maximum of timeslots to return. If `0` is passed, all existing
ones are returned.
window_aware (bool): If set to true, only timeslots within the scheduling window are
returned.
Returns:
([Timeslot]): The upcoming timeslots.
"""
now = Engine.engine_time()
next_timeslots = []
......@@ -223,12 +236,24 @@ class TimetableService:
if not self.timetable:
return []
for timeslot in self.timetable:
if timeslot.get_start() > now:
if (len(next_timeslots) < max_count) or max_count == 0:
next_timeslots.append(timeslot)
ts: Timeslot
for ts in self.timetable:
if ts.get_start() > now:
in_window = self.is_timeslot_in_window(ts)
if not window_aware or in_window:
if (len(next_timeslots) < max_count) or max_count == 0:
next_timeslots.append(ts)
else:
break
else:
break
start = SU.fmt_time(ts.get_start())
end = SU.fmt_time(ts.get_end())
t1: int = self.config.get("scheduling_window_start")
t2: int = self.config.get("scheduling_window_end")
msg = f"Skip timeslot #{ts.get_id()} [{start} - {end}] "
msg += f"- not in scheduling window T¹-{t1}s to T²-{t2}s"
self.logger.info(msg)
print(msg)
return next_timeslots
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment