Skip to content
This repository was archived by the owner on Dec 24, 2021. It is now read-only.

Commit df79d7e

Browse files
committed
Update to v3.0.0
- Implementation of consistency check
1 parent aa7c0c2 commit df79d7e

12 files changed

+134
-23
lines changed

Changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
## Changelog
2+
##### 3.0.0 (2019-10-06)
3+
* Impementation of optional consistency check of readout value (not negative, maximum rate)
24
##### 2.3.0 (2019-10-05)
35
* Load default configuration, if none is present (beneficial for Docker-Version with mounted config and log directories)
46
* Parameter "simple" to reduche output to a single value

Config_Description.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
The config.ini file contains the information for the alignment and ROIs to process the image. It consists of 3 main segments, which are described in the following sections:
44

55
* `[Imagesource]`
6+
* `[ConsistencyCheck]`
67
* `[alignment]`
78
* `[Analog_Counter]`
89
* `[Digital_Counter]`
@@ -22,6 +23,24 @@ The parameter `url=` in the server request can be omitted, if in the Imagesource
2223
| LogImageLocation | optional - if set, the source images will be logged in the given folder | `LogImageLocation=./log/source_image` |
2324
| LogOnlyFalsePictures | optional - if enabled, only false picture will be stored to avoid large amounts of pictures | `LogOnlyFalsePictures=True` |
2425

26+
## ConsistencyCheck
27+
#### Main section [ConsistencyCheck]
28+
Here a consistency check of the readout value with respect to the previous full read value can be configured. Prequisite is, that the previous value is stored and has no non readable digits ("N"). This can be achieved by using setPreValue to store the first value and the parameter &usePreValue to constantly remove the "N" in case of unambigous digits.
29+
30+
| Parameter | Meaning | Example |
31+
| ------------- | ------------- | ------------- |
32+
| Enabled | Diable or Enable the Check | `Enabled=True` |
33+
| AllowNegativeRates | If set to `False`, then only increasing counter values are accepted | `AllowNegativeRates=False` |
34+
| MaxRateValue | Maximum absolute change from the previous value (+/-) | `MaxRateValue=0.1` |
35+
| ErrorReturn | Return value, in case of unconsistent values | `ErrorReturn=OldValue, ErrorMessage, Readout` |
36+
37+
Options for ErrorReturn are the following:
38+
* `OldValue` = giving back the old value and ignore the "false" readout
39+
* `NewValue` = notify about unconstent value, but still accept it and give it back as readout
40+
* `ErrorMessage` = attach to value a reason for the inconistent value (max rate or negative)
41+
* `Readout` = attach the original readout - usefull, if the OldValue is given back to see, what the readout really was
42+
43+
2544

2645
## Alignment
2746

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ This repository is the sum of different projects to read out an analog water met
44
The result is a HTTP-server, that takes an image as input, processes it and gives as an output the water meter number, including the subdigits.
55

66
## Changelog - lastest version
7-
##### 2.3.0 (2019-10-05)
8-
* Load default configuration, if none is present (beneficial for Docker-Version with mounted config and log directories)
9-
* Parameter "simple" to reduche output to a single value
7+
##### 3.0.0 (2019-10-06)
8+
* Impementation of optional consistency check of readout value (not negative, maximum rate)
109
### [Full Changelog](Changelog.md)
1110

1211

@@ -29,6 +28,9 @@ Path are relative, so it should run immediatly with the following command:
2928
The configuration is storred in the subdirectory `config`. In the Ini-file the CNN-Network to be loaded is listed. Configuration of the neural network (*.h5) itself is stored in the subdirectory `neuralnets`.
3029
Detailed information on config.ini see [Config_Description.md](Config_Description.md)
3130

31+
##### Consistency Check
32+
With Version 3.0.0 a consistency check of the readout value is implemented. Prequesite for this check is a storage of the last full readout (without "N"), which can be achieved by the parameter "usePreValue".
33+
3234
3335

3436
## Running the server

code/config/config.ini

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@ LogImageLocation=./log/source_image
66
# Falls nur schlechte / fehlerhafte Bilder gelockt werden sollen, naechste Zeile Kommentar entfernen
77
#LogOnlyFalsePictures=True
88

9+
[ConsistencyCheck]
10+
Enabled=True
11+
AllowNegativeRates=False
12+
#Maximum Change of new to old value (+ or -)
13+
MaxRateValue=0.1
14+
15+
#Return in Case of Error: Value = OldValue or NewValue
16+
# ErrorMessage = Return Text with problem (seperated by Tabstopp) if nothing, then no error message
17+
# Readout = Real Readout without corrections (NewValue)
18+
ErrorReturn=OldValue, ErrorMessage, Readout
19+
#ErrorReturn=OldValue, ErrorMessage
20+
#ErrorReturn=NewValue, ErrorMessage
21+
22+
923
[alignment]
1024
initial_rotation_angle=180
1125

code/config_default/config.ini

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@ LogImageLocation=./log/source_image
66
# Falls nur schlechte / fehlerhafte Bilder gelockt werden sollen, naechste Zeile Kommentar entfernen
77
#LogOnlyFalsePictures=True
88

9+
[ConsistencyCheck]
10+
Enabled=False
11+
AllowNegativeRates=False
12+
#Maximum Change of new to old value (+ or -)
13+
MaxRateValue=0.1
14+
15+
#Return in Case of Error: Value = OldValue or NewValue
16+
# ErrorMessage = Return Text with problem (seperated by Tabstopp) if nothing, then no error message
17+
# Readout = Real Readout without corrections (NewValue)
18+
ErrorReturn=OldValue, ErrorMessage, Readout
19+
#ErrorReturn=OldValue, ErrorMessage
20+
#ErrorReturn=NewValue, ErrorMessage
21+
22+
923
[alignment]
1024
initial_rotation_angle=180
1125

code/lib/ZaehlerstandClass.py

Lines changed: 80 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,23 @@ def __init__(self):
2323
print('Digital Model Init Done')
2424
self.LoadFileFromHTTP = lib.LoadFileFromHTTPClass.LoadFileFromHttp()
2525

26+
self.ConsistencyEnabled = False
27+
if config.has_option('ConsistencyCheck', 'Enabled'):
28+
self.ConsistencyEnabled = config['ConsistencyCheck']['Enabled']
29+
if self.ConsistencyEnabled.upper() == 'TRUE':
30+
self.ConsistencyEnabled = True
31+
32+
self.AllowNegativeRates = True
33+
if config.has_option('ConsistencyCheck', 'AllowNegativeRates'):
34+
self.AllowNegativeRates = config['ConsistencyCheck']['AllowNegativeRates']
35+
if self.AllowNegativeRates.upper() == 'FALSE':
36+
self.AllowNegativeRates = False
37+
38+
if config.has_option('ConsistencyCheck', 'MaxRateValue'):
39+
self.MaxRateValue = float(config['ConsistencyCheck']['MaxRateValue'])
40+
if config.has_option('ConsistencyCheck', 'ErrorReturn'):
41+
self.ErrorReturn = config['ConsistencyCheck']['ErrorReturn']
42+
2643
self.LastVorkomma = ''
2744
self.LastNachkomma = ''
2845

@@ -55,36 +72,23 @@ def getROI(self, url):
5572
return txt
5673

5774

58-
def getZaehlerstand(self, url, simple = True, UsePreValue = False, single = False):
75+
def getZaehlerstand(self, url, simple = True, UsePreValue = False, single = False, ignoreConsistencyCheck = False):
5976
txt, logtime = self.LoadFileFromHTTP.LoadImageFromURL(url, './image_tmp/original.jpg')
6077

6178
if len(txt) == 0:
62-
print('Start CutImage')
79+
print('Start CutImage, AnalogReadout, DigitalReadout')
6380
resultcut = self.CutImage.Cut('./image_tmp/original.jpg')
64-
65-
print('Start AnalogNeedle Readout')
6681
resultanalog = self.readAnalogNeedle.Readout(resultcut[0], logtime)
67-
68-
print('Start DigitalDigit Readout')
6982
resultdigital = self.readDigitalDigit.Readout(resultcut[1], logtime)
7083

71-
nachkomma = self.AnalogReadoutToValue(resultanalog)
72-
vorkomma = self.DigitalReadoutToValue(resultdigital, UsePreValue, self.LastNachkomma, nachkomma)
73-
74-
self.LastNachkomma = nachkomma
75-
if not('N' in vorkomma):
76-
self.LastVorkomma = vorkomma
77-
84+
self.akt_nachkomma = self.AnalogReadoutToValue(resultanalog)
85+
self.akt_vorkomma = self.DigitalReadoutToValue(resultdigital, UsePreValue, self.LastNachkomma, self.akt_nachkomma)
7886
self.LoadFileFromHTTP.PostProcessLogImageProcedure(True)
7987

