diff py/utils.py @ 570:afe2eb17723e

untested fridge.integrator
author Matt Johnston <matt@ucc.asn.au>
date Wed, 11 Nov 2015 00:20:20 +0800
parents d7575050e4be
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: