From aa27dc8519a8ed6a7a9d3aa5dffb74c0d337a82c Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Tue, 21 Mar 2023 08:34:02 +0000 Subject: [PATCH] create daily-totals.py script. This script produces a line chart, using Bokeh, displaying the daily totals for both Light Meters. The data is process from /data and the chart is written to the /output directory -- as a HTML file. --- daily-totals.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100755 daily-totals.py diff --git a/daily-totals.py b/daily-totals.py new file mode 100755 index 0000000..a215dcf --- /dev/null +++ b/daily-totals.py @@ -0,0 +1,44 @@ +from bokeh.plotting import figure, output_file, save, show +from bokeh.models import Legend +import pandas as pd +import numpy as np +from bokeh.models import ColumnDataSource + +x_vals = [] +y_vals = [] +file_data = pd.read_csv("data/light-meter-1-daily-totals.csv", sep=",", + header=None, index_col=False, dtype='unicode') +for row in file_data.values[1:] : + x_vals.append(row[0]) + y_vals.append(row[1]) + +x_vals2 = [] +y_vals2 = [] +file_data2 = pd.read_csv("data/light-meter-2-daily-totals.csv", sep=",", + header=None, index_col=False, dtype='unicode') +for row in file_data2.values[1:] : + x_vals2.append(row[0]) + y_vals2.append(row[1]) + +data = {'x_values': pd.to_datetime(x_vals), + 'y_values': np.asarray(y_vals).astype(int), + 'x_values2': pd.to_datetime(x_vals2), + 'y_values2': np.asarray(y_vals2).astype(int)} + +source = ColumnDataSource(data=data) + +p = figure(title="Total Daily Reading for Light Meters", + x_axis_label="Date", + y_axis_label="Total Readings", + x_axis_type='datetime', + sizing_mode="stretch_both") +p.axis.major_label_text_font_size = "12px" +p.axis.major_label_standoff = 10 + +p.line(x='x_values', y='y_values', source=source, + line_color="blue", legend_label="Light Meter 1 (Andy)") +p.line(x='x_values2', y='y_values2', source=source, + line_color="orange", legend_label="Light Meter 2 (Tony)") + +output_file("output/daily-totals.html") +save(p)