aboutsummaryrefslogtreecommitdiffstats
path: root/snag/graphs.py
diff options
context:
space:
mode:
authorMatt Kohls <mattkohls13@gmail.com>2023-10-17 17:10:13 -0400
committerMatt Kohls <mattkohls13@gmail.com>2023-10-17 17:10:13 -0400
commit8b7c8bf1e8ecbd6b9fa79a057752535d024e940c (patch)
tree2a48dcc2fe164c18b639d744c17e3d149c989fdf /snag/graphs.py
parentc8ef8843aaaf28bc38b544ae8ac72accf233aead (diff)
downloadsensor-aggregator-8b7c8bf1e8ecbd6b9fa79a057752535d024e940c.tar.gz
sensor-aggregator-8b7c8bf1e8ecbd6b9fa79a057752535d024e940c.tar.bz2
sensor-aggregator-8b7c8bf1e8ecbd6b9fa79a057752535d024e940c.zip
Hotfixes
Minor tweaks based on things I noticed with real data
Diffstat (limited to 'snag/graphs.py')
-rw-r--r--snag/graphs.py87
1 files changed, 47 insertions, 40 deletions
diff --git a/snag/graphs.py b/snag/graphs.py
index 2905d20..2f4966c 100644
--- a/snag/graphs.py
+++ b/snag/graphs.py
@@ -57,7 +57,7 @@ def get_current(requestArgs, columns, table):
sql = (f"SELECT {columns} "
f"FROM {table} "
"WHERE (date BETWEEN ? AND ?) AND deviceId = ?")
- subset = db.execute(sql, [starttime, endtime, deviceId])
+ subset = db.execute(sql, [starttime.isoformat(" ", "seconds"), endtime.isoformat(" ", "seconds"), deviceId])
else:
subset = None
@@ -146,12 +146,13 @@ def draw_t_graph():
abort(404, "Data not found")
for row in data:
- if isinstance(row['date'], str):
- dates.append(parser.parse(row['date']))
- else:
- dates.append(row['date'])
- tempsC.append(row['temperature'])
- tempsF.append(row['temperature'] * 1.8 + 32)
+ if row['humidity'] is not None:
+ if isinstance(row['date'], str):
+ dates.append(parser.parse(row['date']))
+ else:
+ dates.append(row['date'])
+ tempsC.append(row['temperature'])
+ tempsF.append(row['temperature'] * 1.8 + 32)
buf = double_y_graph(dates, tempsC, tempsF, "Timestamps", "Celsius", "Fahrenheit", "Temperature", "C1")
@@ -172,11 +173,12 @@ def draw_h_graph():
abort(404, "Data not found")
for row in data:
- if isinstance(row['date'], str):
- dates.append(parser.parse(row['date']))
- else:
- dates.append(row['date'])
- humidities.append(row['humidity'])
+ if row['humidity'] is not None:
+ if isinstance(row['date'], str):
+ dates.append(parser.parse(row['date']))
+ else:
+ dates.append(row['date'])
+ humidities.append(row['humidity'])
buf = single_line_graph(dates, humidities, "Timestamps", "Percent", "Relative Humidity", "C0")
@@ -199,13 +201,14 @@ def draw_ht_graph():
abort(404, "Data not found")
for row in data:
- if isinstance(row['date'], str):
- dates.append(parser.parse(row['date']))
- else:
- dates.append(row['date'])
- # tempsC.append(row['temperature'])
- tempsF.append(row['temperature'] * 1.8 + 32)
- humidities.append(row['humidity'])
+ if row['temperature'] is not None and row['humidity'] is not None:
+ if isinstance(row['date'], str):
+ dates.append(parser.parse(row['date']))
+ else:
+ dates.append(row['date'])
+ # tempsC.append(row['temperature'])
+ tempsF.append(row['temperature'] * 1.8 + 32)
+ humidities.append(row['humidity'])
buf = double_line_graph(dates, humidities, tempsF, "Timestamps", "Percent", "Fahrenheit", "Humidity and Temperature", "C0", "C1", "Relative Humidity", "Temperature")
@@ -226,11 +229,12 @@ def draw_p_graph():
abort(404, "Data not found")
for row in data:
- if isinstance(row['date'], str):
- dates.append(parser.parse(row['date']))
- else:
- dates.append(row['date'])
- pressures.append(row['pressure'])
+ if row['pressure'] is not None:
+ if isinstance(row['date'], str):
+ dates.append(parser.parse(row['date']))
+ else:
+ dates.append(row['date'])
+ pressures.append(row['pressure'])
buf = single_line_graph(dates, pressures, "Timestamps", "hPa", "Barometric Pressure", "C2")
@@ -251,11 +255,12 @@ def draw_b_graph():
abort(404, "Data not found")
for row in data:
- if isinstance(row['date'], str):
- dates.append(parser.parse(row['date']))
- else:
- dates.append(row['date'])
- batteries.append(row['batteryCharge'])
+ if row['batteryCharge'] is not None:
+ if isinstance(row['date'], str):
+ dates.append(parser.parse(row['date']))
+ else:
+ dates.append(row['date'])
+ batteries.append(row['batteryCharge'])
buf = single_line_graph(dates, batteries, "Timestamps", "Volts", "Battery Voltage", "C3")
@@ -280,12 +285,13 @@ def draw_l_graph():
uv = []
lux = []
for row in data:
- if isinstance(row['date'], str):
- dates.append(parser.parse(row['date']))
- else:
- dates.append(row['date'])
- uv.append(row['uv_intensity'])
- lux.append(row['lux'])
+ if row['uv_intensity'] is not None and row['lux'] is not None:
+ if isinstance(row['date'], str):
+ dates.append(parser.parse(row['date']))
+ else:
+ dates.append(row['date'])
+ uv.append(row['uv_intensity'])
+ lux.append(row['lux'])
buf = double_line_graph(dates, uv, lux, "Timestamps", "UV Index", "Lux", "UV and Light Intensity", "C4", "C5", "UV Light", "Light Intensity")
@@ -303,11 +309,12 @@ def draw_l_graph():
dates = []
light = []
for row in data:
- if isinstance(row['date'], str):
- dates.append(parser.parse(row['date']))
- else:
- dates.append(row['date'])
- light.append(row['light'])
+ if row['light'] is not None:
+ if isinstance(row['date'], str):
+ dates.append(parser.parse(row['date']))
+ else:
+ dates.append(row['date'])
+ light.append(row['light'])
buf = single_line_graph(dates, light, "Timestamps", "Raw Light Reading", "Light Intensity", "C5")