From 812490cab64a12e4290caeb495bf0c672a7a521f Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Wed, 22 Mar 2023 00:05:36 +0000 Subject: [PATCH] rename lm1-dailies.py to daily-breakdows.py and process all dailies. The script now processes all the daily files for both Light Meters. Each day, for each Light Meter, has their own chart (HTML) made as the output of the script. --- daily-breakdowns.py | 55 +++++++++++++++++++++++++++++++++++++++++++++ lm1-dailies.py | 40 --------------------------------- 2 files changed, 55 insertions(+), 40 deletions(-) create mode 100644 daily-breakdowns.py delete mode 100644 lm1-dailies.py diff --git a/daily-breakdowns.py b/daily-breakdowns.py new file mode 100644 index 0000000..98aab98 --- /dev/null +++ b/daily-breakdowns.py @@ -0,0 +1,55 @@ +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 +import glob +import os + +def generate_charts (meter_num) : + files = glob.glob(f"data/light-meter-{meter_num}/*.csv") + for file_path in files : + single_file = pd.read_csv (file_path, sep="," ,header=None, + index_col=False, dtype='unicode') + file_data = single_file.values[1:] + file_name = os.path.splitext(os.path.basename(file_path))[0] + + if (meter_num == 1) : + fig_title = f"Readings for Light Meter 1 (Andy) on {file_name}" + else : + fig_title = f"Readings for Light Meter 2 (Tony) on {file_name}" + + p = figure(title = fig_title, + x_axis_label = "Date", + y_axis_label = "Light Reading", + x_axis_type = 'datetime', + sizing_mode = "stretch_both") + p.axis.major_label_text_font_size = "12px" + p.axis.major_label_standoff = 10 + # p.yaxis.fixed_location = 0 + + x_raw_vals = [] + y_raw_vals = [] + for row in file_data : + x_raw_vals.append(row[0]) + y_raw_vals.append(row[1]) + + x_vals = pd.to_datetime(x_raw_vals) + y_vals = np.asarray(y_raw_vals).astype(int) + + if (meter_num == 1) : + color = "blue" + else : + color = "orange" + + p.line(x = x_vals, y = y_vals, line_width = 2, line_color = color) + + output_file(f"output/lm{meter_num}-{file_name}.html", + title=f"Light Meter 1: {file_name}") + save(p) + +print("Generating charts for Light Meter 1...") +generate_charts(1) +print("Generating charts for Light Meter 2...") +generate_charts(2) diff --git a/lm1-dailies.py b/lm1-dailies.py deleted file mode 100644 index 37bfdb5..0000000 --- a/lm1-dailies.py +++ /dev/null @@ -1,40 +0,0 @@ -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 - -def random_colour(): - r = random.randint(0,255) - g = random.randint(0,255) - b = random.randint(0,255) - rgb = [r,g,b] - return rgb - -file_path = "data/light-meter-1/2021-06-17.csv" -single_file = pd.read_csv (file_path, sep="," ,header=None, - index_col=False, dtype='unicode') -file_data = single_file.values[1:] -# print(file_data) - -p = figure(title="Readings for Light Meter 1 (Andy) on INSERT DATE HERE", - x_axis_label="Date", - y_axis_label="Reading", - x_axis_type='datetime', - sizing_mode="stretch_both") -p.axis.major_label_text_font_size = "12px" -p.axis.major_label_standoff = 10 - -x_raw_vals = [] -y_vals = [] -for row in file_data : - x_raw_vals.append(row[0]) - y_vals.append(row[1]) - -x_vals = pd.to_datetime(x_raw_vals) -p.line(x = x_vals, y = y_vals, line_width = 2) - -output_file("output/lm1-INSERT-DATE-HERE.html", - title="Light Meter 1: INSERT DATE HERE") -save(p)