diff --git a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp index 0bfe50bc..a60735f6 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp @@ -232,9 +232,9 @@ int ClassFlowCNNGeneral::ZeigerEvalHybridNeu(float zahl, float zahl_vorgaenger, } // bleibt nur >= 9.5 --> noch kein Nulldurchgang --> 2.8 --> 2, und 3.1 --> 2 - // alles <=x.6 kann als aktuelle Zahl gelten im Übergang. Bei 9.5 Vorgänger kann die aktuelle + // alles >=x.4 kann als aktuelle Zahl gelten im Übergang. Bei 9.5 Vorgänger kann die aktuelle // Zahl noch x.6 - x.7 sein. - if (ergebnis_nachkomma <= 6) + if (ergebnis_nachkomma >= 4) result = ergebnis_vorkomma; else result = (ergebnis_vorkomma - 1 + 10) % 10; diff --git a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h index 81556f01..c65d0dab 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h +++ b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h @@ -30,7 +30,7 @@ protected: int DigitalBand = 3; float DigitalAnalogerVorgaengerUebergangsbereich = 2; float DigitalUebergangsbereichVorgaengerAnalogToDigit = 1; // war vorher 2 - float DigitalUebergangsbereichVorgaenger = 0.9; + float DigitalUebergangsbereichVorgaenger = 0.7; // 9.3 - 0.7 string cnnmodelfile; int modelxsize, modelysize, modelchannel; diff --git a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp index 9d0f85c5..3631d6ae 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp @@ -9,6 +9,7 @@ #include #include "time_sntp.h" +//#define SERIAL_DEBUG // testing debug on serial enabled #define PREVALUE_TIME_FORMAT_OUTPUT "%Y-%m-%dT%H:%M:%S" @@ -663,7 +664,9 @@ bool ClassFlowPostProcessing::doFlow(string zwtime) previous_value = zw - 48; } } - + #ifdef SERIAL_DEBUG + printf("After analog->getReadout: ReturnRaw %s\n", NUMBERS[j]->ReturnRawValue.c_str()); + #endif if (NUMBERS[j]->digit_roi && NUMBERS[j]->analog_roi) NUMBERS[j]->ReturnRawValue = "." + NUMBERS[j]->ReturnRawValue; @@ -674,16 +677,22 @@ bool ClassFlowPostProcessing::doFlow(string zwtime) else NUMBERS[j]->ReturnRawValue = flowDigit->getReadout(j, NUMBERS[j]->isExtendedResolution, previous_value); // Extended Resolution nur falls es keine analogen Ziffern gibt } - + #ifdef SERIAL_DEBUG + printf("After digital->getReadout: ReturnRaw %s\n", NUMBERS[j]->ReturnRawValue.c_str()); + #endif NUMBERS[j]->ReturnRawValue = ShiftDecimal(NUMBERS[j]->ReturnRawValue, NUMBERS[j]->DecimalShift); - printf("ReturnRaw %s", NUMBERS[j]->ReturnRawValue.c_str()); - + #ifdef SERIAL_DEBUG + printf("After ShiftDecimal: ReturnRaw %s\n", NUMBERS[j]->ReturnRawValue.c_str()); + #endif if (IgnoreLeadingNaN) while ((NUMBERS[j]->ReturnRawValue.length() > 1) && (NUMBERS[j]->ReturnRawValue[0] == 'N')) NUMBERS[j]->ReturnRawValue.erase(0, 1); + #ifdef SERIAL_DEBUG + printf("After IgnoreLeadingNaN: ReturnRaw %s\n", NUMBERS[j]->ReturnRawValue.c_str()); + #endif NUMBERS[j]->ReturnValue = NUMBERS[j]->ReturnRawValue; if (findDelimiterPos(NUMBERS[j]->ReturnValue, "N") != std::string::npos) @@ -693,18 +702,27 @@ bool ClassFlowPostProcessing::doFlow(string zwtime) else continue; // es gibt keinen Zahl, da noch ein N vorhanden ist. } - + #ifdef SERIAL_DEBUG + printf("After findDelimiterPos: ReturnValue %s\n", NUMBERS[j]->ReturnRawValue.c_str()); + #endif // Lösche führende Nullen (außer es ist nur noch einen 0) while ((NUMBERS[j]->ReturnValue.length() > 1) && (NUMBERS[j]->ReturnValue[0] == '0')) NUMBERS[j]->ReturnValue.erase(0, 1); - + #ifdef SERIAL_DEBUG + printf("After removeLeadingZeros: ReturnValue %s\n", NUMBERS[j]->ReturnRawValue.c_str()); + #endif NUMBERS[j]->Value = std::stof(NUMBERS[j]->ReturnValue); + #ifdef SERIAL_DEBUG + printf("After setting the Value: Value %f and as double is %f\n", NUMBERS[j]->Value, std::stod(NUMBERS[j]->ReturnValue)); + #endif if (NUMBERS[j]->checkDigitIncreaseConsistency) { NUMBERS[j]->Value = checkDigitConsistency(NUMBERS[j]->Value, NUMBERS[j]->DecimalShift, NUMBERS[j]->analog_roi != NULL, NUMBERS[j]->PreValue); } - + #ifdef SERIAL_DEBUG + printf("After checkDigitIncreaseConsistency: Value %f\n", NUMBERS[j]->Value); + #endif if (!NUMBERS[j]->AllowNegativeRates) @@ -717,7 +735,9 @@ bool ClassFlowPostProcessing::doFlow(string zwtime) continue; } } - + #ifdef SERIAL_DEBUG + printf("After AllowNegativeRates: Value %f\n", NUMBERS[j]->Value); + #endif double difference = difftime(imagetime, NUMBERS[j]->lastvalue); // in Sekunden difference /= 60; NUMBERS[j]->FlowRateAct = (NUMBERS[j]->Value - NUMBERS[j]->PreValue) / difference; @@ -740,7 +760,9 @@ bool ClassFlowPostProcessing::doFlow(string zwtime) continue; } } - + #ifdef SERIAL_DEBUG + printf("After MaxRateCheck: Value %f\n", NUMBERS[j]->Value); + #endif NUMBERS[j]->ReturnChangeAbsolute = RundeOutput(NUMBERS[j]->Value - NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma); NUMBERS[j]->lastvalue = imagetime; NUMBERS[j]->PreValue = NUMBERS[j]->Value; @@ -885,8 +907,14 @@ float ClassFlowPostProcessing::checkDigitConsistency(float input, int _decilamsh { pot++; } + #ifdef SERIAL_DEBUG + printf("checkDigitConsistency: pot=%d, decimalshift=%d\n", pot, _decilamshift); + #endif pot_max = ((int) log10(input)) + 1; - + float not_checked_input = floorf(input * pow(10, pot)) / pow(10, pot); + #ifdef SERIAL_DEBUG + printf("checkDigitConsistency: not_checked_input=%f\n", not_checked_input); + #endif while (pot <= pot_max) { zw = input / pow(10, pot-1); @@ -915,11 +943,13 @@ float ClassFlowPostProcessing::checkDigitConsistency(float input, int _decilamsh input = input + ((float) (1)) * pow(10, pot); // addiere 1 an der Stelle } } - + #ifdef SERIAL_DEBUG + printf("checkDigitConsistency: input=%f", input); + #endif pot++; } - return input; + return not_checked_input + input; } string ClassFlowPostProcessing::getReadoutRate(int _number) diff --git a/code/test/components/jomjol-flowcontroll/test_flowpostprocessing.cpp b/code/test/components/jomjol-flowcontroll/test_flowpostprocessing.cpp index 851a997d..544ca7bb 100644 --- a/code/test/components/jomjol-flowcontroll/test_flowpostprocessing.cpp +++ b/code/test/components/jomjol-flowcontroll/test_flowpostprocessing.cpp @@ -5,7 +5,8 @@ #include void setUpClassFlowPostprocessing(void); -string process_doFlow(std::vector analog, std::vector digits, t_CNNType digType = Digital100); +string process_doFlow(std::vector analog, std::vector digits, t_CNNType digType = Digital100, + bool checkConsistency=false, bool extendedResolution=false, int decimal_shift=0); ClassFlowCNNGeneral* _analog; ClassFlowCNNGeneral* _digit; @@ -43,6 +44,7 @@ void test_doFlow() { std::vector digits = { 1.2, 6.7}; std::vector analogs = { 9.5, 8.4}; const char* expected = "16.98"; + const char* expected_extended = "16.984"; std::string result = process_doFlow(analogs, digits); TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); @@ -195,10 +197,70 @@ void test_doFlow() { // https://github.com/jomjol/AI-on-the-edge-device/issues/921#issuecomment-1242730397 digits = { 3.0, 2.0, 2.0, 8.0, 9.0, 4.0, 1.7, 9.8}; // falscher Wert 32290.420 analogs = { }; - expected = "32289420"; - result = process_doFlow(analogs, digits); + expected = "32289.420"; + expected_extended= "32289.4199"; + // FALSCH! wegen ungenügender Präzision von NUMBERS->Value + // expected_extended= "32289.4198"; + + // extendResolution=false, checkConsistency=false + result = process_doFlow(analogs, digits, Digital100, false, false, -3); TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); + // extendResolution=true + result = process_doFlow(analogs, digits, Digital100, false, true, -3); + TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); + + // checkConsistency=true und extendResolution=true + result = process_doFlow(analogs, digits, Digital100, false, true, -3); + TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); + + // Fehler Rolling (2022-09-10) + // not documented as issue + digits = { 0.0, 0.0, 7.9, 3.8}; // 84.99401 als falsches Ergebnis + analogs = { 0.0, 9.4, 4.1, 0.1}; + expected = "83.9940"; + expected_extended= "83.99401"; + + // checkConsistency=false + result = process_doFlow(analogs, digits, Digital100, false); + TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); + + + // checkConsistency=true + result = process_doFlow(analogs, digits, Digital100, true); + TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); + + // extendResolution=true + result = process_doFlow(analogs, digits, Digital100, false, true); + TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); + + // checkConsistency=true und extendResolution=true + result = process_doFlow(analogs, digits, Digital100, false, true); + TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); + + // Fehler Rolling (2022-09-10) + // https://github.com/jomjol/AI-on-the-edge-device/issues/994#issue-1368570945 + digits = { 0.0, 0.0, 1.0, 2.0, 2.8, 1.9, 2.8, 5.6}; // 123245.6 als falsches Ergebnis + analogs = { }; + expected = "123236"; + expected_extended= "123235.6"; + + // checkConsistency=true + result = process_doFlow(analogs, digits, Digital100, false, false); + TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); + + + // checkConsistency=true + result = process_doFlow(analogs, digits, Digital100, true, false); + TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); + + // extendResolution=true + result = process_doFlow(analogs, digits, Digital100, false, true); + TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); + + // checkConsistency=true und extendResolution=true + result = process_doFlow(analogs, digits, Digital100, false, true); + TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); } @@ -221,7 +283,8 @@ void setUpClassFlowPostprocessing(t_CNNType digType, t_CNNType anaType) } -std::string process_doFlow(std::vector analog, std::vector digits, t_CNNType digType) { +std::string process_doFlow(std::vector analog, std::vector digits, t_CNNType digType, + bool checkConsistency, bool extendedResolution, int decimal_shift) { // setup the classundertest setUpClassFlowPostprocessing(digType, Analogue100); @@ -231,7 +294,6 @@ std::string process_doFlow(std::vector analog, std::vector digits, if (digits.size()>0) { general* gen_digit = _digit->GetGENERAL("default", true); gen_digit->ROI.clear(); - for (int i = 0; i analog, std::vector digits, printf("Setup ROIs completed.\n"); undertestPost->InitNUMBERS(); + if (checkConsistency) { + printf("checkConsistency=true\n"); + std::vector* NUMBERS = undertestPost->GetNumbers(); + for (int _n = 0; _n < (*NUMBERS).size(); ++_n) { + printf("Set checkConsistency on number: %d\n", _n); + (*NUMBERS)[_n]->checkDigitIncreaseConsistency = true; + } + } + if (extendedResolution ) { + std::vector* NUMBERS = undertestPost->GetNumbers(); + for (int _n = 0; _n < (*NUMBERS).size(); ++_n) { + printf("Set extendedResolution on number: %d\n", _n); + (*NUMBERS)[_n]->isExtendedResolution = true; + } + + } + if (decimal_shift!=0) { + std::vector* NUMBERS = undertestPost->GetNumbers(); + for (int _n = 0; _n < (*NUMBERS).size(); ++_n) { + printf("Set decimalshif on number: %d to %d\n", _n, decimal_shift); + (*NUMBERS)[_n]->DecimalShift = decimal_shift; + (*NUMBERS)[_n]->DecimalShiftInitial = decimal_shift; + } + } string time; // run test