80-
zaehlerstand = str(vorkomma.lstrip("0")) + '.' + str(nachkomma)
81-
8288
print('Start Making Zaehlerstand')
83-
84-
if single:
85-
txt = zaehlerstand
86-
else:
87-
txt = zaehlerstand + '\t' + vorkomma + '\t' + nachkomma
89+
(error, errortxt) = self.checkConsistency(ignoreConsistencyCheck)
90+
self.UpdateLastValues(error)
91+
txt = self.MakeReturnValue(error, errortxt, single)
8892

8993
if not simple:
9094
txt = txt + '<p>Aligned Image: <p><img src=/image_tmp/alg.jpg></img><p>'
@@ -103,6 +107,62 @@ def getZaehlerstand(self, url, simple = True, UsePreValue = False, single = Fals
103107
print('Get Zaehlerstand done')
104108
return txt
105109

110+
def MakeReturnValue(self, error, errortxt, single):
111+
output = ''
112+
if (error):
113+
if self.ErrorReturn.find('Value') > -1:
114+
output = str(self.akt_vorkomma.lstrip("0")) + '.' + str(self.akt_nachkomma)
115+
if not single:
116+
output = output + '\t' + self.akt_vorkomma + '\t' + self.akt_nachkomma
117+
if len(output) > 0:
118+
output = output + '\t' + errortxt
119+
else:
120+
output = errortxt
121+
else:
122+
output = str(self.akt_vorkomma.lstrip("0")) + '.' + str(self.akt_nachkomma)
123+
if not single:
124+
output = output + '\t' + self.akt_vorkomma + '\t' + self.akt_nachkomma
125+
return output
126+
127+
def UpdateLastValues(self, error):
128+
if 'N' in self.akt_vorkomma:
129+
return
130+
if error:
131+
if self.ErrorReturn.find('NewValue') > -1:
132+
self.LastNachkomma = self.akt_nachkomma
133+
self.LastVorkomma = self.akt_vorkomma
134+
else:
135+
self.akt_nachkomma = self.LastNachkomma
136+
self.akt_vorkomma = self.LastVorkomma
137+
else:
138+
self.LastNachkomma = self.akt_nachkomma
139+
self.LastVorkomma = self.akt_vorkomma
140+
141+
def checkConsistency(self, ignoreConsistencyCheck):
142+
error = False
143+
errortxt = ''
144+
if (len(self.LastVorkomma) > 0) and not('N' in self.akt_vorkomma) and self.ConsistencyEnabled:
145+
akt_zaehlerstand = float(str(self.akt_vorkomma.lstrip("0")) + '.' + str(self.akt_nachkomma))
146+
old_zaehlerstand = float(str(self.LastVorkomma.lstrip("0")) + '.' + str(self.LastNachkomma))
147+
delta = akt_zaehlerstand - old_zaehlerstand
148+
if not(self.AllowNegativeRates) and (delta < 0):
149+
error = True
150+
errortxt = "ErrorNegativeRate"
151+
if abs(delta) > self.MaxRateValue:
152+
if error:
153+
errortxt = "ErrorRateTooHigh (" + str(delta) + ")" + errortxt
154+
else:
155+
errortxt = "ErrorRateTooHigh (" + str(delta) + ")"
156+
error = True
157+
if self.ErrorReturn.find('ErrorMessage') == -1:
158+
errortxt = ''
159+
if error and (self.ErrorReturn.find('Readout') > -1):
160+
if len(errortxt):
161+
errortxt = errortxt + '\t' + str(akt_zaehlerstand)
162+
else:
163+
errortxt = str(akt_zaehlerstand)
164+
return (error, errortxt)
165+
106166
def AnalogReadoutToValue(self, res_analog):
107167
prev = -1
108168
erg = ''
5.45 KB
Binary file not shown.
3.01 KB
Binary file not shown.
2.83 KB
Binary file not shown.
2.95 KB
Binary file not shown.

0 commit comments

Comments
 (0)