MCPcopy Create free account
hub / github.com/LabPy/lantz / RunningState

Class RunningState

lantz/stats.py:36–65  ·  view source on GitHub ↗

Accumulator for events. :param value: first value to add.

Source from the content-addressed store, hash-verified

34
35
36class RunningState(object):
37 """Accumulator for events.
38
39 :param value: first value to add.
40 """
41
42 def __init__(self, value=None):
43 if value is not None:
44 self.add(value)
45
46 def __getattr__(self, key):
47 if key in ('last', 'count', 'sum', 'sum2'):
48 return 0
49 if key == 'min':
50 return float('inf')
51 if key == 'max':
52 return float('-inf')
53 raise AttributeError('{} is not a valid attribute of RunningState'.format(key))
54
55 def add(self, value):
56 """Add to the accumulator.
57
58 :param value: value to be added.
59 """
60 self.last = value
61 self.count += 1
62 self.sum += value
63 self.sum2 += value * value
64 self.min = min(self.min, value)
65 self.max = max(self.max, value)
66
67
68class RunningStats(dict):

Callers 1

addMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected