@@ -269,6 +269,8 @@ def year_statistics(target_date):
269
269
270
270
def update_electricity_statistics (reading ):
271
271
""" Updates the ElectricityStatistics records. """
272
+ print ('update_electricity_statistics() - Start' )
273
+
272
274
MAP = {
273
275
# Reading field: Stats record field.
274
276
'phase_currently_delivered_l1' : 'highest_usage_l1' ,
@@ -281,14 +283,27 @@ def update_electricity_statistics(reading):
281
283
stats = ElectricityStatistics .get_solo ()
282
284
dirty = False
283
285
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
+
284
291
for reading_field , stat_field in MAP .items ():
292
+ print ('update_electricity_statistics() - Current check:' , reading_field , '/' , stat_field )
285
293
reading_value = getattr (reading , reading_field ) or 0
286
294
highest_value = getattr (stats , '{}_value' .format (stat_field )) or 0
295
+ print ('update_electricity_statistics() - reading_value / highest_value: ' , reading_value , '/' , highest_value )
287
296
288
297
if reading_value and Decimal (reading_value ) > Decimal (highest_value ):
298
+ print ('update_electricity_statistics() - New high for' , stat_field )
289
299
dirty = True
290
300
setattr (stats , '{}_value' .format (stat_field ), reading_value )
291
301
setattr (stats , '{}_timestamp' .format (stat_field ), reading .timestamp )
292
302
303
+ print ('update_electricity_statistics() - Dirty:' , dirty )
304
+
293
305
if dirty :
306
+ print ('update_electricity_statistics() - Updated!' )
294
307
stats .save ()
308
+
309
+ print ('update_electricity_statistics() - End' )
0 commit comments