You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.6 KiB
81 lines
2.6 KiB
import csv |
|
import datetime |
|
from services import io_services, log_services |
|
# import pdb |
|
|
|
def tally_readings_per_second2(data): |
|
time_tallies = dict() |
|
for item in data: |
|
# print(item[0]) |
|
key = item[0] |
|
if (key in time_tallies): |
|
time_tallies[key] = time_tallies[key] + 1 |
|
# print(f"Updated {time_tallies[key]}") |
|
else: |
|
time_tallies[key] = 1 |
|
#print(f"Added {time_tallies[key]}") |
|
return time_tallies |
|
|
|
def tally_readings_per_second(): |
|
time_tallies = dict() |
|
with open("data/test-data-lite.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 |
|
return time_tallies |
|
|
|
def total_count_for_each_reading_per_second(time_tallies): |
|
tally_totals = dict() |
|
# print(time_tallies) |
|
for val in time_tallies.values(): |
|
if (val in tally_totals): |
|
tally_totals[val] = (tally_totals[val]) + 1 |
|
else: |
|
tally_totals[val] = 1 |
|
# print(tally_totals.items()) |
|
return tally_totals |
|
|
|
def save_rps_totals(totals): |
|
with open("data/results/readings-per-sec.csv", mode="w") as result: |
|
wtr = csv.writer(result) |
|
for k, v in totals.items(): |
|
# print(f"{k}: {v}") |
|
wtr.writerow([k,v]) |
|
|
|
def get_rps_above(threshold, readings): |
|
times = list() |
|
# print(readings.values()) |
|
for k, v in readings.items(): |
|
# print([k, v]) |
|
if (v >= threshold): |
|
times.append(k) |
|
return times |
|
|
|
def tally_flickers(selected_readings, all_readings): |
|
selected = dict() |
|
for time in selected_readings: |
|
# print(f"Looking for {time}...") |
|
selected[time] = all_readings[time] |
|
# for k, v in all_readings.items(): |
|
return selected |
|
|
|
def main(): |
|
# raw_data = load_data() |
|
# time_tallies = tally_readings_per_second2(raw_data) |
|
# # time_tallies = tally_readings_per_second() |
|
# rps_totals = total_count_for_each_reading_per_second(time_tallies) |
|
# save_rps_totals(rps_totals) |
|
# rsp_above_two = get_rps_above(2, time_tallies) |
|
# flicker_tallies = tally_flickers(rsp_above_two, time_tallies) |
|
raw_data = io_services.load_raw_data("data/test-data-lite.csv") |
|
# log_services.print_list(raw_data) |
|
time_tallies = tally_readings_per_second2(raw_data) |
|
log_services.print_dictionary(time_tallies) |
|
|
|
if __name__ == "__main__": |
|
main()
|
|
|