Merge pull request #34 from mattbk/threshold-edits
Fix the furnace threshold and run-time calculation
This commit is contained in:
34
pi_temp.py
34
pi_temp.py
@ -128,27 +128,31 @@ def history():
|
||||
timestep_minutes = 1
|
||||
# Calculate minutes for each streak
|
||||
streak_minutes = streak_lengths(time_series_temperature_values)*timestep_minutes
|
||||
streak_minutes = [x-1 for x in streak_minutes] #Turn this into a duration
|
||||
|
||||
# Send output to page
|
||||
return render_template("history.html", timezone = timezone,
|
||||
graphJSON = graphJSON,
|
||||
total_minutes = sum(streak_minutes),
|
||||
range_hours = range_hours
|
||||
range_hours = range_hours,
|
||||
debug = streak_minutes,
|
||||
)
|
||||
# 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
|
||||
|
||||
# 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]]
|
||||
# add the start and end boundaries
|
||||
boundaries = [0] + boundaries + [len(x)]
|
||||
# take the boundaries as pairwise slices
|
||||
slices = [boundaries[i:i + 2] for i in range(len(boundaries) - 1)]
|
||||
# extract all sequences with length greater than one
|
||||
temporary = [x[start:end] for start, end in slices if end - start > 1]
|
||||
# Remove tuples with all equal values
|
||||
screened = [x for x in temporary if not all(y==x[0] for y in x)]
|
||||
# Calculate length of each list
|
||||
out = [len(x) for x in screened]
|
||||
return out
|
||||
|
||||
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
|
||||
|
@ -78,10 +78,12 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Furnace averaging {{ "%.0f" % (total_minutes/range_hours) }} minutes/hr ({{ total_minutes }} minutes total).
|
||||
Furnace averaging {{ "%.0f" % (total_minutes/range_hours) }} minutes/hour ({{ total_minutes }} minutes total).
|
||||
|
||||
<div class='row' id='plotly-plot'></div>
|
||||
|
||||
{{ debug }}
|
||||
|
||||
</body>
|
||||
|
||||
<footer>
|
||||
|
Reference in New Issue
Block a user