diff --git a/emulate/emulate_queue.py b/emulate/emulate_queue.py index 98d2594..43e5878 100644 --- a/emulate/emulate_queue.py +++ b/emulate/emulate_queue.py @@ -41,7 +41,7 @@ class UserCodeException(BaseException): class NoCodeInDatabaseException(BaseException): - """Exception when there is no code in databae""" + """Exception when there is no code in database""" def check_process(process) -> None: @@ -120,13 +120,15 @@ def retrieve_next_animation() -> Code: random_pk = random.choice(pk_list) return Code.objects.get(pk=random_pk) + def is_time_between(begin_time, end_time, check_time=None) -> bool: check_time = check_time or datetime.now().time() if begin_time < end_time: - return check_time >= begin_time and check_time <= end_time + return begin_time <= check_time <= end_time else: # crosses midnight return check_time >= begin_time or check_time <= end_time + def should_animate() -> bool: cfg = Config.objects.first() if cfg is None: @@ -139,11 +141,13 @@ def should_animate() -> bool: return True return is_time_between(cfg.animation_start_time, cfg.animation_end_time) + def reset_dmx_values(): - number_of_values = 5 * 28 * 3 # 5 rows, 28 columns, 3 color values + number_of_values = 5 * 28 * 3 # 5 rows, 28 columns, 3 color values serialized = ",".join("0" * number_of_values) redis_db.set('DMXvalues', serialized) + def main(): while True: logging.info(f'Running code for {CODE_EMULATION_WAIT_TIME_SECONDS} seconds')