From ca88c51bc9a06eab614364671b93eff56ed5bd82 Mon Sep 17 00:00:00 2001 From: David Trattnig <david.trattnig@o94.at> Date: Wed, 26 Aug 2020 14:53:13 +0200 Subject: [PATCH] Possiblity to limit count of next schedules. --- modules/scheduling/scheduler.py | 42 +++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/modules/scheduling/scheduler.py b/modules/scheduling/scheduler.py index 9088817e..1689dcef 100644 --- a/modules/scheduling/scheduler.py +++ b/modules/scheduling/scheduler.py @@ -320,6 +320,30 @@ class AuraScheduler(threading.Thread): return current_schedule + + def get_next_schedules(self, max_count=0): + """ + Retrieves the schedules to be played after the current one. + + Args: + max_count (Integer): Maximum of schedules to return, if `0` all exitsing ones are returned + Returns: + ([Schedule]): The next schedules + """ + now_unix = self.get_virtual_now() + next_schedules = [] + + for schedule in self.programme: + if schedule.start_unix > now_unix: + if (len(next_schedules) < max_count) or max_count == 0: + next_schedules.append(schedule) + else: + break + + return next_schedules + + + # FIXME Review relevance. def get_act_programme_as_string(self): """ @@ -561,24 +585,6 @@ class AuraScheduler(threading.Thread): - def get_next_schedules(self): - """ - Retrieves the schedules to be played after the current one. - - Returns: - ([Schedule]): The next schedules - """ - now_unix = self.get_virtual_now() - next_schedules = [] - - for schedule in self.programme: - if schedule.start_unix > now_unix: - next_schedules.append(schedule) - - return next_schedules - - - def filter_scheduling_window(self, schedules): """ Ignore schedules which are beyond the scheduling window. The end of the scheduling window -- GitLab