From 874557fd1ec6d25c18499ca6c84de3e4d102e4fc Mon Sep 17 00:00:00 2001 From: jbruce Date: Sat, 14 May 2022 15:37:58 -0400 Subject: [PATCH] of the N temps readings every duty cycle, 2s by default, strip the top 25 percent and bottom 25 percent from those readings, use the rest to get the average temp over the cycle. --- lib/oven.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/oven.py b/lib/oven.py index 0bc7d59..fb0dd18 100644 --- a/lib/oven.py +++ b/lib/oven.py @@ -158,9 +158,21 @@ class TempSensorReal(TempSensor): self.bad_count += 1 if len(temps): - self.temperature = sum(temps) / len(temps) + self.temperature = self.get_avg_temp(temps) time.sleep(self.sleeptime) + def get_avg_temp(self, temps, chop=25): + ''' + strip off chop percent from the beginning and end of the sorted temps + then return the average of what is left + ''' + chop = chop / 100 + temps = sorted(temps) + total = len(temps) + items = int(total*chop) + temps = temps[items:total-items] + return sum(temps) / len(temps) + class Oven(threading.Thread): '''parent oven class. this has all the common code for either a real or simulated oven'''