Miscellaneous fixes #36

Merged
mattbk merged 3 commits from fix-on into master 2017-11-27 22:15:59 -06:00
2 changed files with 11 additions and 4 deletions

View File

@ -135,13 +135,15 @@ def history():
graphJSON = graphJSON, graphJSON = graphJSON,
total_minutes = sum(streak_minutes), total_minutes = sum(streak_minutes),
range_hours = range_hours, range_hours = range_hours,
from_date = from_date_str,
to_date = to_date_str,
debug = streak_minutes, debug = streak_minutes,
) )
# Calculate streak lengths. Based on https://stackoverflow.com/a/33403822/2152245. # Calculate streak lengths. Based on https://stackoverflow.com/a/33403822/2152245.
def streak_lengths(x): def streak_lengths(x):
# find the boundaries where numbers are not consecutive # 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 # add the start and end boundaries
boundaries = [0] + boundaries + [len(x)] boundaries = [0] + boundaries + [len(x)]
# take the boundaries as pairwise slices # take the boundaries as pairwise slices
@ -189,10 +191,13 @@ def get_records():
to_date_utc = arrow_time_to.strftime("%Y-%m-%d %H:%M") 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") 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") to_date_str = arrow_time_to.to(timezone).strftime("%Y-%m-%d %H:%M")
range_hours = range_h_int
else: else:
#Convert datetimes to UTC so we can retrieve the appropriate records from the database #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") 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") 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') conn = sqlite3.connect('pi_temp.db')
curs = conn.cursor() curs = conn.cursor()
@ -202,7 +207,7 @@ def get_records():
humidities = curs.fetchall() humidities = curs.fetchall()
conn.close() 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): def validate_date(d):
try: try:

View File

@ -58,7 +58,7 @@
<div class="row"> <div class="row">
<div class="eleven columns"> <div class="eleven columns">
<div class="one column"> <div class="one column">
<a href="/">Live</a> <a href="/">Live</a>
</div> </div>
<form id="range_select" action = "/history" method="GET"> <form id="range_select" action = "/history" method="GET">
<input type="hidden" class="timezone" name="timezone" /> <input type="hidden" class="timezone" name="timezone" />
@ -82,7 +82,9 @@
<div class='row' id='plotly-plot'></div> <div class='row' id='plotly-plot'></div>
<div class='debug'>
{{ debug }} {{ debug }}
</div>
</body> </body>