Calculate how much the furnace is running #30
28
pi_temp.py
28
pi_temp.py
@ -69,8 +69,7 @@ def lab_temp():
|
|||||||
|
|
||||||
@app.route("/history", methods=['GET']) #Add date limits in the URL #Arguments: from=2015-03-04&to=2015-03-05
|
@app.route("/history", methods=['GET']) #Add date limits in the URL #Arguments: from=2015-03-04&to=2015-03-05
|
||||||
def history():
|
def history():
|
||||||
temperatures, humidities, timezone, from_date_str, to_date_str = get_records()
|
temperatures, humidities, timezone, from_date_str, to_date_str, range_hours = 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 = []
|
||||||
@ -122,9 +121,32 @@ 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
|
||||||
|
|
||||||
|
# Send output to page
|
||||||
return render_template("history.html", timezone = timezone,
|
return render_template("history.html", timezone = timezone,
|
||||||
graphJSON = graphJSON,
|
graphJSON = graphJSON,
|
||||||
|
total_minutes = sum(streak_minutes),
|
||||||
|
range_hours = range_hours
|
||||||
)
|
)
|
||||||
|
# Calculate streak lengths (https://stackoverflow.com/a/20614650/2152245)
|
||||||
|
def streak_lengths(temps):
|
||||||
|
if len(temps) < 2:
|
||||||
|
return len(temps)
|
||||||
|
else:
|
||||||
|
start, streaks = -1, []
|
||||||
|
for idx, (x, y) in enumerate(zip(temps, temps[1:])):
|
||||||
|
if x > y:
|
||||||
|
streaks.append(idx - start)
|
||||||
|
start = idx
|
||||||
|
else:
|
||||||
|
streaks.append(idx - start + 1)
|
||||||
|
long_streaks = [x for x in streaks if x > 3]
|
||||||
|
return long_streaks
|
||||||
|
|
||||||
def get_records():
|
def get_records():
|
||||||
from_date_str = request.args.get('from',time.strftime("%Y-%m-%d 00:00")) #Get the from date value from the URL
|
from_date_str = request.args.get('from',time.strftime("%Y-%m-%d 00:00")) #Get the from date value from the URL
|
||||||
@ -174,7 +196,7 @@ def get_records():
|
|||||||
humidities = curs.fetchall()
|
humidities = curs.fetchall()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
return [temperatures, humidities, timezone, from_date_str, to_date_str]
|
return [temperatures, humidities, timezone, from_date_str, to_date_str, range_h_int]
|
||||||
|
|
||||||
def validate_date(d):
|
def validate_date(d):
|
||||||
try:
|
try:
|
||||||
|
@ -77,6 +77,9 @@
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Furnace averaging {{ "%.2f" % (total_minutes/range_hours) }} minutes/hr ({{ total_minutes }} minutes total).
|
||||||
|
|
||||||
<div class='row' id='plotly-plot'></div>
|
<div class='row' id='plotly-plot'></div>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
Reference in New Issue
Block a user