From 7bfd06cf0380d0f26ff4cc9ccd4607009b0e353f Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Sat, 8 May 2021 19:27:03 +0100 Subject: [PATCH] implement find_flicker feature. This functions goes through the list of readings and forms a dictionary of time-stamps, with light readings beyond a specified readings-per-second threshold, and the reading for said time-stamp. The results are then saved to the specified file, using 'save_rps_totals' function. --- src/flicker.py | 14 ++++++++------ src/services/data_services.py | 22 ++++++++++++++-------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/flicker.py b/src/flicker.py index 48633e2..22df77f 100644 --- a/src/flicker.py +++ b/src/flicker.py @@ -4,21 +4,23 @@ from services import io_services, log_services, data_services # import pdb def main(): - raw_data_path = "data/test-data-lite.csv" + raw_data_path = "data/test-data.csv" rps_save_path = "data/results/readings-per-sec.csv" rps_above_thresh = "data/results/readings_above_threshold.csv" + flicker_list = "data/results/flicker_list.csv" raw_data = io_services.load_raw_data(raw_data_path) # log_services.print_list(raw_data) time_tallies = data_services.tally_readings_per_second(raw_data) # log_services.print_dictionary(time_tallies) rps_totals = data_services.total_count_for_each_reading_per_second(time_tallies) # log_services.print_dictionary(rps_totals) - # io_services.save_rps_totals(rps_totals, rps_save_path) - rps_above_two = data_services.get_rps_above(2, time_tallies) + io_services.save_rps_totals(rps_totals, rps_save_path) + rps_above_herz = data_services.get_rps_above(4, time_tallies) # log_services.print_list(rps_above_two) - io_services.save_rps_above_threshold(rps_above_two, rps_above_thresh) - # flicker_tallies = data_services.tally_flickers(rsp_above_two, raw_data) + io_services.save_rps_above_threshold(rps_above_herz, rps_above_thresh) + flicker_entries = data_services.find_flickers(rps_above_herz, raw_data) # log_services.print_dictionary(flicker_tallies) - + io_services.save_rps_totals(flicker_tallies, flicker_entries) + # filtered_flicker_entries = if __name__ == "__main__": main() diff --git a/src/services/data_services.py b/src/services/data_services.py index ad6b7d9..fc92db6 100644 --- a/src/services/data_services.py +++ b/src/services/data_services.py @@ -28,13 +28,19 @@ def get_rps_above(threshold, readings): times.append(k) return times -def tally_flickers(selected_readings, all_readings): +def find_flickers(selected_readings, all_readings): selected = dict() - log_services.print_list(selected_readings) - # for time in selected_readings: - - # for time in selected_readings: - # # print(f"Looking for {time}...") - # selected[time] = all_readings[time] - # # for k, v in all_readings.items(): + # log_services.print_list(selected_readings) + # print(all_readings[1]) + # print(type(all_readings[0])) + for current_selected_reading in selected_readings: + readings = list() + for current_reading in all_readings: + # print(f"Checking {item} is in {x}...") + if (current_selected_reading == current_reading[0]): + # selected[item] = x[1] + # print(f"Added {item}.") + # selected.append( (item, x[1]) ) + readings.append(current_reading[1]) + selected[current_selected_reading] = readings return selected