diff --git a/lib/oven.py b/lib/oven.py index d0d9ebc..49f290b 100644 --- a/lib/oven.py +++ b/lib/oven.py @@ -327,6 +327,8 @@ class Oven(threading.Thread): self.totaltime = 0 self.target = 0 self.heat = 0 + self.heat_rate = 0 + self.heat_rate_temps = [] self.pid = PID(ki=config.pid_ki, kd=config.pid_kd, kp=config.pid_kp) @staticmethod @@ -339,6 +341,24 @@ class Oven(threading.Thread): startat = 0 return startat + def set_heat_rate(self,runtime,temp): + '''heat rate is the heating rate in degrees/hour + ''' + # arbitrary number of samples + # the time this covers changes based on a few things + numtemps = 60 + self.heat_rate_temps.append((runtime,temp)) + + # drop old temps off the list + if len(self.heat_rate_temps) > numtemps: + self.heat_rate_temps = self.heat_rate_temps[-1*numtemps:] + time2 = self.heat_rate_temps[-1][0] + time1 = self.heat_rate_temps[0][0] + temp2 = self.heat_rate_temps[-1][1] + temp1 = self.heat_rate_temps[0][1] + if time2 > time1: + self.heat_rate = ((temp2 - temp1) / (time2 - time1))*3600 + def run_profile(self, profile, startat=0, allow_seek=True): log.debug('run_profile run on thread' + threading.current_thread().name) runtime = startat * 60 @@ -426,6 +446,8 @@ class Oven(threading.Thread): temp = 0 pass + self.set_heat_rate(self.runtime,temp) + state = { 'cost': self.cost, 'runtime': self.runtime, @@ -433,6 +455,7 @@ class Oven(threading.Thread): 'target': self.target, 'state': self.state, 'heat': self.heat, + 'heat_rate': self.heat_rate, 'totaltime': self.totaltime, 'kwh_rate': config.kwh_rate, 'currency_type': config.currency_type,