1
0
Fork 0
Browse Source

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.
stable
Craig Oates 3 years ago
parent
commit
dc05b3481d
  1. 28
      src/flicker.py

28
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])