diff --git a/mpl/sw-trend1.py b/mpl/sw-trend1.py index f1f0d52..1885e44 100644 --- a/mpl/sw-trend1.py +++ b/mpl/sw-trend1.py @@ -114,11 +114,16 @@ def num2sod(x): frac, integ = math.modf(x) return frac * 86400 -class Lohi: - """Time series online low and high detector.""" - def __init__(self, bias): +class TimedLohi: + """Time series online low and high detector. + + Confirms low/high candidates after timeout. + Time dependent. + """ + def __init__(self, bias, timeout = ONE_MINUTE): assert(bias > 0) self.bias = bias + self.timeout = timeout self.low0 = None self.high0 = None self.prev_lohi = NONE @@ -162,7 +167,7 @@ class Lohi: self.lows.append(self.low0) self.lohis.append(self.low0) self.prev_lohi = LOW - if self.high0[1] < cdt - ONE_MINUTE and \ + if self.high0[1] < cdt - self.timeout and \ ((self.prev_lohi == LOW and \ self.high0[2] > self.lows[-1][2] + self.bias) or (self.prev_lohi == HIGH and \ @@ -172,7 +177,7 @@ class Lohi: self.highs.append(self.high0) self.lohis.append(self.high0) self.prev_lohi = HIGH - if self.low0[1] < cdt - ONE_MINUTE and \ + if self.low0[1] < cdt - self.timeout and \ ((self.prev_lohi == LOW and \ self.low0[2] < self.lows[-1][2]) or (self.prev_lohi == HIGH and \ @@ -403,7 +408,7 @@ class Main: self.ss = [ 0 ] * len(self.xs) self.gs = [ 0 ] * len(self.xs) - self.mmh = Lohi(5) + self.mmh = TimedLohi(5) self.osw = SlidingWindow(5) self.w0 = 0