Accumulator for categorized event statistics.
| 66 | |
| 67 | |
| 68 | class RunningStats(dict): |
| 69 | """Accumulator for categorized event statistics. |
| 70 | """ |
| 71 | |
| 72 | def add(self, key, value): |
| 73 | """Add an event to a given accumulator. |
| 74 | |
| 75 | :param key: category to which the event should be added. |
| 76 | :param value: value of the event. |
| 77 | """ |
| 78 | if key in self: |
| 79 | super().__getitem__(key).add(value) |
| 80 | else: |
| 81 | super().__setitem__(key, RunningState(value)) |
| 82 | |
| 83 | def stats(self, key): |
| 84 | """Return the statistics for the current accumulator. |
| 85 | |
| 86 | :rtype: Stats. |
| 87 | """ |
| 88 | return stats(super().__getitem__(key)) |
no outgoing calls