src/services/rollup.py
BeforeProposed
+11−2
33
44
55def monthly(readings):
6 # Implement facility/month/resource grouping.
7 return []
6 totals = {}
7 for reading in readings:
8 key = reading.facility, reading.month(), reading.resource
9 current = totals.setdefault(key, {'quantity': Decimal('0'), 'count': 0})
10 current['quantity'] += normalize(reading)
11 current['count'] += 1
12 return [
13 {'facility': facility, 'month': period, 'resource': resource,
14 'unit': BASE[resource], 'quantity': formatted(value['quantity']), 'readings': value['count']}
15 for (facility, period, resource), value in sorted(totals.items())
16 ]
817
918
1019def summary(readings):