Browse Source

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.
master
Craig Oates 1 year ago
parent
commit
2ef83236d0
  1. 59
      lm2-hourly-totals.py

59
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)
Loading…
Cancel
Save