From f91f5e3cba24e04aeb90f2d77299c64e116667cb Mon Sep 17 00:00:00 2001 From: Frank Haverland Date: Mon, 17 Oct 2022 20:29:35 +0200 Subject: [PATCH 01/11] rewrite of ZeigerEvalAnalogToDigitNeu added explizit test-cases for it. --- .../ClassFlowCNNGeneral.cpp | 86 +++++++++--------- .../jomjol_flowcontroll/ClassFlowCNNGeneral.h | 8 +- .../ClassFlowDefineTypes.h | 1 + .../ClassFlowPostProcessing.cpp | 29 +++++- .../ClassFlowPostProcessing.h | 2 +- .../test_ZeigerEvalAnalogToDigitNeu.cpp | 88 +++++++++++++++++++ ...ow.cpp => test_flow_postrocess_helper.cpp} | 6 +- ...t_flow.h => test_flow_postrocess_helper.h} | 0 .../test_flow_pp_negative.cpp | 2 +- .../test_flowpostprocessing.cpp | 52 ++++++----- code/test/test_suite_flowcontroll.cpp | 9 +- sd-card/html/edit_config_param.html | 14 +++ 12 files changed, 215 insertions(+), 82 deletions(-) create mode 100644 code/test/components/jomjol-flowcontroll/test_ZeigerEvalAnalogToDigitNeu.cpp rename code/test/components/jomjol-flowcontroll/{test_flow.cpp => test_flow_postrocess_helper.cpp} (97%) rename code/test/components/jomjol-flowcontroll/{test_flow.h => test_flow_postrocess_helper.h} (100%) diff --git a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp index 661ce729..908dc25a 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp @@ -10,7 +10,7 @@ static const char* TAG = "flow_analog"; -bool debugdetailgeneral = false; + ClassFlowCNNGeneral::ClassFlowCNNGeneral(ClassFlowAlignment *_flowalign, t_CNNType _cnntype) : ClassFlowImage(NULL, TAG) { @@ -28,7 +28,7 @@ ClassFlowCNNGeneral::ClassFlowCNNGeneral(ClassFlowAlignment *_flowalign, t_CNNTy flowpostalignment = _flowalign; } -string ClassFlowCNNGeneral::getReadout(int _analog = 0, bool _extendedResolution, int prev, float _vorgaengerAnalog) +string ClassFlowCNNGeneral::getReadout(int _analog = 0, bool _extendedResolution, int prev, float _vorgaengerAnalog, float analogDigitalTransitionStart) { string result = ""; @@ -87,7 +87,7 @@ string ClassFlowCNNGeneral::getReadout(int _analog = 0, bool _extendedResolution { // prev = ZeigerEval(GENERAL[_analog]->ROI[GENERAL[_analog]->ROI.size() - 1]->result_float, prev); if (_vorgaengerAnalog >= 0) - prev = ZeigerEvalHybridNeu(GENERAL[_analog]->ROI[GENERAL[_analog]->ROI.size() - 1]->result_float, _vorgaengerAnalog, prev, true); + prev = ZeigerEvalHybridNeu(GENERAL[_analog]->ROI[GENERAL[_analog]->ROI.size() - 1]->result_float, _vorgaengerAnalog, prev, true, analogDigitalTransitionStart); else prev = ZeigerEvalHybridNeu(GENERAL[_analog]->ROI[GENERAL[_analog]->ROI.size() - 1]->result_float, prev, prev); result = std::to_string(prev); @@ -127,7 +127,7 @@ string ClassFlowCNNGeneral::getReadout(int _analog = 0, bool _extendedResolution return result; } -int ClassFlowCNNGeneral::ZeigerEvalHybridNeu(float zahl, float zahl_vorgaenger, int eval_vorgaenger, bool AnalogerVorgaenger) +int ClassFlowCNNGeneral::ZeigerEvalHybridNeu(float zahl, float zahl_vorgaenger, int eval_vorgaenger, bool AnalogerVorgaenger, float digitalAnalogTransitionStart) { int result; int ergebnis_nachkomma = ((int) floor(zahl * 10)) % 10; @@ -147,7 +147,7 @@ int ClassFlowCNNGeneral::ZeigerEvalHybridNeu(float zahl, float zahl_vorgaenger, if (AnalogerVorgaenger) { - result = ZeigerEvalAnalogToDigitNeu(zahl, zahl_vorgaenger, eval_vorgaenger); + result = ZeigerEvalAnalogToDigitNeu(zahl, zahl_vorgaenger, eval_vorgaenger, digitalAnalogTransitionStart); if (debugdetailgeneral) LogFile.WriteToFile("ClassFlowCNNGeneral::ZeigerEvalHybridNeu - Analoger Vorgänger, Bewertung über ZeigerEvalAnalogNeu = " + std::to_string(result) + " zahl: " + std::to_string(zahl) + " zahl_vorgaenger = " + std::to_string(zahl_vorgaenger)+ " eval_vorgaenger = " + std::to_string(eval_vorgaenger) + " DigitalUnschaerfe = " + std::to_string(DigitalUnschaerfe)); return result; @@ -201,55 +201,49 @@ int ClassFlowCNNGeneral::ZeigerEvalHybridNeu(float zahl, float zahl_vorgaenger, } -int ClassFlowCNNGeneral::ZeigerEvalAnalogToDigitNeu(float zahl, float ziffer_vorgaenger, int eval_vorgaenger) +int ClassFlowCNNGeneral::ZeigerEvalAnalogToDigitNeu(float zahl, float ziffer_vorgaenger, int eval_vorgaenger, float analogDigitalTransitionStart) { int result; int ergebnis_nachkomma = ((int) floor(zahl * 10)) % 10; int ergebnis_vorkomma = ((int) floor(zahl) + 10) % 10; + bool roundedUp = false; - if (ziffer_vorgaenger < 0) - { - result = (int) floor(zahl); - if (debugdetailgeneral) LogFile.WriteToFile("ClassFlowCNNGeneral::ZeigerEvalAnalogToDigitNeu - kein Vorgänger - Ergebnis = " + std::to_string(result) + - " zahl: " + std::to_string(zahl) + " ziffer_vorgaenger = " + std::to_string(ziffer_vorgaenger) + " AnalogFehler = " + std::to_string(AnalogFehler)); - return result; - } - - if (ziffer_vorgaenger <= 3 && eval_vorgaenger<9) // Nulldurchgang hat stattgefunden (!Bewertung über Prev_value und nicht Zahl!) --> hier aufrunden (2.8 --> 3, aber auch 3.1 --> 3) - // aber Sonderfall ziffer_vorgaeger = 0.1 vor_vorgaenger 9.9 => eval_vorgaenger ist 9, damit hat Nulldurchgang nicht stattgefunden. - { - if (ergebnis_nachkomma > 5) - result = (ergebnis_vorkomma + 1) % 10; - else - result = ergebnis_vorkomma; - if (debugdetailgeneral) LogFile.WriteToFile("ClassFlowCNNGeneral::ZeigerEvalAnalogToDigitNeu - Nulldurchgang hat stattgefunden = " + std::to_string(result) + - " zahl: " + std::to_string(zahl) + " ziffer_vorgaenger = " + std::to_string(ziffer_vorgaenger) + " DigitalUnschaerfe = " + std::to_string(DigitalUnschaerfe)); - return result; - } - - // Vorlauf ziffer_vorgaenger <=9.9 und ergebnis_nachkomma >=0..1 (digits drehen nach umschalten nicht gleich weiter) - // Beispiel dig=4.0, ana=9.1 ==> dig=3 - - // Nachlauf ziffer_vorgaenger 0..2 und ergebnis_nachkomma 8..9 - // Beispiel dig=6.8, ana=2.2 ==> dig=7 - // dig=4.8, ana=5.5 => dig=4 - - // Vorlauf bei ergebnis_nachkomma >=0..1 und ziffer_vorgaenger 8..9 - if (ergebnis_nachkomma <= 1 && ziffer_vorgaenger>=8) { - result = (ergebnis_vorkomma - 1 + 10) % 10; + // Innerhalb der digitalen Unschaefe + if (ergebnis_nachkomma >= (10-DigitalUnschaerfe * 10)) { // Band um die Ziffer --> Runden, da Ziffer im Rahmen Ungenauigkeit erreicht + result = (int) (round(zahl) + 10) % 10; + roundedUp = true; + // vor/nachkomma neu berechnen, da wir anhand der Unschaefe die Zahl anpassen. + ergebnis_nachkomma = ((int) floor(result * 10)) % 10; + ergebnis_vorkomma = ((int) floor(result) + 10) % 10; + if (debugdetailgeneral) LogFile.WriteToFile("ClassFlowCNNGeneral::ZeigerEvalAnalogToDigitNeu - digitaleUnschaerfe - Ergebnis = " + std::to_string(result) + + " zahl: " + std::to_string(zahl) + " ziffer_vorgaenger: " + std::to_string(ziffer_vorgaenger) + + " erg_vorkomma: " + std::to_string(ergebnis_vorkomma) + + " erg_nachkomma: " + std::to_string(ergebnis_nachkomma)); } else { - // Ziffer bleibt bei x.8 oder x.9 "hängen", kommt also nicht richtig auf x.0 - // muss eine Rundung erfolgen - // jedoch nicht im während der Transition (ziffer_vorgaenger>=8) - if (eval_vorgaenger<9 && ziffer_vorgaenger<8 && ergebnis_nachkomma >= 8) - result = ((int) round(zahl) + 10) % 10; - else - result = ergebnis_vorkomma; + result = (int) ((int) trunc(zahl) + 10) % 10; + if (debugdetailgeneral) LogFile.WriteToFile("ClassFlowCNNGeneral::ZeigerEvalAnalogToDigitNeu - KEINE digitaleUnschaerfe - Ergebnis = " + std::to_string(result) + + " zahl: " + std::to_string(zahl) + " ziffer_vorgaenger = " + std::to_string(ziffer_vorgaenger)); } - - if (debugdetailgeneral) LogFile.WriteToFile("ClassFlowCNNGeneral::ZeigerEvalAnalogToDigitNeu - 9.0 --> noch kein Nulldurchgang = " + std::to_string(result) + - " zahl: " + std::to_string(zahl) + " ziffer_vorgaenger = " + std::to_string(ziffer_vorgaenger) + " DigitalUnschaerfe = " + std::to_string(DigitalUnschaerfe)); + + // Kein Nulldurchgang hat stattgefunden. + // Nur eval_vorgaenger verwendet, da ziffer_vorgaenger hier falsch sein könnte. + // ziffer_vorgaenger<=0.1 & eval_vorgaenger=9 entspricht analog wurde zurückgesetzt wegen vorhergehender analog, die noch nicht auf 0 sind. + if ((eval_vorgaenger>=9 && (ziffer_vorgaenger>analogDigitalTransitionStart || ziffer_vorgaenger<=0.2) && roundedUp) + // digit läuft dem Analog vor. Darf aber erst passieren, wenn + // digit wirklich schnon los läuft, deshalb 9 + || (eval_vorgaenger>9 && ziffer_vorgaenger>analogDigitalTransitionStart && ergebnis_nachkomma<=1)) + + { + result = ((ergebnis_vorkomma+10) - 1) % 10; + if (debugdetailgeneral) LogFile.WriteToFile("ClassFlowCNNGeneral::ZeigerEvalAnalogToDigitNeu - Nulldurchgang noch nicht stattgefunden = " + std::to_string(result) + + " zahl: " + std::to_string(zahl) + + " ziffer_vorgaenger = " + std::to_string(ziffer_vorgaenger) + + " erg_nachkomma = " + std::to_string(ergebnis_nachkomma)); + + } + return result; + } int ClassFlowCNNGeneral::ZeigerEvalAnalogNeu(float zahl, int ziffer_vorgaenger) diff --git a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h index 055df5e3..03c48d8c 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h +++ b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h @@ -20,6 +20,7 @@ class ClassFlowCNNGeneral : public ClassFlowImage { protected: + bool debugdetailgeneral = false; t_CNNType CNNType; std::vector GENERAL; float CNNGoodThreshold; @@ -28,7 +29,6 @@ protected: float DigitalUnschaerfe = 0.2; int DigitalBand = 3; float DigitalAnalogerVorgaengerUebergangsbereich = 2; - // nicht mehr benötigt float DigitalUebergangsbereichVorgaengerAnalogToDigit = 1; // war vorher 2 float DigitalUebergangsbereichVorgaenger = 0.7; // 9.3 - 0.7 float DigitalUebergangsbereichVorlauf = 9.7; // Vorlauf-Nulldurchgang passiert erst ab ca. 9.7 @@ -41,8 +41,8 @@ protected: bool SaveAllFiles; int ZeigerEvalAnalogNeu(float zahl, int ziffer_vorgaenger); - int ZeigerEvalAnalogToDigitNeu(float zahl, float ziffer_vorgaenger, int eval_vorgaenger); - int ZeigerEvalHybridNeu(float zahl, float zahl_vorgaenger, int eval_vorgaenger, bool AnalogerVorgaenger = false); + int ZeigerEvalAnalogToDigitNeu(float zahl, float ziffer_vorgaenger, int eval_vorgaenger, float analogDigitalTransitionStart); + int ZeigerEvalHybridNeu(float zahl, float zahl_vorgaenger, int eval_vorgaenger, bool AnalogerVorgaenger = false, float analogDigitalTransitionStart=9.2); @@ -58,7 +58,7 @@ public: bool doFlow(string time); string getHTMLSingleStep(string host); - string getReadout(int _analog, bool _extendedResolution = false, int prev = -1, float _vorgaengerAnalog = -1); + string getReadout(int _analog, bool _extendedResolution = false, int prev = -1, float _vorgaengerAnalog = -1, float analogDigitalTransitionStart=9.2); void DrawROI(CImageBasis *_zw); diff --git a/code/components/jomjol_flowcontroll/ClassFlowDefineTypes.h b/code/components/jomjol_flowcontroll/ClassFlowDefineTypes.h index c296ca27..c7ebc693 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowDefineTypes.h +++ b/code/components/jomjol_flowcontroll/ClassFlowDefineTypes.h @@ -46,6 +46,7 @@ struct NumberPost { int AnzahlDigital; int DecimalShift; int DecimalShiftInitial; + float AnalogDigitalTransitionStart; // Wann ist das digit > x.1, also wann fängt es an zu kippen int Nachkomma; bool isExtendedResolution; diff --git a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp index e0b900eb..cb6bbb00 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp @@ -343,6 +343,29 @@ void ClassFlowPostProcessing::handleDecimalSeparator(string _decsep, string _val } } +void ClassFlowPostProcessing::handleAnalogDigitalTransitionStart(string _decsep, string _value) +{ + string _digit, _decpos; + int _pospunkt = _decsep.find_first_of("."); +// printf("Name: %s, Pospunkt: %d\n", _decsep.c_str(), _pospunkt); + if (_pospunkt > -1) + _digit = _decsep.substr(0, _pospunkt); + else + _digit = "default"; + + for (int j = 0; j < NUMBERS.size(); ++j) + { + float _zwdc = 9.2; + { + _zwdc = stof(_value); + } + if (_digit == "default" || NUMBERS[j]->name == _digit) // erstmal auf default setzen (falls sonst nichts gesetzt) + { + NUMBERS[j]->AnalogDigitalTransitionStart = _zwdc; + + } + } +} void ClassFlowPostProcessing::handleMaxRateType(string _decsep, string _value) @@ -447,6 +470,10 @@ bool ClassFlowPostProcessing::ReadParameter(FILE* pfile, string& aktparamgraph) { handleDecimalSeparator(zerlegt[0], zerlegt[1]); } + if ((toUpper(_param) == "ANALOG_DIGITAL_TRANSITION_START") && (zerlegt.size() > 1)) + { + handleAnalogDigitalTransitionStart(zerlegt[0], zerlegt[1]); + } if ((toUpper(_param) == "MAXRATEVALUE") && (zerlegt.size() > 1)) { handleMaxRateValue(zerlegt[0], zerlegt[1]); @@ -674,7 +701,7 @@ bool ClassFlowPostProcessing::doFlow(string zwtime) if (NUMBERS[j]->digit_roi) { if (NUMBERS[j]->analog_roi) - NUMBERS[j]->ReturnRawValue = flowDigit->getReadout(j, false, previous_value, NUMBERS[j]->analog_roi->ROI[0]->result_float) + NUMBERS[j]->ReturnRawValue; + NUMBERS[j]->ReturnRawValue = flowDigit->getReadout(j, false, previous_value, NUMBERS[j]->analog_roi->ROI[0]->result_float, NUMBERS[j]->AnalogDigitalTransitionStart) + NUMBERS[j]->ReturnRawValue; else NUMBERS[j]->ReturnRawValue = flowDigit->getReadout(j, NUMBERS[j]->isExtendedResolution, previous_value); // Extended Resolution nur falls es keine analogen Ziffern gibt } diff --git a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.h b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.h index 9d63804b..dac4d4f1 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.h +++ b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.h @@ -41,7 +41,7 @@ protected: void handleMaxRateValue(string _decsep, string _value); void handleDecimalExtendedResolution(string _decsep, string _value); void handleMaxRateType(string _decsep, string _value); - + void handleAnalogDigitalTransitionStart(string _decsep, string _value); diff --git a/code/test/components/jomjol-flowcontroll/test_ZeigerEvalAnalogToDigitNeu.cpp b/code/test/components/jomjol-flowcontroll/test_ZeigerEvalAnalogToDigitNeu.cpp new file mode 100644 index 00000000..3e0c8fbb --- /dev/null +++ b/code/test/components/jomjol-flowcontroll/test_ZeigerEvalAnalogToDigitNeu.cpp @@ -0,0 +1,88 @@ +#include +#include + +class UnderTestCNNGeneral : public ClassFlowCNNGeneral { + public: + UnderTestCNNGeneral( ClassFlowAlignment *_flowalign, t_CNNType _cnntype) : + ClassFlowCNNGeneral(_flowalign, _cnntype) {}; + + using ClassFlowCNNGeneral::ZeigerEvalAnalogToDigitNeu; + + +}; + + +/** + * @brief + * + * Transition = x.8 - x.2 hier keine Transition in den Testfaellen + * Versatz = dig=x.n, ana= n.y: kein Versatz, da beide "n" gleich + */ +void test_analogToDigit_Standard() { + + UnderTestCNNGeneral* undertest = new UnderTestCNNGeneral(nullptr, Digital100); + + // 4.8 ist eine "hängende" 5. Heißt sie ist nicht bis auf 5.0 umgesprungen. + // ab Transition sollte trotzdem ein "hängendes Digit" gerundet werden. + // Transition = ja + // Versatz = nein + TEST_ASSERT_EQUAL_INT(5, undertest->ZeigerEvalAnalogToDigitNeu(4.8, 8.0, 8, 9.2)); + + // https://github.com/jomjol/AI-on-the-edge-device/issues/921#issue-1344032217 + // Standard: dig=9.6, ana=6.8 => erg=9 + // Transition = nein + // Versatz = nein + TEST_ASSERT_EQUAL_INT(9, undertest->ZeigerEvalAnalogToDigitNeu( 9.6, 6.8, 6, 9.2)); + + + // https://github.com/jomjol/AI-on-the-edge-device/issues/921#issuecomment-1220365920 + // Standard: dig=4.6, ana=6.2 => erg=4 + // Transition = nein + // Versatz = nein + TEST_ASSERT_EQUAL_INT(4, undertest->ZeigerEvalAnalogToDigitNeu( 4.6, 6.2, 6, 9.2)); + + // https://github.com/jomjol/AI-on-the-edge-device/issues/1143#issuecomment-1274434805 + // Hängendes digit () + // Standard: dig=6.8, ana=8.6 => erg=7 + // Transition = nein + // Versatz = nein + TEST_ASSERT_EQUAL_INT(7, undertest->ZeigerEvalAnalogToDigitNeu( 6.8, 8.6, 6, 9.2)); + + // https://github.com/jomjol/AI-on-the-edge-device/issues/1143#issuecomment-1274434805 + // Ebenfalls Hängendes digit () bei kleinem Zeiger nach 0-Durchlauf + // Standard: dig=6.8, ana=1.0 => erg=7 + // Transition = nein + // Versatz = nein + TEST_ASSERT_EQUAL_INT(7, undertest->ZeigerEvalAnalogToDigitNeu( 6.8, 8.6, 6, 9.2)); + + +} + +void test_analogToDigit_Transition() { + UnderTestCNNGeneral* undertest = new UnderTestCNNGeneral(nullptr, Digital100); + + // https://github.com/jomjol/AI-on-the-edge-device/issues/921#issuecomment-1222672175 + // Standard: dig=3.9, ana=9.7 => erg=3 + // Transition = ja + // Nulldurchgang = nein + // Versatz = nein + TEST_ASSERT_EQUAL_INT(3, undertest->ZeigerEvalAnalogToDigitNeu( 3.9, 9.7, 9, 9.2)); + + // ohne Referenz + // Standard: dig=4.0, ana=9.1 => erg=4 + // Transition = ja + // Nulldurchgang = nein + // Versatz = nein + // Besonderheit: Digit ist bei analog 9.1 noch nicht losgelaufen + TEST_ASSERT_EQUAL_INT(4, undertest->ZeigerEvalAnalogToDigitNeu( 4.0, 9.1, 9, 9.2)); + + // ohne Referenz + // Standard: dig=9.8, ana=0.1, ana_2=9.9 => erg=9 + // Transition = ja + // Nulldurchgang = nein + // Versatz = nein + // Besonderheit: analog wird durch vorherigen analog wieder auf 9 gesetzt + TEST_ASSERT_EQUAL_INT(9, undertest->ZeigerEvalAnalogToDigitNeu( 9.8, 0.1, 9, 9.2)); + + +} diff --git a/code/test/components/jomjol-flowcontroll/test_flow.cpp b/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.cpp similarity index 97% rename from code/test/components/jomjol-flowcontroll/test_flow.cpp rename to code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.cpp index 41d02a75..283e7fc3 100644 --- a/code/test/components/jomjol-flowcontroll/test_flow.cpp +++ b/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.cpp @@ -1,4 +1,4 @@ -#include "test_flow.h" +#include "test_flow_postrocess_helper.h" UnderTestPost* setUpClassFlowPostprocessing(t_CNNType digType, t_CNNType anaType) @@ -42,7 +42,9 @@ std::string process_doFlow(std::vector analog, std::vector digits, // run test TEST_ASSERT_TRUE(_undertestPost->doFlow(time)); - return _undertestPost->getReadout(0); + std::string result = _undertestPost->getReadout(0); + delete _undertestPost; + return result; } diff --git a/code/test/components/jomjol-flowcontroll/test_flow.h b/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.h similarity index 100% rename from code/test/components/jomjol-flowcontroll/test_flow.h rename to code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.h diff --git a/code/test/components/jomjol-flowcontroll/test_flow_pp_negative.cpp b/code/test/components/jomjol-flowcontroll/test_flow_pp_negative.cpp index 6fd55da7..0a650deb 100644 --- a/code/test/components/jomjol-flowcontroll/test_flow_pp_negative.cpp +++ b/code/test/components/jomjol-flowcontroll/test_flow_pp_negative.cpp @@ -1,4 +1,4 @@ -#include "test_flow.h" +#include "test_flow_postrocess_helper.h" diff --git a/code/test/components/jomjol-flowcontroll/test_flowpostprocessing.cpp b/code/test/components/jomjol-flowcontroll/test_flowpostprocessing.cpp index da9e001d..3d9082d8 100644 --- a/code/test/components/jomjol-flowcontroll/test_flowpostprocessing.cpp +++ b/code/test/components/jomjol-flowcontroll/test_flowpostprocessing.cpp @@ -1,9 +1,12 @@ -#include "test_flow.h" +#include "test_flow_postrocess_helper.h" /** + * ACHTUNG! Die Test laufen aktuell nur mit ausgeschaltetem Debug in ClassFlowCNNGeneral + * + * * @brief Testet die doFlow-Methode von ClassFlowPostprocessing * digits[] - enthält die liste der vom Model zurückgegebenen Ergebnisse (class100/cont) in der Reihenfolge von links nach rechts * analog[] - enthält die Liste der Zeiger vom Model, wie bei den digits @@ -29,7 +32,7 @@ void test_doFlow() { TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); /* - * https://github.com/jomjol/AI-on-the-edge-device/issues/921 + * https://github.com/jomjol/AI-on-the-edge-device/issues/921#issue-1344032217 * * Das Ergebnis sollte "376529.6" sein. */ @@ -40,7 +43,7 @@ void test_doFlow() { TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); /* - * https://github.com/jomjol/AI-on-the-edge-device/issues/921 + * https://github.com/jomjol/AI-on-the-edge-device/issues/921#issuecomment-1220365920 * * Das Ergebnis sollte "167734.6" sein. Bzw. 16.98 ohne Extended true */ @@ -81,13 +84,13 @@ void test_doFlow() { digits = { 1.1, 9.0, 4.0}; analogs = { 8.1, 2.6, 6.25, 9.7}; - expected = "193.8259"; + expected = "194.8259"; result = process_doFlow(analogs, digits); TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); digits = { 1.1, 9.0, 4.0}; analogs = { 9.1, 2.6, 6.25, 9.7}; - expected = "193.9259"; + expected = "194.9259"; result = process_doFlow(analogs, digits); TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); @@ -346,10 +349,10 @@ void test_doFlow() { // Fehler bei V12.0.1 // https://github.com/jomjol/AI-on-the-edge-device/issues/1110#issue-1391153343 - digits = { 1.0, 4.0, 2.0}; // 142.9269 als falsches Ergebnis + digits = { 1.0, 4.0, 2.0}; // 141.9269 als falsches Ergebnis analogs = { 9.2, 2.5, 6.8, 9.0}; - expected = "141.9269"; - expected_extended= "141.92690"; + expected = "142.9269"; + expected_extended= "142.92690"; // extendResolution=false result = process_doFlow(analogs, digits, Digital100, false, false, 0); @@ -364,8 +367,11 @@ void test_doFlow() { // https://github.com/jomjol/AI-on-the-edge-device/issues/1110#issuecomment-1262626388 digits = { 1.2, 6.8, 0.0, 0.0, 5.0, 2.8}; //170.05387 als falsches Ergebnis analogs = { 8.7}; - expected = "170.0528"; - expected_extended= "170.05287"; + // Aktuell nicht sicher, ob doch + expected = "170.0538"; + expected_extended= "170.05387"; + //expected = "170.0528"; + //expected_extended= "170.05287"; // extendResolution=false result = process_doFlow(analogs, digits, Digital100, false, false, -3); @@ -378,10 +384,10 @@ void test_doFlow() { // Fehler bei rolling post V12.0.1 // lokal watermeter1 - digits = { 0.0, 0.0, 9.0, 1.0}; //91.88174 als falsches Ergebnis + digits = { 0.0, 0.0, 9.0, 1.0}; //90.88174 als falsches Ergebnis analogs = {9.0, 8.0, 1.8, 7.4}; - expected = "90.8817"; - expected_extended= "90.88174"; + expected = "91.8817"; + expected_extended= "91.88174"; // extendResolution=false result = process_doFlow(analogs, digits, Digital100, false, false, 0); @@ -426,9 +432,8 @@ void test_doFlow() { // https://github.com/jomjol/AI-on-the-edge-device/issues/1143#issuecomment-1274434805 digits = { 4.9, 6.9, 6.8}; // 576.8649 als falsches Ergebnis analogs = {8.6, 6.2, 5.0, 9.0}; - // fall unklar ob wirklich 577 oder 576, erst mal 577 - expected = "576.8649"; - expected_extended= "576.86490"; + expected = "577.8649"; + expected_extended= "577.86490"; // extendResolution=false result = process_doFlow(analogs, digits, Digital100, false, false, 0); @@ -440,19 +445,18 @@ void test_doFlow() { // Fehler V12.0.1 "TODO 00211.03480 vs 00211.03580" - // Lokal - digits = { 4.9, 6.9, 6.8}; // 576.8649 als falsches Ergebnis - analogs = {8.6, 6.2, 5.0, 9.0}; - // fall unklar ob wirklich 577 oder 576, erst mal 577 - expected = "576.8649"; - expected_extended= "576.86490"; + // Lokal "Hängendes Digit" + digits = { 2.0, 1.0, 1.0, 0.0, 3.0, 4.8}; // 00211.03480 als falsches Ergebnis + analogs = {8.0}; + expected = "211.0358"; + expected_extended= "211.03580"; // extendResolution=false - result = process_doFlow(analogs, digits, Digital100, false, false, 0); + result = process_doFlow(analogs, digits, Digital100, false, false, -3); TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); // checkConsistency=false und extendResolution=true - result = process_doFlow(analogs, digits, Digital100, false, true, 0); + result = process_doFlow(analogs, digits, Digital100, false, true, -3); TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); diff --git a/code/test/test_suite_flowcontroll.cpp b/code/test/test_suite_flowcontroll.cpp index de4343cc..9d096e84 100644 --- a/code/test/test_suite_flowcontroll.cpp +++ b/code/test/test_suite_flowcontroll.cpp @@ -1,8 +1,9 @@ #include -#include "components/jomjol-flowcontroll/test_flow.cpp" +#include "components/jomjol-flowcontroll/test_flow_postrocess_helper.cpp" #include "components/jomjol-flowcontroll/test_flowpostprocessing.cpp" #include "components/jomjol-flowcontroll/test_flow_pp_negative.cpp" +#include "components/jomjol-flowcontroll/test_ZeigerEvalAnalogToDigitNeu.cpp" // SD-Card //////////////////// #include "nvs_flash.h" #include "esp_vfs_fat.h" @@ -104,8 +105,10 @@ extern "C" void app_main() Init_NVS_SDCard(); UNITY_BEGIN(); - RUN_TEST(testNegative); - RUN_TEST(test_doFlow); + RUN_TEST(test_analogToDigit_Standard); + RUN_TEST(test_analogToDigit_Transition); + //RUN_TEST(testNegative); + RUN_TEST(test_doFlow); UNITY_END(); } \ No newline at end of file diff --git a/sd-card/html/edit_config_param.html b/sd-card/html/edit_config_param.html index caf488b6..d5ef7007 100644 --- a/sd-card/html/edit_config_param.html +++ b/sd-card/html/edit_config_param.html @@ -489,6 +489,20 @@ textarea { Shift the digit separator within the digital digits (positiv and negativ) + + + + + + + + + + If you have false Values, but the recognition is correct. Look for the start of changing of the first digit and note the analog pointer value behind. Set it here. + Only used on combination of digits and analog pointers. + + + From 5d35df65f3c5231deb9ce8761c22355e8ccdecd7 Mon Sep 17 00:00:00 2001 From: Frank Haverland Date: Mon, 17 Oct 2022 20:29:50 +0200 Subject: [PATCH 02/11] add testNegative --- code/test/test_suite_flowcontroll.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/code/test/test_suite_flowcontroll.cpp b/code/test/test_suite_flowcontroll.cpp index 9d096e84..f91be40c 100644 --- a/code/test/test_suite_flowcontroll.cpp +++ b/code/test/test_suite_flowcontroll.cpp @@ -104,10 +104,11 @@ extern "C" void app_main() initGPIO(); Init_NVS_SDCard(); UNITY_BEGIN(); - + + RUN_TEST(testNegative); + RUN_TEST(test_analogToDigit_Standard); RUN_TEST(test_analogToDigit_Transition); - //RUN_TEST(testNegative); RUN_TEST(test_doFlow); UNITY_END(); From 426d6bae3ff31649d5c495234877ad9e5bd3c99f Mon Sep 17 00:00:00 2001 From: Frank Haverland Date: Mon, 17 Oct 2022 20:37:15 +0200 Subject: [PATCH 03/11] fix name of ANALOGDIGITALTRANSITIONSTART --- code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp index cb6bbb00..ac168c7f 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp @@ -470,7 +470,7 @@ bool ClassFlowPostProcessing::ReadParameter(FILE* pfile, string& aktparamgraph) { handleDecimalSeparator(zerlegt[0], zerlegt[1]); } - if ((toUpper(_param) == "ANALOG_DIGITAL_TRANSITION_START") && (zerlegt.size() > 1)) + if ((toUpper(_param) == "ANALOGDIGITALTRANSITIONSTART") && (zerlegt.size() > 1)) { handleAnalogDigitalTransitionStart(zerlegt[0], zerlegt[1]); } From e5649d03b29c8028e54cd4ff217b83b74afa8102 Mon Sep 17 00:00:00 2001 From: Frank Haverland Date: Mon, 17 Oct 2022 20:40:20 +0200 Subject: [PATCH 04/11] min and max of ANALOGDIGITALTRANSITIONSTART added --- sd-card/html/edit_config_param.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sd-card/html/edit_config_param.html b/sd-card/html/edit_config_param.html index d5ef7007..5cc65890 100644 --- a/sd-card/html/edit_config_param.html +++ b/sd-card/html/edit_config_param.html @@ -495,7 +495,7 @@ textarea { - + If you have false Values, but the recognition is correct. Look for the start of changing of the first digit and note the analog pointer value behind. Set it here. From ace1936a7822fdb921e4be69aa332ca6d2cd5da8 Mon Sep 17 00:00:00 2001 From: Frank Haverland Date: Mon, 17 Oct 2022 20:47:12 +0200 Subject: [PATCH 05/11] added AnalogDigitalTransitionStart to expert config --- sd-card/html/edit_config_param.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sd-card/html/edit_config_param.html b/sd-card/html/edit_config_param.html index 5cc65890..a3e12541 100644 --- a/sd-card/html/edit_config_param.html +++ b/sd-card/html/edit_config_param.html @@ -490,7 +490,7 @@ textarea { - + From be8598bcaa3fa306a7d09579cdc89b6b91cbc100 Mon Sep 17 00:00:00 2001 From: Frank Haverland Date: Mon, 17 Oct 2022 21:36:11 +0200 Subject: [PATCH 06/11] read and save config for AnalogDigitalTransitionStart --- sd-card/config/config.ini | 1 + sd-card/html/edit_config_param.html | 8 +++++--- sd-card/html/readconfigparam.js | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/sd-card/config/config.ini b/sd-card/config/config.ini index ee7c75fc..138e9a72 100644 --- a/sd-card/config/config.ini +++ b/sd-card/config/config.ini @@ -42,6 +42,7 @@ main.ana4 155 328 92 92 false [PostProcessing] main.DecimalShift = 0 +main.AnalogDigitalTransitionStart = 9.2 PreValueUse = true PreValueAgeStartup = 720 AllowNegativeRates = false diff --git a/sd-card/html/edit_config_param.html b/sd-card/html/edit_config_param.html index a3e12541..bbd04232 100644 --- a/sd-card/html/edit_config_param.html +++ b/sd-card/html/edit_config_param.html @@ -490,16 +490,16 @@ textarea { - + - + If you have false Values, but the recognition is correct. Look for the start of changing of the first digit and note the analog pointer value behind. Set it here. - Only used on combination of digits and analog pointers. + Only used on combination of digits and analog pointers. Default=9.2 @@ -1684,6 +1684,7 @@ function UpdateInputIndividual() if (NUNBERSAkt != -1) { ReadParameter(param, "PostProcessing", "DecimalShift", true, NUNBERSAkt) + ReadParameter(param, "PostProcessing", "AnalogDigitalTransitionStart", true, NUNBERSAkt) ReadParameter(param, "PostProcessing", "MaxRateValue", true, NUNBERSAkt) ReadParameter(param, "PostProcessing", "MaxRateType", true, NUNBERSAkt) ReadParameter(param, "PostProcessing", "ExtendedResolution", true, NUNBERSAkt) @@ -1693,6 +1694,7 @@ function UpdateInputIndividual() var sel = document.getElementById("Numbers_value1"); NUNBERSAkt = sel.selectedIndex; WriteParameter(param, category, "PostProcessing", "DecimalShift", true, NUNBERSAkt); + WriteParameter(param, category, "PostProcessing", "AnalogDigitalTransitionStart", true, NUNBERSAkt); WriteParameter(param, category, "PostProcessing", "MaxRateValue", true, NUNBERSAkt); WriteParameter(param, category, "PostProcessing", "MaxRateType", true, NUNBERSAkt); WriteParameter(param, category, "PostProcessing", "ExtendedResolution", true, NUNBERSAkt); diff --git a/sd-card/html/readconfigparam.js b/sd-card/html/readconfigparam.js index afbedc5d..9e7eb8b7 100644 --- a/sd-card/html/readconfigparam.js +++ b/sd-card/html/readconfigparam.js @@ -102,6 +102,7 @@ function ParseConfig() { category[catname]["found"] = false; param[catname] = new Object(); ParamAddValue(param, catname, "DecimalShift", 1, true); + ParamAddValue(param, catname, "AnalogDigitalTransitionStart", 1, true); ParamAddValue(param, catname, "PreValueUse"); ParamAddValue(param, catname, "PreValueAgeStartup"); ParamAddValue(param, catname, "AllowNegativeRates"); From bc46149573eda04ee7a86228f59731f7b1d1efca Mon Sep 17 00:00:00 2001 From: Frank Haverland Date: Mon, 17 Oct 2022 22:22:47 +0200 Subject: [PATCH 07/11] init the analogDigitalTransitionStart with 9.2 if nothing set in config --- .../jomjol_flowcontroll/ClassFlowCNNGeneral.h | 2 +- .../jomjol_flowcontroll/ClassFlowPostProcessing.cpp | 1 + .../test_ZeigerEvalAnalogToDigitNeu.cpp | 10 +++++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h index 03c48d8c..5731c0a2 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h +++ b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h @@ -20,7 +20,7 @@ class ClassFlowCNNGeneral : public ClassFlowImage { protected: - bool debugdetailgeneral = false; + bool debugdetailgeneral = true; t_CNNType CNNType; std::vector GENERAL; float CNNGoodThreshold; diff --git a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp index ac168c7f..d500a1ec 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp @@ -584,6 +584,7 @@ void ClassFlowPostProcessing::InitNUMBERS() _number->DecimalShift = 0; _number->DecimalShiftInitial = 0; _number->isExtendedResolution = false; + _number->AnalogDigitalTransitionStart=9.2; _number->FlowRateAct = 0; // m3 / min diff --git a/code/test/components/jomjol-flowcontroll/test_ZeigerEvalAnalogToDigitNeu.cpp b/code/test/components/jomjol-flowcontroll/test_ZeigerEvalAnalogToDigitNeu.cpp index 3e0c8fbb..c3d79740 100644 --- a/code/test/components/jomjol-flowcontroll/test_ZeigerEvalAnalogToDigitNeu.cpp +++ b/code/test/components/jomjol-flowcontroll/test_ZeigerEvalAnalogToDigitNeu.cpp @@ -53,7 +53,7 @@ void test_analogToDigit_Standard() { // Standard: dig=6.8, ana=1.0 => erg=7 // Transition = nein // Versatz = nein - TEST_ASSERT_EQUAL_INT(7, undertest->ZeigerEvalAnalogToDigitNeu( 6.8, 8.6, 6, 9.2)); + TEST_ASSERT_EQUAL_INT(7, undertest->ZeigerEvalAnalogToDigitNeu( 6.8, 1.0, 1, 9.2)); } @@ -85,4 +85,12 @@ void test_analogToDigit_Transition() { TEST_ASSERT_EQUAL_INT(9, undertest->ZeigerEvalAnalogToDigitNeu( 9.8, 0.1, 9, 9.2)); + // https://github.com/jomjol/AI-on-the-edge-device/issues/1110#issuecomment-1277425333 + // Standard: dig=5.9, ana=9.4 => erg=9 + // Transition = ja + // Nulldurchgang = nein + // Versatz = nein + // Besonderheit: + TEST_ASSERT_EQUAL_INT(5, undertest->ZeigerEvalAnalogToDigitNeu( 5.9, 9.4, 9, 9.2)); + } From fc0bbc57cb1466340ad7e5ed59a51624ec6d17af Mon Sep 17 00:00:00 2001 From: Frank Haverland Date: Mon, 17 Oct 2022 22:27:39 +0200 Subject: [PATCH 08/11] update changelog --- Changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Changelog.md b/Changelog.md index d25f3ca8..d2a0c7f1 100644 --- a/Changelog.md +++ b/Changelog.md @@ -10,6 +10,7 @@ - Updated built environment to `espressif32@v5.2.0` - [#1176](https://github.com/jomjol/AI-on-the-edge-device/discussions/1176) accept minor negative values (-0.2) if extended resolution is enabled +- [#1143](https://github.com/jomjol/AI-on-the-edge-device/issues/1143) added config parameter AnalogDigitalTransitionStart. It can setup very early and very late digit transition starts. ### Fixed - [#1116](https://github.com/jomjol/AI-on-the-edge-device/issues/1116) precision problem at setting prevalue From 0e55fc7f7ed14160a716451194d324250b0368b1 Mon Sep 17 00:00:00 2001 From: Frank Haverland Date: Tue, 18 Oct 2022 23:01:09 +0200 Subject: [PATCH 09/11] add @Plawasan test cases. Works now with setable analogdigitTransistionstart --- .../ClassFlowCNNGeneral.cpp | 2 +- .../jomjol_flowcontroll/ClassFlowCNNGeneral.h | 2 +- .../test_ZeigerEvalAnalogToDigitNeu.cpp | 8 +++ .../test_flow_postrocess_helper.cpp | 10 +++ .../test_flow_postrocess_helper.h | 8 +++ .../test_flowpostprocessing.cpp | 69 ++++++++++++++++--- 6 files changed, 89 insertions(+), 10 deletions(-) diff --git a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp index 908dc25a..77e00d7c 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp @@ -228,7 +228,7 @@ int ClassFlowCNNGeneral::ZeigerEvalAnalogToDigitNeu(float zahl, float ziffer_vor // Kein Nulldurchgang hat stattgefunden. // Nur eval_vorgaenger verwendet, da ziffer_vorgaenger hier falsch sein könnte. // ziffer_vorgaenger<=0.1 & eval_vorgaenger=9 entspricht analog wurde zurückgesetzt wegen vorhergehender analog, die noch nicht auf 0 sind. - if ((eval_vorgaenger>=9 && (ziffer_vorgaenger>analogDigitalTransitionStart || ziffer_vorgaenger<=0.2) && roundedUp) + if ((eval_vorgaenger>=6 && (ziffer_vorgaenger>analogDigitalTransitionStart || ziffer_vorgaenger<=0.2) && roundedUp) // digit läuft dem Analog vor. Darf aber erst passieren, wenn // digit wirklich schnon los läuft, deshalb 9 || (eval_vorgaenger>9 && ziffer_vorgaenger>analogDigitalTransitionStart && ergebnis_nachkomma<=1)) diff --git a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h index 5731c0a2..03c48d8c 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h +++ b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h @@ -20,7 +20,7 @@ class ClassFlowCNNGeneral : public ClassFlowImage { protected: - bool debugdetailgeneral = true; + bool debugdetailgeneral = false; t_CNNType CNNType; std::vector GENERAL; float CNNGoodThreshold; diff --git a/code/test/components/jomjol-flowcontroll/test_ZeigerEvalAnalogToDigitNeu.cpp b/code/test/components/jomjol-flowcontroll/test_ZeigerEvalAnalogToDigitNeu.cpp index c3d79740..a118a74c 100644 --- a/code/test/components/jomjol-flowcontroll/test_ZeigerEvalAnalogToDigitNeu.cpp +++ b/code/test/components/jomjol-flowcontroll/test_ZeigerEvalAnalogToDigitNeu.cpp @@ -93,4 +93,12 @@ void test_analogToDigit_Transition() { // Besonderheit: TEST_ASSERT_EQUAL_INT(5, undertest->ZeigerEvalAnalogToDigitNeu( 5.9, 9.4, 9, 9.2)); + // https://github.com/jomjol/AI-on-the-edge-device/issues/1110#issuecomment-1282168030 + // Standard: dig=1.8, ana=7.8 => erg=9 + // Transition = ja + // Nulldurchgang = nein + // Versatz = nein + // Besonderheit: Digit läuft mit Analog mit. Deshalb 1.8 (vs. 7.8) + TEST_ASSERT_EQUAL_INT(1, undertest->ZeigerEvalAnalogToDigitNeu( 1.8, 7.8, 7, 7.7)); + } diff --git a/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.cpp b/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.cpp index 283e7fc3..c37e0577 100644 --- a/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.cpp +++ b/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.cpp @@ -142,3 +142,13 @@ void setDecimalShift(UnderTestPost* _underTestPost, int _decimal_shift) { } } } + +void setAnalogdigitTransistionStart(UnderTestPost* _underTestPost, float _analogdigitTransistionStart) { + if (_analogdigitTransistionStart!=0) { + std::vector* NUMBERS = _underTestPost->GetNumbers(); + for (int _n = 0; _n < (*NUMBERS).size(); ++_n) { + printf("Setting decimal shift on number: %d to %f\n", _n, _analogdigitTransistionStart); + (*NUMBERS)[_n]->AnalogDigitalTransitionStart = _analogdigitTransistionStart; + } + } +} diff --git a/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.h b/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.h index e9f54262..6b103f25 100644 --- a/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.h +++ b/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.h @@ -99,4 +99,12 @@ void setExtendedResolution(UnderTestPost* _UnderTestPost, bool _extendedResoluti */ void setDecimalShift(UnderTestPost* _UnderTestPost, int decimal_shift); +/** + * @brief Set the Analogdigit Transistion Start + * + * @param _underTestPost the testobject + * @param _analogdigitTransistionStart the analog to digit transition start + */ +void setAnalogdigitTransistionStart(UnderTestPost* _underTestPost, float _analogdigitTransistionStart); + #endif // TEST_FLOW_H diff --git a/code/test/components/jomjol-flowcontroll/test_flowpostprocessing.cpp b/code/test/components/jomjol-flowcontroll/test_flowpostprocessing.cpp index 3d9082d8..228ff4d8 100644 --- a/code/test/components/jomjol-flowcontroll/test_flowpostprocessing.cpp +++ b/code/test/components/jomjol-flowcontroll/test_flowpostprocessing.cpp @@ -366,21 +366,24 @@ void test_doFlow() { // Fehler bei V12.0.1 // https://github.com/jomjol/AI-on-the-edge-device/issues/1110#issuecomment-1262626388 digits = { 1.2, 6.8, 0.0, 0.0, 5.0, 2.8}; //170.05387 als falsches Ergebnis + // letztes digit läuft mit analog zeiger mit. Hier nur lösbar mit setAnalogdigitTransistionStart=7.7 analogs = { 8.7}; - // Aktuell nicht sicher, ob doch - expected = "170.0538"; - expected_extended= "170.05387"; - //expected = "170.0528"; - //expected_extended= "170.05287"; + expected = "170.0528"; + expected_extended= "170.05287"; // extendResolution=false - result = process_doFlow(analogs, digits, Digital100, false, false, -3); + UnderTestPost* undertestPost = init_do_flow(analogs, digits, Digital100, false, false, -3); + setAnalogdigitTransistionStart(undertestPost, 7.7); + result = process_doFlow(undertestPost); TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); + delete undertestPost; // checkConsistency=false und extendResolution=true - result = process_doFlow(analogs, digits, Digital100, false, true, -3); + undertestPost = init_do_flow(analogs, digits, Digital100, false, true, -3); + setAnalogdigitTransistionStart(undertestPost, 7.7); + result = process_doFlow(undertestPost); TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); - + delete undertestPost; // Fehler bei rolling post V12.0.1 // lokal watermeter1 @@ -459,7 +462,57 @@ void test_doFlow() { result = process_doFlow(analogs, digits, Digital100, false, true, -3); TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); + // Fehler V12.0.1 + // https://github.com/jomjol/AI-on-the-edge-device/issues/1143#issuecomment-1281231468 + digits = { 1.0, 1.9, 6.0}; // 125.923 als falsches Ergebnis + analogs = {9.3, 2.3, 3.1}; + expected = "126.923"; + expected_extended= "126.9231"; + + // extendResolution=false + result = process_doFlow(analogs, digits, Digital100, false, false, 0); + TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); + // checkConsistency=false und extendResolution=true + result = process_doFlow(analogs, digits, Digital100, false, true, 0); + TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); + + // Fehler V12.0.1 + // https://github.com/jomjol/AI-on-the-edge-device/issues/1110#issuecomment-1282168030 + digits = { 3.0, 8.1, 5.9, 0.0, 5.0, 6.7}; // 386.05672 als richtiges Ergebnis. Letztes digit schein mit dem Analogzeiger mitzulaufen + analogs = {7.2}; + expected = "386.0567"; + expected_extended= "386.05672"; + + // extendResolution=false + result = process_doFlow(analogs, digits, Digital100, false, false, -3); + TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); + + // checkConsistency=false und extendResolution=true + result = process_doFlow(analogs, digits, Digital100, false, true, -3); + TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); + + // Fehler V12.0.1 + // https://github.com/jomjol/AI-on-the-edge-device/issues/1110#issuecomment-1282168030 + digits = { 1.2, 7.0, 1.2, 2.0, 4.0, 1.8}; // 171.24278 als falsches Ergebnis. + // Test ist nur erfolgreich mit Veränderung des AnalogdigitTransistionStart + analogs = {7.8}; + expected = "171.2417"; + expected_extended= "171.24178"; + + // extendResolution=false + undertestPost = init_do_flow(analogs, digits, Digital100, false, false, -3); + setAnalogdigitTransistionStart(undertestPost, 7.7); + result = process_doFlow(undertestPost); + TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); + delete undertestPost; + + // checkConsistency=false und extendResolution=true + undertestPost = init_do_flow(analogs, digits, Digital100, false, true, -3); + setAnalogdigitTransistionStart(undertestPost, 7.7); + result = process_doFlow(undertestPost); + TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); + delete undertestPost; } From 33b9a15f732dbbe5e4c796db1384fe329f189494 Mon Sep 17 00:00:00 2001 From: Frank Haverland Date: Tue, 18 Oct 2022 23:02:11 +0200 Subject: [PATCH 10/11] enable debug on CNNGeneral --- code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h index 03c48d8c..5731c0a2 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h +++ b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h @@ -20,7 +20,7 @@ class ClassFlowCNNGeneral : public ClassFlowImage { protected: - bool debugdetailgeneral = false; + bool debugdetailgeneral = true; t_CNNType CNNType; std::vector GENERAL; float CNNGoodThreshold; From cd2350140d0a02dc7972a99a0f2d69316b67d61c Mon Sep 17 00:00:00 2001 From: Slider0007 Date: Wed, 19 Oct 2022 09:32:52 +0200 Subject: [PATCH 11/11] Fix for image logging + file deletion routines --- code/components/jomjol_flowcontroll/ClassFlowImage.cpp | 10 ++++++---- code/components/jomjol_helper/Helper.cpp | 2 +- code/components/jomjol_logfile/ClassLogFile.cpp | 5 +++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/code/components/jomjol_flowcontroll/ClassFlowImage.cpp b/code/components/jomjol_flowcontroll/ClassFlowImage.cpp index 8fd45139..a5c9ca54 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowImage.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowImage.cpp @@ -65,7 +65,7 @@ void ClassFlowImage::LogImage(string logPath, string name, float *resultFloat, i else { sprintf(buf, "%.1f_", *resultFloat); - if (strcmp(buf, "10.0_")) + if (strcmp(buf, "10.0_") == 0) sprintf(buf, "0.0_"); } @@ -119,14 +119,16 @@ void ClassFlowImage::RemoveOldLogs() string folderPath = LogImageLocation + "/" + entry->d_name; if (entry->d_type == DT_DIR) { //ESP_LOGI(logTag, "Compare %s %s", entry->d_name, folderName.c_str()); - if ((strlen(entry->d_name) == folderName.length()) && (strcmp(entry->d_name, folderName.c_str()) < 0)) { - deleted += removeFolder(folderPath.c_str(), logTag); + if ((strlen(entry->d_name) == folderName.length()) && (strcmp(entry->d_name, folderName.c_str()) == 0)) { + removeFolder(folderPath.c_str(), logTag); + deleted++; } else { notDeleted ++; } } } - ESP_LOGI(logTag, "%d older log files deleted. %d current log files not deleted.", deleted, notDeleted); + ESP_LOGI(logTag, "%d image folder deleted. %d image folder not deleted.", deleted, notDeleted); + LogFile.WriteToFile("Image folder deleted: " + std::to_string(deleted) + ". Image folder not deleted: " + std::to_string(notDeleted)); closedir(dir); } diff --git a/code/components/jomjol_helper/Helper.cpp b/code/components/jomjol_helper/Helper.cpp index 2d543735..3c1bc20b 100644 --- a/code/components/jomjol_helper/Helper.cpp +++ b/code/components/jomjol_helper/Helper.cpp @@ -319,7 +319,7 @@ string getDirectory(string filename) string getFileType(string filename) { - size_t lastpos = filename.find(".", 0); + size_t lastpos = filename.rfind(".", filename.length()); size_t neu_pos; while ((neu_pos = filename.find(".", lastpos + 1)) > -1) { diff --git a/code/components/jomjol_logfile/ClassLogFile.cpp b/code/components/jomjol_logfile/ClassLogFile.cpp index 3d3605d9..17507a42 100644 --- a/code/components/jomjol_logfile/ClassLogFile.cpp +++ b/code/components/jomjol_logfile/ClassLogFile.cpp @@ -176,7 +176,7 @@ void ClassLogFile::RemoveOld() while ((entry = readdir(dir)) != NULL) { if (entry->d_type == DT_REG) { //ESP_LOGI(TAG, "list log file : %s %s", entry->d_name, cmpfilename); - if ((strlen(entry->d_name) == strlen(cmpfilename)) && (strcmp(entry->d_name, cmpfilename) < 0)) { + if ((strlen(entry->d_name) == strlen(cmpfilename)) && (strcmp(entry->d_name, cmpfilename) == 0)) { ESP_LOGI(TAG, "delete log file : %s", entry->d_name); std::string filepath = logroot + "/" + entry->d_name; if (unlink(filepath.c_str()) == 0) { @@ -189,7 +189,8 @@ void ClassLogFile::RemoveOld() } } } - ESP_LOGI(TAG, "%d older log files deleted. %d current log files not deleted.", deleted, notDeleted); + ESP_LOGI(TAG, "%d logfiles deleted. %d files not deleted (incl. leer.txt).", deleted, notDeleted); + LogFile.WriteToFile("logfiles deleted: " + std::to_string(deleted) + " files not deleted (incl. leer.txt): " + std::to_string(notDeleted)); closedir(dir); }