From 2ef83236d0eb2fbf96626af0d560c04095807ed1 Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Tue, 21 Mar 2023 13:25:54 +0000 Subject: [PATCH] create lm2-hourly-totals.py script. This script does exactly the same as lm1-hourly-totals.py script but it processes and creates a line chart from the readings of Light Meter 2. --- lm2-hourly-totals.py | 59 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 lm2-hourly-totals.py diff --git a/lm2-hourly-totals.py b/lm2-hourly-totals.py new file mode 100644 index 0000000..2f2621c --- /dev/null +++ b/lm2-hourly-totals.py @@ -0,0 +1,59 @@ +from bokeh.plotting import figure, output_file, save, show +from bokeh.models import Legend, ColumnDataSource +import bokeh.palettes +import pandas as pd +import numpy as np +import random + +# Hour Slots, hardcoded to reduce duplicated processing of data. +x_vals = ["00", "01", "02", "03", "04", "05", + "06", "07", "08", "09", "10", "11", + "12", "13", "14", "15", "16", "17", + "18", "19", "20", "21", "22", "23", + "24"] +dates = [] +y_vals = [] +file_data = [] +for month in range(6, 8, 1) : + for day in range(1, 31, 1) : + if (day < 10) : + d = f"0{day}" + else : + d = day + if day < 13 and month == 6 : + print(f"Skipping: data/light-meter-2-hourly-totals/2021-0{month}/2012-0{month}-{d}.csv") + else : + file_path = f"data/light-meter-2-hourly-totals/2021-0{month}/2021-0{month}-{d}.csv" + single_file = pd.read_csv (file_path, sep="," ,header=None, + index_col=False, dtype='unicode') + dates.append(f"2021-0{month}-{d}") + file_data.append(single_file.values[1:]) + +p = figure(title="Total Hourly Reading for Light Meter 2 (Tony)", + x_axis_label="Hour", + y_axis_label="Total Readings", + sizing_mode="stretch_both") +p.axis.major_label_text_font_size = "12px" +p.axis.major_label_standoff = 10 + +def random_colour(): + r = random.randint(0,255) + g = random.randint(0,255) + b = random.randint(0,255) + rgb = [r,g,b] + return rgb + +for day in dates : + for row in file_data : + y_vals = [] + for data in row : + reading = data[1] + y_vals.append(reading) + p.line(x = np.asarray(x_vals).astype(str), + y = np.asarray(y_vals).astype(int), + # legend_label=f"{day}", + line_color=random_colour()) + +output_file("output/lm2-hourly-totals.html", + title="Total Hourly Reading for Light Meter 2") +save(p)