Calculate total furnace minutes in view.

This commit is contained in:
mattbk
2017-11-25 04:37:41 +00:00
parent fc17ab2a86
commit 410f42ed4a
2 changed files with 12 additions and 10 deletions

View File

@ -71,7 +71,6 @@ def lab_temp():
def history(): def history():
temperatures, humidities, timezone, from_date_str, to_date_str = get_records() 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. # Create new record tables so that datetimes are adjusted back to the user browser's time zone.
time_series_adjusted_temperatures = [] time_series_adjusted_temperatures = []
time_series_adjusted_humidities = [] time_series_adjusted_humidities = []
@ -122,21 +121,24 @@ def history():
fig = Figure(data=data, layout=layout) fig = Figure(data=data, layout=layout)
graphJSON = json.dumps(fig, cls=plotly.utils.PlotlyJSONEncoder) graphJSON = json.dumps(fig, cls=plotly.utils.PlotlyJSONEncoder)
## Duration of significant heat increases
# Timestep from raw database values for temperature
timestep_minutes = (datetime.datetime.strptime(temperatures[1][0], "%Y-%m-%d %H:%M:%S")-datetime.datetime.strptime(temperatures[0][0], "%Y-%m-%d %H:%M:%S")).seconds/60
# Calculate minutes for each streak
streak_minutes = streak_lengths(time_series_temperature_values)*timestep_minutes
x = time_series_temperature_values
result = longest_streak(x)
return render_template("history.html", timezone = timezone, return render_template("history.html", timezone = timezone,
graphJSON = graphJSON, graphJSON = graphJSON,
result = result, total_minutes = sum(streak_minutes),
) )
# Calculate streak lengths (https://stackoverflow.com/a/20614650/2152245)
def longest_streak(grades): def streak_lengths(temps):
if len(grades) < 2: if len(temps) < 2:
return len(grades) return len(temps)
else: else:
start, streaks = -1, [] start, streaks = -1, []
for idx, (x, y) in enumerate(zip(grades, grades[1:])): for idx, (x, y) in enumerate(zip(temps, temps[1:])):
if x > y: if x > y:
streaks.append(idx - start) streaks.append(idx - start)
start = idx start = idx

View File

@ -79,7 +79,7 @@
</div> </div>
<div class='row' id='plotly-plot'></div> <div class='row' id='plotly-plot'></div>
{{ result }} {{ total_minutes }}
</body> </body>