diff options
author | Matt Kohls <mattkohls13@gmail.com> | 2023-10-17 17:10:13 -0400 |
---|---|---|
committer | Matt Kohls <mattkohls13@gmail.com> | 2023-10-17 17:10:13 -0400 |
commit | 8b7c8bf1e8ecbd6b9fa79a057752535d024e940c (patch) | |
tree | 2a48dcc2fe164c18b639d744c17e3d149c989fdf | |
parent | c8ef8843aaaf28bc38b544ae8ac72accf233aead (diff) | |
download | sensor-aggregator-8b7c8bf1e8ecbd6b9fa79a057752535d024e940c.tar.gz sensor-aggregator-8b7c8bf1e8ecbd6b9fa79a057752535d024e940c.tar.bz2 sensor-aggregator-8b7c8bf1e8ecbd6b9fa79a057752535d024e940c.zip |
Hotfixes
Minor tweaks based on things I noticed with real data
-rw-r--r-- | snag/data.py | 20 | ||||
-rw-r--r-- | snag/graphs.py | 87 |
2 files changed, 65 insertions, 42 deletions
diff --git a/snag/data.py b/snag/data.py index 3bf8df3..69f9849 100644 --- a/snag/data.py +++ b/snag/data.py @@ -6,11 +6,19 @@ from flask import ( Blueprint, flash, g, redirect, render_template, request, url_for, json ) from werkzeug.exceptions import abort -from datetime import datetime +from datetime import datetime, timedelta from snag.db import get_db +import time bp = Blueprint('data', __name__, url_prefix='/data') +# Temp dst function, should add this to database to track instead +def is_dst_aware(deviceId): + if (deviceId in [2]): + return False + else: + return True + # Process json data # # Expects something like this: @@ -43,6 +51,10 @@ def unpack_json_scheme_1(req): if 'status' in req: if 'timeStamp' in req['status'][0]: now = req['status'][0]['timeStamp'] + now = datetime.strptime(now, "%Y-%m-%dT%H:%M:%SZ") + if not is_dst_aware(deviceId) and time.daylight: + now = now + timedelta(hours=1) + now = now.strftime("%Y-%m-%d %H:%M:%S") else: now = datetime.now() battery = req['status'][0]['battery'] @@ -55,6 +67,10 @@ def unpack_json_scheme_1(req): humidity = environment['humidity'] pressure = environment['pressure'] now = environment['timeStamp'] + now = datetime.strptime(now, "%Y-%m-%dT%H:%M:%SZ") + if not is_dst_aware(deviceId) and time.daylight: + now = now + timedelta(hours=1) + now = now.strftime("%Y-%m-%d %H:%M:%S") if env == 'outdoor': lux = environment['lux'] uv = environment['uv'] @@ -102,7 +118,7 @@ def get_devices(): for env in envs: envDict = { "environment" : env["environment"], - # "environmentDesc" : env["environmentDescription"] + "environmentDesc" : env["environmentDescription"] } envList.append(envDict) deviceLine = { 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") |