From 2b188237bb132e6409917abaf6b0714d4c85213f Mon Sep 17 00:00:00 2001 From: mattbk Date: Tue, 28 Nov 2017 03:45:44 +0000 Subject: [PATCH 1/3] Only use increasing temperature values. --- pi_temp.py | 2 +- templates/history.html | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pi_temp.py b/pi_temp.py index 4df3649..db209a0 100755 --- a/pi_temp.py +++ b/pi_temp.py @@ -141,7 +141,7 @@ def history(): # Calculate streak lengths. Based on https://stackoverflow.com/a/33403822/2152245. def streak_lengths(x): # find the boundaries where numbers are not consecutive - boundaries = [i for i in range(1, len(x)) if x[i] < x[i-1]] + boundaries = [i for i in range(1, len(x)) if x[i] <= x[i-1]] # add the start and end boundaries boundaries = [0] + boundaries + [len(x)] # take the boundaries as pairwise slices diff --git a/templates/history.html b/templates/history.html index 7a34c6a..5678962 100755 --- a/templates/history.html +++ b/templates/history.html @@ -82,7 +82,9 @@
+
{{ debug }} +
-- 2.39.5 From e78148f3586658175cfe3698df9088105c8bc204 Mon Sep 17 00:00:00 2001 From: mattbk Date: Tue, 28 Nov 2017 04:01:26 +0000 Subject: [PATCH 2/3] Fix range_hours while we're at it. --- pi_temp.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pi_temp.py b/pi_temp.py index db209a0..666e196 100755 --- a/pi_temp.py +++ b/pi_temp.py @@ -189,10 +189,13 @@ def get_records(): to_date_utc = arrow_time_to.strftime("%Y-%m-%d %H:%M") from_date_str = arrow_time_from.to(timezone).strftime("%Y-%m-%d %H:%M") to_date_str = arrow_time_to.to(timezone).strftime("%Y-%m-%d %H:%M") + range_hours = range_h_int else: #Convert datetimes to UTC so we can retrieve the appropriate records from the database from_date_utc = arrow.get(from_date_obj, timezone).to('Etc/UTC').strftime("%Y-%m-%d %H:%M") to_date_utc = arrow.get(to_date_obj, timezone).to('Etc/UTC').strftime("%Y-%m-%d %H:%M") + difference = (arrow.get(to_date_obj, timezone) - arrow.get(from_date_obj, timezone)) + range_hours = (difference.total_seconds()) / 3600 conn = sqlite3.connect('pi_temp.db') curs = conn.cursor() @@ -202,7 +205,7 @@ def get_records(): humidities = curs.fetchall() conn.close() - return [temperatures, humidities, timezone, from_date_str, to_date_str, range_h_int] + return [temperatures, humidities, timezone, from_date_str, to_date_str, range_hours] def validate_date(d): try: -- 2.39.5 From 32cab451c19f54c35758b3a5ba4f99096f0a08b6 Mon Sep 17 00:00:00 2001 From: mattbk Date: Tue, 28 Nov 2017 04:13:39 +0000 Subject: [PATCH 3/3] Pass the date ranges again. --- pi_temp.py | 2 ++ templates/history.html | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pi_temp.py b/pi_temp.py index 666e196..7bc4081 100755 --- a/pi_temp.py +++ b/pi_temp.py @@ -135,6 +135,8 @@ def history(): graphJSON = graphJSON, total_minutes = sum(streak_minutes), range_hours = range_hours, + from_date = from_date_str, + to_date = to_date_str, debug = streak_minutes, ) diff --git a/templates/history.html b/templates/history.html index 5678962..a68fd00 100755 --- a/templates/history.html +++ b/templates/history.html @@ -58,7 +58,7 @@
- Live + Live
@@ -74,7 +74,7 @@
-
+
-- 2.39.5