From c73f5b2d2542d7bfa332ab70d6323e79f93cae2f Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Sun, 9 May 2021 00:19:07 +0100 Subject: [PATCH] add fix to stop duplicating entries in find_readings_with_lights_on. The function was originally looping through the set of readings for a particular time-stamp. If there was more than one reading above 39, it would append that particular time-stamp every time the if-statement was true -- as it looped through each reading for said time-stamp. This change adds a break and a variable to track if the time-stamp should be added to the list -- after it has broke out of the if-block. --- src/services/data_services.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/services/data_services.py b/src/services/data_services.py index 022e74a..707bd04 100644 --- a/src/services/data_services.py +++ b/src/services/data_services.py @@ -36,9 +36,15 @@ def find_flickers(selected_readings, all_readings): def find_readings_with_lights_on(flicker_entries): filtered_readings = list() + add_to_list = False for time, reading in flicker_entries.items(): for item in reading: val = int(item) if (val > 39): - filtered_readings.append( (time, reading) ) + add_to_list = True + break + else: + add_to_list = False + if (add_to_list == True): + filtered_readings.append( (time, reading) ) return filtered_readings