From 30c78c11eef40e2269e287ff526b6dd36f31fa12 Mon Sep 17 00:00:00 2001 From: MDW <--unset> Date: Sun, 4 Dec 2022 16:20:38 +0100 Subject: [PATCH] Skip estimated values --- veolia-idf-domoticz.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/veolia-idf-domoticz.py b/veolia-idf-domoticz.py index 47d511c..96bb075 100755 --- a/veolia-idf-domoticz.py +++ b/veolia-idf-domoticz.py @@ -1063,6 +1063,15 @@ def update_device(self, csv_file): date_time = row[0] counter = row[1] conso = row[2] + method = row[3] # "Mesuré" or "Estimé" + + if method in ("Estimé", ): + # Do not use estimated values which may result + # in a total that is not increasing + # (when the estimated value is smaller than the + # previous real value or higher than the next + # real value) + continue # Check line integrity (Date starting by 2 or 1) if date[0] == "2" or date[0] == "1": @@ -1203,15 +1212,34 @@ def update_device(self, csv_file): row = rows[-1] p_row = rows[-2] + method = row[3] # "Mesuré" or "Estimé" + if method in ("Estimé", ): + self.print( "File contains estimated data in last line: %s" % (row,)) + # Try previous row which may be a measurement + row = p_row + p_row = rows[-3] + date = row[0][0:10] date_time = row[0] meter_total = row[1] meter_period_total = row[2] + method = row[3] # "Mesuré" or "Estimé" p_date_time = p_row[0] p_meter_total = p_row[1] p_meter_period_total = p_row[2] + if method in ("Estimé", ): + self.print( " Skip Method " + method) + # Do not use estimated values which may result + # in a total that is not increasing + # (when the estimated value is smaller than the + # previous real value or higher than the next + # real value) + raise RuntimeError( + "File contains estimated data in last lines: %s" % (row,) + ) + # Check line integrity (Date starting with 2 (Year)) if date[0] == "2": # Verify data integrity :