diff py/utils.py @ 271:11cebd6f0bfb

untested fridge.integrator
author Matt Johnston <matt@ucc.asn.au>
date Wed, 11 Nov 2015 00:20:20 +0800
parents 9d0313b685ae
children af924d27140f
line wrap: on
line diff
--- a/py/utils.py	Wed Nov 11 00:07:21 2015 +0800
+++ b/py/utils.py	Wed Nov 11 00:20:20 2015 +0800
@@ -174,6 +174,9 @@
 
 class StepIntegrator(object):
     """
+    Takes on/off events and a monotonically increasing timefn. Returns the integral 
+    of (now-limittime, now) over those events.
+
     >>> s = StepIntegrator(lambda: t, 40)
     >>> t = 1
     >>> s.turn(1)
@@ -212,6 +215,12 @@
         self._timefn = timefn
         self._limittime = limittime
 
+    def set_limit(self, limittime):
+        if self._limittime == limittime:
+            return
+        self._limittime = limittime
+        self.trim()
+
     def turn(self, value):
         if not self._on_periods:
             if value: