From 84168c4a6a7e53931543d71be277af0aa698d6f9 Mon Sep 17 00:00:00 2001 From: mattbk Date: Fri, 17 Nov 2017 18:15:19 +0000 Subject: [PATCH 1/6] Temporarily remove timezone conversion to improve speed. --- pi_temp.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pi_temp.py b/pi_temp.py index b5f90c9..9e58b76 100755 --- a/pi_temp.py +++ b/pi_temp.py @@ -78,12 +78,12 @@ def history(): time_series_humidity_values = [] for record in temperatures: - local_timedate_series = arrow.get(record[0], "YYYY-MM-DD HH:mm").to(timezone) + local_timedate_series = arrow.get(record[0], "YYYY-MM-DD HH:mm") time_series_adjusted_temperatures.append(local_timedate_series.format('YYYY-MM-DD HH:mm')) time_series_temperature_values.append(round(record[2],2)) for record in humidities: - local_timedate_series = arrow.get(record[0], "YYYY-MM-DD HH:mm").to(timezone) + local_timedate_series = arrow.get(record[0], "YYYY-MM-DD HH:mm") time_series_adjusted_humidities.append(local_timedate_series.format('YYYY-MM-DD HH:mm')) #Best to pass datetime in text #so that Plotly respects it time_series_humidity_values.append(round(record[2],2)) From 4bb3bccd24f9e987f1b8852ff99b754a689897f2 Mon Sep 17 00:00:00 2001 From: mattbk Date: Fri, 17 Nov 2017 19:48:28 +0000 Subject: [PATCH 2/6] Shelve. --- pi_temp.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pi_temp.py b/pi_temp.py index 9e58b76..d31076f 100755 --- a/pi_temp.py +++ b/pi_temp.py @@ -77,8 +77,9 @@ def history(): time_series_temperature_values = [] time_series_humidity_values = [] + local_timedate_series = [arrow.get(record[0], "YYYY-MM-DD HH:mm").to(timezone) for record in temperatures] for record in temperatures: - local_timedate_series = arrow.get(record[0], "YYYY-MM-DD HH:mm") + #local_timedate_series = arrow.get(record[0], "YYYY-MM-DD HH:mm") time_series_adjusted_temperatures.append(local_timedate_series.format('YYYY-MM-DD HH:mm')) time_series_temperature_values.append(round(record[2],2)) From 536ade30e5c2cb58dba419a51b2b788c8abbf2a6 Mon Sep 17 00:00:00 2001 From: mattbk Date: Fri, 17 Nov 2017 22:11:56 +0000 Subject: [PATCH 3/6] Shelve. --- pi_temp.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/pi_temp.py b/pi_temp.py index d31076f..9b1b316 100755 --- a/pi_temp.py +++ b/pi_temp.py @@ -68,6 +68,12 @@ def lab_temp(): return render_template("no_sensor.html") @app.route("/history", methods=['GET']) #Add date limits in the URL #Arguments: from=2015-03-04&to=2015-03-05 +def change_tz(record): + local_timedate_series = arrow.get(record[0], "YYYY-MM-DD HH:mm").to(timezone) + time_series_adjusted_temperatures.append(local_timedate_series.format('YYYY-MM-DD HH:mm')) + time_series_temperature_values.append(round(record[2],2)) + return {'time':time_series_adjusted_temperatures,'value':time_series_temperature_values} #this is a dict + def history(): temperatures, humidities, timezone, from_date_str, to_date_str = get_records() @@ -77,11 +83,12 @@ def history(): time_series_temperature_values = [] time_series_humidity_values = [] - local_timedate_series = [arrow.get(record[0], "YYYY-MM-DD HH:mm").to(timezone) for record in temperatures] - for record in temperatures: + local_timedate_series = [change_tz(x) for x in temperatures] + + #for record in temperatures: #local_timedate_series = arrow.get(record[0], "YYYY-MM-DD HH:mm") - time_series_adjusted_temperatures.append(local_timedate_series.format('YYYY-MM-DD HH:mm')) - time_series_temperature_values.append(round(record[2],2)) + #time_series_adjusted_temperatures.append(local_timedate_series.format('YYYY-MM-DD HH:mm')) + #time_series_temperature_values.append(round(record[2],2)) for record in humidities: local_timedate_series = arrow.get(record[0], "YYYY-MM-DD HH:mm") @@ -91,8 +98,8 @@ def history(): temp = Scatter( - x=time_series_adjusted_temperatures, - y=time_series_temperature_values, + x=local_timedate_series['time'], + y=local_timedate_series['value'], name='Temperature', mode='lines', line=Line(color='red') From 67a854c474674cb63309e1ca33857732a05d1ea3 Mon Sep 17 00:00:00 2001 From: mattbk Date: Fri, 17 Nov 2017 22:51:34 +0000 Subject: [PATCH 4/6] Fix conflicts. --- pi_temp.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pi_temp.py b/pi_temp.py index 9b1b316..c3d4e93 100755 --- a/pi_temp.py +++ b/pi_temp.py @@ -83,12 +83,10 @@ def history(): time_series_temperature_values = [] time_series_humidity_values = [] - local_timedate_series = [change_tz(x) for x in temperatures] - - #for record in temperatures: - #local_timedate_series = arrow.get(record[0], "YYYY-MM-DD HH:mm") - #time_series_adjusted_temperatures.append(local_timedate_series.format('YYYY-MM-DD HH:mm')) - #time_series_temperature_values.append(round(record[2],2)) + for record in temperatures: + local_timedate_series = arrow.get(record[0], "YYYY-MM-DD HH:mm") + time_series_adjusted_temperatures.append(local_timedate_series.format('YYYY-MM-DD HH:mm')) + time_series_temperature_values.append(round(record[2],2)) for record in humidities: local_timedate_series = arrow.get(record[0], "YYYY-MM-DD HH:mm") From 07be441922f6b0cb391e653b0e05e1e811a5c0b1 Mon Sep 17 00:00:00 2001 From: mattbk Date: Fri, 17 Nov 2017 22:55:32 +0000 Subject: [PATCH 5/6] Ugh. --- pi_temp.py | 48 +++++++++++++++++++++--------------------------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/pi_temp.py b/pi_temp.py index c3d4e93..b74159b 100755 --- a/pi_temp.py +++ b/pi_temp.py @@ -68,15 +68,9 @@ def lab_temp(): return render_template("no_sensor.html") @app.route("/history", methods=['GET']) #Add date limits in the URL #Arguments: from=2015-03-04&to=2015-03-05 -def change_tz(record): - local_timedate_series = arrow.get(record[0], "YYYY-MM-DD HH:mm").to(timezone) - time_series_adjusted_temperatures.append(local_timedate_series.format('YYYY-MM-DD HH:mm')) - time_series_temperature_values.append(round(record[2],2)) - return {'time':time_series_adjusted_temperatures,'value':time_series_temperature_values} #this is a dict - def history(): temperatures, humidities, timezone, from_date_str, to_date_str = get_records() - + # Create new record tables so that datetimes are adjusted back to the user browser's time zone. time_series_adjusted_temperatures = [] time_series_adjusted_humidities = [] @@ -96,32 +90,32 @@ def history(): temp = Scatter( - x=local_timedate_series['time'], - y=local_timedate_series['value'], - name='Temperature', - mode='lines', - line=Line(color='red') - ) + x=local_timedate_series, + y=time_series_temperature_values, + name='Temperature', + mode='lines', + line=Line(color='red') + ) hum = Scatter( - x=time_series_adjusted_humidities, - y=time_series_humidity_values, - name='Humidity', - line=Line(color='aqua') - ) + x=time_series_adjusted_humidities, + y=time_series_humidity_values, + name='Humidity', + line=Line(color='aqua') + ) data = Data([temp, hum]) layout = Layout( title="Temperature and Humidity", - xaxis=XAxis( - type='date', - autorange=True - ), - yaxis=YAxis( - title='Fahrenheit / Percent', - type='linear', - autorange=True - ), + xaxis=XAxis( + type='date', + autorange=True + ), + yaxis=YAxis( + title='Fahrenheit / Percent', + type='linear', + autorange=True + ), ) fig = Figure(data=data, layout=layout) From 0b98b2d2a710da1415c8602df39418d5b57ca87c Mon Sep 17 00:00:00 2001 From: mattbk Date: Fri, 17 Nov 2017 22:57:54 +0000 Subject: [PATCH 6/6] Fix. --- pi_temp.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pi_temp.py b/pi_temp.py index b74159b..172a767 100755 --- a/pi_temp.py +++ b/pi_temp.py @@ -71,6 +71,7 @@ def lab_temp(): def history(): temperatures, humidities, timezone, from_date_str, to_date_str = get_records() + # Create new record tables so that datetimes are adjusted back to the user browser's time zone. time_series_adjusted_temperatures = [] time_series_adjusted_humidities = [] @@ -90,7 +91,7 @@ def history(): temp = Scatter( - x=local_timedate_series, + x=time_series_adjusted_temperatures, y=time_series_temperature_values, name='Temperature', mode='lines',