def __init__(self, period, metric=None): ProxiedMetric.__init__(self, metric) self.period = period self.lastData = None self.percentChange = PercentChange(metric) self._addMetric(self.percentChange) self.changes = list() self.val = None
def handle(self, perioddata): ProxiedMetric.handle(self, perioddata) if self.percentChange.ready(): nextchg = self.percentChange.value() if len(self.changes) == self.period: # have enough to calculate value, do it now before storing our latest value count = 0.0 for pc in self.changes: if pc < nextchg: count = count + 1.0 self.val = 100 * (count / float(self.period)) self.changes.append(nextchg) if len(self.changes) > self.period: self.changes = self.changes[len(self.changes) - self.period:] pass
def handle(self, perioddata): ProxiedMetric.handle(self, perioddata) if self.percentChange.ready(): nextchg = self.percentChange.value() if len (self.changes) == self.period: # have enough to calculate value, do it now before storing our latest value count = 0.0 for pc in self.changes: if pc < nextchg: count = count+1.0 self.val = 100*(count/float(self.period)) self.changes.append(nextchg) if len(self.changes) > self.period: self.changes = self.changes[len(self.changes)-self.period:] pass
def handle(self, perioddata): ProxiedMetric.handle(self, perioddata) if self.metric.ready(): data = self.metric.value() if self.lastData != None: delta = data - self.lastData if delta > 0: if self.val == None or self.val < 0: self.val = 1.0 else: self.val = self.val + 1.0 if delta < 0: if self.val == None or self.val > 0: self.val = -1.0 else: self.val = self.val - 1.0 if delta == 0: self.val = 0 self.lastData = data
def recommendedPreload(self): return ProxiedMetric.recommendedPreload(self) + self.period
def __init__(self, metric=None): ProxiedMetric.__init__(self, metric) self.val = None self.lastData = None