From dc05b3481d47e506bb02d61e8e9499c15f490139 Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Sat, 8 May 2021 00:01:37 +0100 Subject: [PATCH] create flicker.py and csv parsing code. The code in this file is mostly to get the ball moving in this repository. This file opens the 'light-meter-sample-readings-23-04-2021-ritherdon.csv' file and tallies-up the number of requests per second groups. After that, it writes the results to 23-04-2021-readings-per-sec.csv. As an example (to help explain), it counts and stores how many times the light meter (factory1) took a reading at the rate of two times per second. In this instance, there were 2955 instances of the light meter taking two readings per second. This roughly equates to 10% of the days readings was at a rate of two requests per second. 28% of the time the light meter was recording at four requests per second, 18% for one and 44% for three. --- src/flicker.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/flicker.py diff --git a/src/flicker.py b/src/flicker.py new file mode 100644 index 0000000..d04bc4b --- /dev/null +++ b/src/flicker.py @@ -0,0 +1,28 @@ +import csv +import datetime + +time_tallies = dict() +tally_totals = dict() + +with open("data/light-meter-sample-readings-23-04-2021-ritherdon.csv") as csv_file: + csv_reader = csv.reader(csv_file, delimiter=",") + for r in csv_reader: + if (r[1] != "Time Stamp"): + time_str = r[1] + if (time_str in time_tallies): + time_tallies[time_str] = (time_tallies[time_str]) + 1 + else: + time_tallies[time_str] = 1 + for r2 in time_tallies.values(): + if (r2 in tally_totals): + tally_totals[r2] = (tally_totals[r2]) + 1 + else: + tally_totals[r2] = 1 + #print(tally_totals) + print(tally_totals.items()) +with open("data/results/23-04-2021-readings-per-sec.csv", mode="w") as result: + wtr = csv.writer(result) + for k, v in tally_totals.items(): + print(f"{k}: {v}") + wtr.writerow([k,v]) +