From af6fecbabd0442173dc6b075685677f3512614f2 Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Wed, 22 Mar 2023 00:28:21 +0000 Subject: [PATCH] create dailies-side-by-side.py script. I didn't mean to create this script. It takes the individual daily readings for a Light Meter and places each 'daily readings' next to each other, on the same graph. This is essentially stitching the full log of reading back together but with gaps between the individual charts. The gaps are formed, I think -- I haven't checked -- because the 'missing data' (when the factory was closed or no welding was happening) is being treated as such. I'm assuming it's because I've passed each 'daily line' as separate lines so Bokeh has no reason to join them together. This script makes a HTML chart for both Light Meters. And, the charts are slow and not very nice to deal with. I've only kept the script and the charts it produces because the charts look interesting as images and I want to see what Nic thinks. She might find them useful from an artistic perspective. --- dailies-side-by-side.py | 59 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 dailies-side-by-side.py diff --git a/dailies-side-by-side.py b/dailies-side-by-side.py new file mode 100644 index 0000000..721b8e2 --- /dev/null +++ b/dailies-side-by-side.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 +import glob +import os + +def random_colour(): + r = random.randint(0,255) + g = random.randint(0,255) + b = random.randint(0,255) + rgb = [r,g,b] + return rgb + +def generate_charts (meter_num) : + if (meter_num == 1) : + fig_title = f"Daily Readings for Light Meter 1 (Andy)" + else : + fig_title = f"Daily Readings for Light Meter 2 (Tony)" + + 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 + + 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] + + 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) + + p.line(x = x_vals, + y = y_vals, + line_width = 2, + line_color = random_colour()) + + output_file(f"output/lm{meter_num}-daily-side-by-side.html", + title=f"Light Meter 1 Daily Overlayed") + save(p) + +print("Generating charts for Light Meter 1...") +generate_charts(1) +print("Generating charts for Light Meter 2...") +generate_charts(2)