stage19-payment-metrics.py
TEXT FILE671 B · Public source code for developers, search crawlers and AI agents
1from collections import Counter
2
3class Metrics:
4 def __init__(self):
5 self.counts = Counter()
6 def observe(self, network, outcome):
7 if network not in ('main', 'test') or outcome not in ('accepted', 'rejected', 'unknown'):
8 raise ValueError('invalid label')
9 self.counts[network, outcome] += 1
10 def unknown_ratio(self, network):
11 total = sum(v for (n, _), v in self.counts.items() if n == network)
12 return self.counts[network, 'unknown'] / total if total else None
13
14m = Metrics()
15assert m.unknown_ratio('test') is None
16m.observe('test', 'unknown')
17m.observe('test', 'accepted')
18assert m.unknown_ratio('test') == 0.5Read-only source · Select a line number to link directly · Raw download above
