diff options
Diffstat (limited to 'snag/graphs.py')
-rw-r--r-- | snag/graphs.py | 87 |
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") |