IgnoreLeadingNaN fix (#3547)

* test1

* test2

* Update edit_config_template.html

* fix

* Update NUMBER.CheckDigitIncreaseConsistency.md

---------

Co-authored-by: CaCO3 <caco3@ruinelli.ch>
This commit is contained in:
SybexX
2025-03-01 00:09:11 +01:00
committed by GitHub
parent c587ca3224
commit cd1165e547
7 changed files with 1828 additions and 1857 deletions

View File

@@ -31,7 +31,6 @@ enum t_RateType {
RateChange // time difference is considered and a normalized rate is used for comparison with NumberPost.maxRate RateChange // time difference is considered and a normalized rate is used for comparison with NumberPost.maxRate
}; };
/** /**
* Holds all properties and settings of a sequence. A sequence is a set of digit and/or analog ROIs that are combined to * Holds all properties and settings of a sequence. A sequence is a set of digit and/or analog ROIs that are combined to
* provide one meter reading (value). * provide one meter reading (value).
@@ -45,6 +44,7 @@ struct NumberPost {
int ChangeRateThreshold; // threshold parameter for negative rate detection int ChangeRateThreshold; // threshold parameter for negative rate detection
bool PreValueOkay; // previousValueValid; indicates that the reading of the previous round has no errors bool PreValueOkay; // previousValueValid; indicates that the reading of the previous round has no errors
bool AllowNegativeRates; // allowNegativeRate; defines if the consistency checks allow negative rates between consecutive meter readings. bool AllowNegativeRates; // allowNegativeRate; defines if the consistency checks allow negative rates between consecutive meter readings.
bool IgnoreLeadingNaN;
bool checkDigitIncreaseConsistency; // extendedConsistencyCheck; performs an additional consistency check to avoid wrong readings bool checkDigitIncreaseConsistency; // extendedConsistencyCheck; performs an additional consistency check to avoid wrong readings
time_t timeStampLastValue; // Timestamp for the last read value; is used for the log time_t timeStampLastValue; // Timestamp for the last read value; is used for the log
time_t timeStampLastPreValue; // Timestamp for the last PreValue set; is used for useMaxRateValue time_t timeStampLastPreValue; // Timestamp for the last PreValue set; is used for useMaxRateValue
@@ -66,7 +66,7 @@ struct NumberPost {
float AnalogToDigitTransitionStart; // AnalogToDigitTransitionStartValue; FIXME: need a better description; When is the digit > x.1, i.e. when does it start to tilt? float AnalogToDigitTransitionStart; // AnalogToDigitTransitionStartValue; FIXME: need a better description; When is the digit > x.1, i.e. when does it start to tilt?
int Nachkomma; // decimalPlaces; usually defined by the number of analog ROIs; affected by DecimalShift int Nachkomma; // decimalPlaces; usually defined by the number of analog ROIs; affected by DecimalShift
string DomoticzIdx; // Domoticz counter Idx string DomoticzIdx; // Domoticz counter Idx
string FieldV1; // influxdbFieldName_v1; Name of the Field in InfluxDBv1 string FieldV1; // influxdbFieldName_v1; Name of the Field in InfluxDBv1
string MeasurementV1; // influxdbMeasurementName_v1; Name of the Measurement in InfluxDBv1 string MeasurementV1; // influxdbMeasurementName_v1; Name of the Measurement in InfluxDBv1
@@ -83,4 +83,3 @@ struct NumberPost {
}; };
#endif #endif

View File

@@ -320,7 +320,6 @@ ClassFlowPostProcessing::ClassFlowPostProcessing(std::vector<ClassFlow*>* lfc, C
ListFlowControll = lfc; ListFlowControll = lfc;
flowTakeImage = NULL; flowTakeImage = NULL;
UpdatePreValueINI = false; UpdatePreValueINI = false;
IgnoreLeadingNaN = false;
flowAnalog = _analog; flowAnalog = _analog;
flowDigit = _digit; flowDigit = _digit;
@@ -431,6 +430,27 @@ void ClassFlowPostProcessing::handleAllowNegativeRate(string _decsep, string _va
} }
} }
void ClassFlowPostProcessing::handleIgnoreLeadingNaN(string _decsep, string _value) {
string _digit, _decpos;
int _pospunkt = _decsep.find_first_of(".");
if (_pospunkt > -1) {
_digit = _decsep.substr(0, _pospunkt);
}
else {
_digit = "default";
}
for (int j = 0; j < NUMBERS.size(); ++j) {
bool _zwdc = alphanumericToBoolean(_value);
// Set to default first (if nothing else is set)
if ((_digit == "default") || (NUMBERS[j]->name == _digit)) {
NUMBERS[j]->IgnoreLeadingNaN = _zwdc;
}
}
}
void ClassFlowPostProcessing::handleMaxRateType(string _decsep, string _value) { void ClassFlowPostProcessing::handleMaxRateType(string _decsep, string _value) {
string _digit, _decpos; string _digit, _decpos;
int _pospunkt = _decsep.find_first_of("."); int _pospunkt = _decsep.find_first_of(".");
@@ -509,7 +529,7 @@ void ClassFlowPostProcessing::handleChangeRateThreshold(string _decsep, string _
} }
} }
} }
/*
void ClassFlowPostProcessing::handlecheckDigitIncreaseConsistency(std::string _decsep, std::string _value) void ClassFlowPostProcessing::handlecheckDigitIncreaseConsistency(std::string _decsep, std::string _value)
{ {
std::string _digit; std::string _digit;
@@ -532,7 +552,7 @@ void ClassFlowPostProcessing::handlecheckDigitIncreaseConsistency(std::string _d
} }
} }
} }
*/
bool ClassFlowPostProcessing::ReadParameter(FILE* pfile, string& aktparamgraph) { bool ClassFlowPostProcessing::ReadParameter(FILE* pfile, string& aktparamgraph) {
std::vector<string> splitted; std::vector<string> splitted;
int _n; int _n;
@@ -585,12 +605,7 @@ bool ClassFlowPostProcessing::ReadParameter(FILE* pfile, string& aktparamgraph)
} }
if ((toUpper(_param) == "CHECKDIGITINCREASECONSISTENCY") && (splitted.size() > 1)) { if ((toUpper(_param) == "CHECKDIGITINCREASECONSISTENCY") && (splitted.size() > 1)) {
// handlecheckDigitIncreaseConsistency(splitted[0], splitted[1]); handlecheckDigitIncreaseConsistency(splitted[0], splitted[1]);
if (alphanumericToBoolean(splitted[1])) {
for (_n = 0; _n < NUMBERS.size(); ++_n) {
NUMBERS[_n]->checkDigitIncreaseConsistency = true;
}
}
} }
if ((toUpper(_param) == "ALLOWNEGATIVERATES") && (splitted.size() > 1)) { if ((toUpper(_param) == "ALLOWNEGATIVERATES") && (splitted.size() > 1)) {
@@ -602,7 +617,7 @@ bool ClassFlowPostProcessing::ReadParameter(FILE* pfile, string& aktparamgraph)
} }
if ((toUpper(_param) == "IGNORELEADINGNAN") && (splitted.size() > 1)) { if ((toUpper(_param) == "IGNORELEADINGNAN") && (splitted.size() > 1)) {
IgnoreLeadingNaN = alphanumericToBoolean(splitted[1]); handleIgnoreLeadingNaN(splitted[0], splitted[1]);
} }
if ((toUpper(_param) == "PREVALUEAGESTARTUP") && (splitted.size() > 1)) { if ((toUpper(_param) == "PREVALUEAGESTARTUP") && (splitted.size() > 1)) {
@@ -670,6 +685,7 @@ void ClassFlowPostProcessing::InitNUMBERS() {
_number->FlowRateAct = 0; // m3 / min _number->FlowRateAct = 0; // m3 / min
_number->PreValueOkay = false; _number->PreValueOkay = false;
_number->AllowNegativeRates = false; _number->AllowNegativeRates = false;
_number->IgnoreLeadingNaN = false;
_number->MaxRateValue = 0.1; _number->MaxRateValue = 0.1;
_number->MaxRateType = AbsoluteChange; _number->MaxRateType = AbsoluteChange;
_number->useMaxRateValue = false; _number->useMaxRateValue = false;
@@ -821,7 +837,7 @@ bool ClassFlowPostProcessing::doFlow(string zwtime) {
ESP_LOGD(TAG, "After ShiftDecimal: ReturnRaw %s", NUMBERS[j]->ReturnRawValue.c_str()); ESP_LOGD(TAG, "After ShiftDecimal: ReturnRaw %s", NUMBERS[j]->ReturnRawValue.c_str());
#endif #endif
if (IgnoreLeadingNaN) { if (NUMBERS[j]->IgnoreLeadingNaN) {
while ((NUMBERS[j]->ReturnRawValue.length() > 1) && (NUMBERS[j]->ReturnRawValue[0] == 'N')) { while ((NUMBERS[j]->ReturnRawValue.length() > 1) && (NUMBERS[j]->ReturnRawValue[0] == 'N')) {
NUMBERS[j]->ReturnRawValue.erase(0, 1); NUMBERS[j]->ReturnRawValue.erase(0, 1);
} }
@@ -868,12 +884,7 @@ bool ClassFlowPostProcessing::doFlow(string zwtime) {
if (NUMBERS[j]->checkDigitIncreaseConsistency) { if (NUMBERS[j]->checkDigitIncreaseConsistency) {
if (flowDigit) { if (flowDigit) {
if (flowDigit->getCNNType() != Digit) { NUMBERS[j]->Value = checkDigitConsistency(NUMBERS[j]->Value, NUMBERS[j]->DecimalShift, NUMBERS[j]->analog_roi != NULL, NUMBERS[j]->PreValue);
ESP_LOGD(TAG, "checkDigitIncreaseConsistency = true - ignored due to wrong CNN-Type (not Digit Classification)");
}
else {
NUMBERS[j]->Value = checkDigitConsistency(NUMBERS[j]->Value, NUMBERS[j]->DecimalShift, NUMBERS[j]->analog_roi != NULL, NUMBERS[j]->PreValue);
}
} }
else { else {
#ifdef SERIAL_DEBUG #ifdef SERIAL_DEBUG

View File

@@ -10,7 +10,6 @@
#include <string> #include <string>
class ClassFlowPostProcessing : class ClassFlowPostProcessing :
public ClassFlow public ClassFlow
{ {
@@ -19,8 +18,7 @@ protected:
int PreValueAgeStartup; int PreValueAgeStartup;
bool ErrorMessage; bool ErrorMessage;
bool IgnoreLeadingNaN; // SPECIAL CASE for User Gustl ???
ClassFlowCNNGeneral* flowAnalog; ClassFlowCNNGeneral* flowAnalog;
ClassFlowCNNGeneral* flowDigit; ClassFlowCNNGeneral* flowDigit;
@@ -35,15 +33,16 @@ protected:
float checkDigitConsistency(double input, int _decilamshift, bool _isanalog, double _preValue); float checkDigitConsistency(double input, int _decilamshift, bool _isanalog, double _preValue);
void InitNUMBERS(); void InitNUMBERS();
void handleDecimalSeparator(string _decsep, string _value); void handleDecimalSeparator(string _decsep, string _value);
void handleMaxRateValue(string _decsep, string _value); void handleMaxRateValue(string _decsep, string _value);
void handleDecimalExtendedResolution(string _decsep, string _value); void handleDecimalExtendedResolution(string _decsep, string _value);
void handleMaxRateType(string _decsep, string _value); void handleMaxRateType(string _decsep, string _value);
void handleAnalogToDigitTransitionStart(string _decsep, string _value); void handleAnalogToDigitTransitionStart(string _decsep, string _value);
void handleAllowNegativeRate(string _decsep, string _value); void handleAllowNegativeRate(string _decsep, string _value);
void handleIgnoreLeadingNaN(string _decsep, string _value);
void handleChangeRateThreshold(string _decsep, string _value); void handleChangeRateThreshold(string _decsep, string _value);
void handlecheckDigitIncreaseConsistency(std::string _decsep, std::string _value);
std::string GetStringReadouts(general);
void WriteDataLog(int _index); void WriteDataLog(int _index);
@@ -75,5 +74,4 @@ public:
string name(){return "ClassFlowPostProcessing";}; string name(){return "ClassFlowPostProcessing";};
}; };
#endif //CLASSFFLOWPOSTPROCESSING_H #endif //CLASSFFLOWPOSTPROCESSING_H

View File

@@ -31,7 +31,6 @@ AlignmentAlgo
CNNGoodThreshold CNNGoodThreshold
PreValueAgeStartup PreValueAgeStartup
ErrorMessage ErrorMessage
CheckDigitIncreaseConsistency
IO0 IO0
IO1 IO1
IO3 IO3

View File

@@ -6,3 +6,6 @@ Default Value: `false`
An additional consistency check. An additional consistency check.
It especially improves the zero crossing check between digits. It especially improves the zero crossing check between digits.
!!! Note
This parameter must be prefixed with `<NUMBER>` followed by a dot (eg. `main.CheckDigitIncreaseConsistency`). `<NUMBER>` is the name of the number sequence defined in the ROI's.

File diff suppressed because it is too large Load Diff

View File

@@ -6,7 +6,6 @@ var ref = new Array(2);
var NUMBERS = new Array(0); var NUMBERS = new Array(0);
var REFERENCES = new Array(0); var REFERENCES = new Array(0);
function getNUMBERSList() { function getNUMBERSList() {
_domainname = getDomainname(); _domainname = getDomainname();
var namenumberslist = ""; var namenumberslist = "";
@@ -33,7 +32,6 @@ function getNUMBERSList() {
return namenumberslist; return namenumberslist;
} }
function getDATAList() { function getDATAList() {
_domainname = getDomainname(); _domainname = getDomainname();
datalist = ""; datalist = "";
@@ -62,7 +60,6 @@ function getDATAList() {
return datalist; return datalist;
} }
function getTFLITEList() { function getTFLITEList() {
_domainname = getDomainname(); _domainname = getDomainname();
tflitelist = ""; tflitelist = "";
@@ -90,7 +87,6 @@ function getTFLITEList() {
return tflitelist; return tflitelist;
} }
function ParseConfig() { function ParseConfig() {
config_split = config_gesamt.split("\n"); config_split = config_gesamt.split("\n");
var aktline = 0; var aktline = 0;
@@ -172,7 +168,7 @@ function ParseConfig() {
category[catname]["enabled"] = false; category[catname]["enabled"] = false;
category[catname]["found"] = false; category[catname]["found"] = false;
param[catname] = new Object(); param[catname] = new Object();
ParamAddValue(param, catname, "DecimalShift", 1, true); ParamAddValue(param, catname, "DecimalShift", 1, true, "0");
ParamAddValue(param, catname, "AnalogToDigitTransitionStart", 1, true, "9.2"); ParamAddValue(param, catname, "AnalogToDigitTransitionStart", 1, true, "9.2");
ParamAddValue(param, catname, "ChangeRateThreshold", 1, true, "2"); ParamAddValue(param, catname, "ChangeRateThreshold", 1, true, "2");
// ParamAddValue(param, catname, "PreValueUse", 1, true, "true"); // ParamAddValue(param, catname, "PreValueUse", 1, true, "true");
@@ -185,7 +181,7 @@ function ParseConfig() {
ParamAddValue(param, catname, "IgnoreLeadingNaN", 1, true, "false"); ParamAddValue(param, catname, "IgnoreLeadingNaN", 1, true, "false");
// ParamAddValue(param, catname, "IgnoreAllNaN", 1, true, "false"); // ParamAddValue(param, catname, "IgnoreAllNaN", 1, true, "false");
ParamAddValue(param, catname, "ErrorMessage"); ParamAddValue(param, catname, "ErrorMessage");
ParamAddValue(param, catname, "CheckDigitIncreaseConsistency"); ParamAddValue(param, catname, "CheckDigitIncreaseConsistency", 1, true, "false");
var catname = "MQTT"; var catname = "MQTT";
category[catname] = new Object(); category[catname] = new Object();
@@ -359,7 +355,6 @@ function ParseConfig() {
} }
} }
function ParamAddValue(param, _cat, _param, _anzParam = 1, _isNUMBER = false, _defaultValue = "", _checkRegExList = null) { function ParamAddValue(param, _cat, _param, _anzParam = 1, _isNUMBER = false, _defaultValue = "", _checkRegExList = null) {
param[_cat][_param] = new Object(); param[_cat][_param] = new Object();
param[_cat][_param]["found"] = false; param[_cat][_param]["found"] = false;
@@ -371,7 +366,6 @@ function ParamAddValue(param, _cat, _param, _anzParam = 1, _isNUMBER = false, _d
param[_cat][_param].checkRegExList = _checkRegExList; param[_cat][_param].checkRegExList = _checkRegExList;
}; };
function ParseConfigParamAll(_aktline, _catname) { function ParseConfigParamAll(_aktline, _catname) {
++_aktline; ++_aktline;
@@ -403,7 +397,6 @@ function ParseConfigParamAll(_aktline, _catname) {
return _aktline; return _aktline;
} }
function ParamExtractValue(_param, _linesplit, _catname, _paramname, _aktline, _iscom, _anzvalue = 1) { function ParamExtractValue(_param, _linesplit, _catname, _paramname, _aktline, _iscom, _anzvalue = 1) {
if ((_linesplit[0].toUpperCase() == _paramname.toUpperCase()) && (_linesplit.length > _anzvalue)) { if ((_linesplit[0].toUpperCase() == _paramname.toUpperCase()) && (_linesplit.length > _anzvalue)) {
_param[_catname][_paramname]["found"] = true; _param[_catname][_paramname]["found"] = true;
@@ -417,7 +410,6 @@ function ParamExtractValue(_param, _linesplit, _catname, _paramname, _aktline, _
} }
} }
function ParamExtractValueAll(_param, _linesplit, _catname, _aktline, _iscom) { function ParamExtractValueAll(_param, _linesplit, _catname, _aktline, _iscom) {
for (var paramname in _param[_catname]) { for (var paramname in _param[_catname]) {
_AktROI = "default"; _AktROI = "default";
@@ -475,7 +467,6 @@ function ParamExtractValueAll(_param, _linesplit, _catname, _aktline, _iscom) {
} }
} }
function getCamConfig() { function getCamConfig() {
ParseConfig(); ParseConfig();
@@ -653,12 +644,10 @@ function getCamConfig() {
return param; return param;
} }
function getConfigParameters() { function getConfigParameters() {
return param; return param;
} }
function WriteConfigININew() { function WriteConfigININew() {
// Cleanup empty NUMBERS // Cleanup empty NUMBERS
for (var j = 0; j < NUMBERS.length; ++j) { for (var j = 0; j < NUMBERS.length; ++j) {
@@ -760,7 +749,6 @@ function WriteConfigININew() {
} }
} }
function isCommented(input) { function isCommented(input) {
let isComment = false; let isComment = false;
@@ -772,7 +760,6 @@ function isCommented(input) {
return [isComment, input]; return [isComment, input];
} }
function SaveConfigToServer(_domainname){ function SaveConfigToServer(_domainname){
// leere Zeilen am Ende löschen // leere Zeilen am Ende löschen
var zw = config_split.length - 1; var zw = config_split.length - 1;
@@ -792,17 +779,14 @@ function SaveConfigToServer(_domainname){
FileSendContent(config_gesamt, "/config/config.ini", _domainname); FileSendContent(config_gesamt, "/config/config.ini", _domainname);
} }
function getConfig() { function getConfig() {
return config_gesamt; return config_gesamt;
} }
function getConfigCategory() { function getConfigCategory() {
return category; return category;
} }
function ExtractROIs(_aktline, _type){ function ExtractROIs(_aktline, _type){
var linesplit = ZerlegeZeile(_aktline); var linesplit = ZerlegeZeile(_aktline);
abc = getNUMBERS(linesplit[0], _type); abc = getNUMBERS(linesplit[0], _type);
@@ -819,7 +803,6 @@ function ExtractROIs(_aktline, _type){
} }
} }
function getNUMBERS(_name, _type, _create = true) { function getNUMBERS(_name, _type, _create = true) {
_pospunkt = _name.indexOf ("."); _pospunkt = _name.indexOf (".");
@@ -879,7 +862,6 @@ function getNUMBERS(_name, _type, _create = true) {
return neuroi; return neuroi;
} }
function CopyReferenceToImgTmp(_domainname) { function CopyReferenceToImgTmp(_domainname) {
for (index = 0; index < 2; ++index) { for (index = 0; index < 2; ++index) {
_filenamevon = REFERENCES[index]["name"]; _filenamevon = REFERENCES[index]["name"];
@@ -894,12 +876,10 @@ function CopyReferenceToImgTmp(_domainname) {
} }
} }
function GetReferencesInfo(){ function GetReferencesInfo(){
return REFERENCES; return REFERENCES;
} }
function UpdateConfigReferences(_domainname){ function UpdateConfigReferences(_domainname){
for (var index = 0; index < 2; ++index) { for (var index = 0; index < 2; ++index) {
_filenamenach = REFERENCES[index]["name"]; _filenamenach = REFERENCES[index]["name"];
@@ -914,7 +894,6 @@ function UpdateConfigReferences(_domainname){
} }
} }
function UpdateConfigReference(_anzneueref, _domainname){ function UpdateConfigReference(_anzneueref, _domainname){
var index = 0; var index = 0;
@@ -939,12 +918,10 @@ function UpdateConfigReference(_anzneueref, _domainname){
FileCopyOnServer(_filenamevon, _filenamenach, _domainname); FileCopyOnServer(_filenamevon, _filenamenach, _domainname);
} }
function getNUMBERInfo(){ function getNUMBERInfo(){
return NUMBERS; return NUMBERS;
} }
function RenameNUMBER(_alt, _neu){ function RenameNUMBER(_alt, _neu){
if ((_neu.indexOf(".") >= 0) || (_neu.indexOf(",") >= 0) || (_neu.indexOf(" ") >= 0) || (_neu.indexOf("\"") >= 0)) { if ((_neu.indexOf(".") >= 0) || (_neu.indexOf(",") >= 0) || (_neu.indexOf(" ") >= 0) || (_neu.indexOf("\"") >= 0)) {
return "Number sequence name must not contain , . \" or a space"; return "Number sequence name must not contain , . \" or a space";
@@ -972,7 +949,6 @@ function RenameNUMBER(_alt, _neu){
return ""; return "";
} }
function DeleteNUMBER(_delete){ function DeleteNUMBER(_delete){
if (NUMBERS.length == 1) { if (NUMBERS.length == 1) {
return "One number sequence is mandatory. Therefore this cannot be deleted" return "One number sequence is mandatory. Therefore this cannot be deleted"
@@ -993,7 +969,6 @@ function DeleteNUMBER(_delete){
return ""; return "";
} }
function CreateNUMBER(_numbernew){ function CreateNUMBER(_numbernew){
found = false; found = false;
@@ -1041,7 +1016,6 @@ function CreateNUMBER(_numbernew){
return ""; return "";
} }
function getROIInfo(_typeROI, _number){ function getROIInfo(_typeROI, _number){
index = -1; index = -1;
@@ -1059,7 +1033,6 @@ function getROIInfo(_typeROI, _number){
} }
} }
function RenameROI(_number, _type, _alt, _neu){ function RenameROI(_number, _type, _alt, _neu){
if ((_neu.includes("=")) || (_neu.includes(".")) || (_neu.includes(":")) || (_neu.includes(",")) || (_neu.includes(";")) || (_neu.includes(" ")) || (_neu.includes("\""))) { if ((_neu.includes("=")) || (_neu.includes(".")) || (_neu.includes(":")) || (_neu.includes(",")) || (_neu.includes(";")) || (_neu.includes(" ")) || (_neu.includes("\""))) {
return "ROI name must not contain . : , ; = \" or space"; return "ROI name must not contain . : , ; = \" or space";
@@ -1098,7 +1071,6 @@ function RenameROI(_number, _type, _alt, _neu){
return ""; return "";
} }
function DeleteNUMBER(_delte) { function DeleteNUMBER(_delte) {
if (NUMBERS.length == 1) { if (NUMBERS.length == 1) {
return "The last number cannot be deleted" return "The last number cannot be deleted"
@@ -1119,7 +1091,6 @@ function DeleteNUMBER(_delte) {
return ""; return "";
} }
function CreateROI(_number, _type, _pos, _roinew, _x, _y, _dx, _dy, _CCW){ function CreateROI(_number, _type, _pos, _roinew, _x, _y, _dx, _dy, _CCW){
_indexnumber = -1; _indexnumber = -1;