Skip to content

Commit 96633c3

Browse files
All time highs empty #535
1 parent db18e5c commit 96633c3

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

dsmr_stats/services.py

+15
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ def year_statistics(target_date):
269269

270270
def update_electricity_statistics(reading):
271271
""" Updates the ElectricityStatistics records. """
272+
print('update_electricity_statistics() - Start')
273+
272274
MAP = {
273275
# Reading field: Stats record field.
274276
'phase_currently_delivered_l1': 'highest_usage_l1',
@@ -281,14 +283,27 @@ def update_electricity_statistics(reading):
281283
stats = ElectricityStatistics.get_solo()
282284
dirty = False
283285

286+
print('update_electricity_statistics() - Reading trigger:', reading.timestamp)
287+
288+
for x in MAP.keys():
289+
print('update_electricity_statistics() - Reading', x, ' ', getattr(reading, x))
290+
284291
for reading_field, stat_field in MAP.items():
292+
print('update_electricity_statistics() - Current check:', reading_field, '/', stat_field)
285293
reading_value = getattr(reading, reading_field) or 0
286294
highest_value = getattr(stats, '{}_value'.format(stat_field)) or 0
295+
print('update_electricity_statistics() - reading_value / highest_value: ', reading_value, '/', highest_value)
287296

288297
if reading_value and Decimal(reading_value) > Decimal(highest_value):
298+
print('update_electricity_statistics() - New high for', stat_field)
289299
dirty = True
290300
setattr(stats, '{}_value'.format(stat_field), reading_value)
291301
setattr(stats, '{}_timestamp'.format(stat_field), reading.timestamp)
292302

303+
print('update_electricity_statistics() - Dirty:', dirty)
304+
293305
if dirty:
306+
print('update_electricity_statistics() - Updated!')
294307
stats.save()
308+
309+
print('update_electricity_statistics() - End')

0 commit comments

Comments
 (0)