From f771a707641acc546891d38d7169d8e8682f7989 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Piotr=20Moru=C5=9B?= Date: Tue, 11 May 2021 17:22:33 +0200 Subject: [PATCH 1/2] Fix DMXvalues reset to properly serialize zeros --- emulate/emulate_queue.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/emulate/emulate_queue.py b/emulate/emulate_queue.py index 56b0227..98d2594 100644 --- a/emulate/emulate_queue.py +++ b/emulate/emulate_queue.py @@ -140,12 +140,9 @@ def should_animate() -> bool: return is_time_between(cfg.animation_start_time, cfg.animation_end_time) def reset_dmx_values(): - dmx_values_zeros = list() - for i in range(5): - dmx_values_zeros.append(list()) - for j in range(28): - dmx_values_zeros[i].append([0, 0, 0]) - redis_db.set('DMXvalues', str(dmx_values_zeros)) + 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: From 2db6de1e7470080f41380bac9ab301725f02a05c Mon Sep 17 00:00:00 2001 From: Maciej Prostak Date: Tue, 11 May 2021 15:42:30 +0200 Subject: [PATCH 2/2] Refactor pep8 --- emulate/emulate_queue.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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')