Merge pull request #1183 from haverland/minor_negative_accept

fix change for tollerance for extendedResolution.
This commit is contained in:
jomjol
2022-10-16 21:59:32 +02:00
committed by GitHub
7 changed files with 355 additions and 118 deletions

View File

@@ -728,22 +728,30 @@ bool ClassFlowPostProcessing::doFlow(string zwtime)
} }
else else
{ {
printf("checkDigitIncreaseConsistency = true - no digital numbers defined!\n"); #ifdef SERIAL_DEBUG
printf("checkDigitIncreaseConsistency = true - no digital numbers defined!\n");
#endif
} }
} }
#ifdef SERIAL_DEBUG #ifdef SERIAL_DEBUG
printf("After checkDigitIncreaseConsistency: Value %f\n", NUMBERS[j]->Value); printf("After checkDigitIncreaseConsistency: Value %f\n", NUMBERS[j]->Value);
#endif #endif
if (!NUMBERS[j]->AllowNegativeRates) if (!NUMBERS[j]->AllowNegativeRates)
{ {
if ((NUMBERS[j]->Value < NUMBERS[j]->PreValue)) if ((NUMBERS[j]->Value < NUMBERS[j]->PreValue))
{ {
#ifdef SERIAL_DEBUG
printf("Neg: value=%f, preValue=%f, preToll%f\n", NUMBERS[j]->Value, NUMBERS[j]->PreValue,
NUMBERS[j]->PreValue-(2/pow(10, NUMBERS[j]->Nachkomma))
) ;
#endif
// Bei isExtendedResolution Ungenauigkeit von 0.2 mit einrechnen. // Bei isExtendedResolution Ungenauigkeit von 0.2 mit einrechnen.
if (NUMBERS[j]->Value < (NUMBERS[j]->PreValue-0.2) && NUMBERS[j]->isExtendedResolution) { if (NUMBERS[j]->Value >= (NUMBERS[j]->PreValue-(2/pow(10, NUMBERS[j]->Nachkomma))) && NUMBERS[j]->isExtendedResolution) {
NUMBERS[j]->Value = NUMBERS[j]->PreValue; NUMBERS[j]->Value = NUMBERS[j]->PreValue;
NUMBERS[j]->ReturnValue = to_string(NUMBERS[j]->PreValue);
} else { } else {
NUMBERS[j]->ErrorMessageText = NUMBERS[j]->ErrorMessageText + "Neg. Rate - Read: " + zwvalue + " - Raw: " + NUMBERS[j]->ReturnRawValue + " - Pre: " + RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma) + " "; NUMBERS[j]->ErrorMessageText = NUMBERS[j]->ErrorMessageText + "Neg. Rate - Read: " + zwvalue + " - Raw: " + NUMBERS[j]->ReturnRawValue + " - Pre: " + RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma) + " ";
NUMBERS[j]->Value = NUMBERS[j]->PreValue; NUMBERS[j]->Value = NUMBERS[j]->PreValue;
@@ -929,9 +937,6 @@ float ClassFlowPostProcessing::checkDigitConsistency(double input, int _decilams
printf("checkDigitConsistency: pot=%d, decimalshift=%d\n", pot, _decilamshift); printf("checkDigitConsistency: pot=%d, decimalshift=%d\n", pot, _decilamshift);
#endif #endif
pot_max = ((int) log10(input)) + 1; pot_max = ((int) log10(input)) + 1;
#ifdef SERIAL_DEBUG
printf("checkDigitConsistency: not_checked_input=%f\n", not_checked_input);
#endif
while (pot <= pot_max) while (pot <= pot_max)
{ {
zw = input / pow(10, pot-1); zw = input / pow(10, pot-1);

View File

@@ -49,6 +49,7 @@ public:
bool PreValueUse; bool PreValueUse;
ClassFlowPostProcessing(std::vector<ClassFlow*>* lfc, ClassFlowCNNGeneral *_analog, ClassFlowCNNGeneral *_digit); ClassFlowPostProcessing(std::vector<ClassFlow*>* lfc, ClassFlowCNNGeneral *_analog, ClassFlowCNNGeneral *_digit);
virtual ~ClassFlowPostProcessing(){};
bool ReadParameter(FILE* pfile, string& aktparamgraph); bool ReadParameter(FILE* pfile, string& aktparamgraph);
bool doFlow(string time); bool doFlow(string time);
string getReadout(int _number); string getReadout(int _number);

View File

@@ -0,0 +1,142 @@
#include "test_flow.h"
UnderTestPost* setUpClassFlowPostprocessing(t_CNNType digType, t_CNNType anaType)
{
ClassFlowCNNGeneral* _analog;
ClassFlowCNNGeneral* _digit;
std::vector<ClassFlow*> FlowControll;
ClassFlowMakeImage* flowmakeimage;
// wird im doFlow verwendet
flowmakeimage = new ClassFlowMakeImage(&FlowControll);
FlowControll.push_back(flowmakeimage);
// Die Modeltypen werden gesetzt, da keine Modelle verwendet werden.
_analog = new ClassFlowCNNGeneral(nullptr, anaType);
_digit = new ClassFlowCNNGeneral(nullptr, digType);
return new UnderTestPost(&FlowControll, _analog, _digit);
}
std::string process_doFlow(UnderTestPost* _underTestPost) {
string time;
// run test
TEST_ASSERT_TRUE(_underTestPost->doFlow(time));
return _underTestPost->getReadout(0);
}
std::string process_doFlow(std::vector<float> analog, std::vector<float> digits, t_CNNType digType,
bool checkConsistency, bool extendedResolution, int decimal_shift) {
// setup the classundertest
UnderTestPost* _undertestPost = init_do_flow(analog, digits, digType, checkConsistency, extendedResolution, decimal_shift);
printf("SetupClassFlowPostprocessing completed.\n");
string time;
// run test
TEST_ASSERT_TRUE(_undertestPost->doFlow(time));
return _undertestPost->getReadout(0);
}
UnderTestPost* init_do_flow(std::vector<float> analog, std::vector<float> digits, t_CNNType digType,
bool checkConsistency, bool extendedResolution, int decimal_shift) {
UnderTestPost* _undertestPost = setUpClassFlowPostprocessing(digType, Analogue100);
// digits
if (digits.size()>0) {
general* gen_digit = _undertestPost->flowDigit->GetGENERAL("default", true);
gen_digit->ROI.clear();
for (int i = 0; i<digits.size(); i++) {
roi* digitROI = new roi();
string name = "digit_" + std::to_string(i);
digitROI->name = name;
digitROI->result_klasse = (int) digits[i];
digitROI->result_float = digits[i];
gen_digit->ROI.push_back(digitROI);
}
}
// analog
if (analog.size()>0) {
general* gen_analog = _undertestPost->flowAnalog->GetGENERAL("default", true);
gen_analog->ROI.clear();
for (int i = 0; i<analog.size(); i++) {
roi* anaROI = new roi();
string name = "ana_" + std::to_string(i);
anaROI->name = name;
anaROI->result_float = analog[i];
gen_analog->ROI.push_back(anaROI);
}
}
printf("Setting up of ROIs completed.\n");
_undertestPost->InitNUMBERS();
setConsitencyCheck(_undertestPost, checkConsistency);
setExtendedResolution(_undertestPost, extendedResolution);
setDecimalShift(_undertestPost, decimal_shift);
return _undertestPost;
}
void setPreValue(UnderTestPost* _underTestPost, double _preValue) {
if (_preValue>0) {
printf("preValue=%f", _preValue);
std::vector<NumberPost*>* NUMBERS = _underTestPost->GetNumbers();
for (int _n = 0; _n < (*NUMBERS).size(); ++_n) {
(*NUMBERS)[_n]->PreValue = _preValue;
}
}
}
void setAllowNegatives(UnderTestPost* _underTestPost, bool _allowNegatives) {
printf("checkConsistency=true\n");
std::vector<NumberPost*>* NUMBERS = _underTestPost->GetNumbers();
for (int _n = 0; _n < (*NUMBERS).size(); ++_n) {
(*NUMBERS)[_n]->AllowNegativeRates = _allowNegatives;
}
}
void setConsitencyCheck(UnderTestPost* _underTestPost, bool _checkConsistency) {
if (_checkConsistency) {
printf("checkConsistency=true\n");
std::vector<NumberPost*>* NUMBERS = _underTestPost->GetNumbers();
for (int _n = 0; _n < (*NUMBERS).size(); ++_n) {
(*NUMBERS)[_n]->checkDigitIncreaseConsistency = true;
}
}
}
void setExtendedResolution(UnderTestPost* _underTestPost, bool _extendedResolution) {
if (_extendedResolution ) {
std::vector<NumberPost*>* NUMBERS = _underTestPost->GetNumbers();
for (int _n = 0; _n < (*NUMBERS).size(); ++_n) {
(*NUMBERS)[_n]->isExtendedResolution = true;
}
}
}
void setDecimalShift(UnderTestPost* _underTestPost, int _decimal_shift) {
if (_decimal_shift!=0) {
std::vector<NumberPost*>* NUMBERS = _underTestPost->GetNumbers();
for (int _n = 0; _n < (*NUMBERS).size(); ++_n) {
printf("Setting decimal shift on number: %d to %d\n", _n, _decimal_shift);
(*NUMBERS)[_n]->DecimalShift = _decimal_shift;
(*NUMBERS)[_n]->DecimalShiftInitial = _decimal_shift;
}
}
}

View File

@@ -0,0 +1,102 @@
#pragma once
#ifndef TEST_FLOW_H
#define TEST_FLOW_H
#include <unity.h>
#include <ClassFlowPostProcessing.h>
#include <ClassFlowCNNGeneral.h>
#include <ClassFlowCNNGeneral.h>
#include <ClassFlowMakeImage.h>
class UnderTestPost : public ClassFlowPostProcessing {
public:
UnderTestPost(std::vector<ClassFlow*>* lfc, ClassFlowCNNGeneral *_analog, ClassFlowCNNGeneral *_digit)
: ClassFlowPostProcessing::ClassFlowPostProcessing(lfc, _analog, _digit) {}
using ClassFlowPostProcessing::InitNUMBERS;
using ClassFlowPostProcessing::RundeOutput;
using ClassFlowPostProcessing::flowAnalog;
using ClassFlowPostProcessing::flowDigit;
};
/**
* @brief Set the Up Class Flow Postprocessing object
*
* @param digType the model type of digits
* @param anaType the model type of analog
* @return UnderTestPost* a created, but not setted up testobject
*/
UnderTestPost* setUpClassFlowPostprocessing(t_CNNType digType, t_CNNType anaType);
/**
* @brief creates a testobject (including setup). AnalogType is Class100, because all analog types do the same.
*
* @param analog the analog recognitions
* @param digits the digit recognitions
* @param digType the digit model type (default Digital100)
* @param checkConsistency sets property checkConsistency (default = false)
* @param extendedResolution sets property extendedResolution (default = false)
* @param decimal_shift set property decimal_shift (Nachkommastellen, default = 0)
* @return UnderTestPost* the created testobject
*/
UnderTestPost* init_do_flow(std::vector<float> analog, std::vector<float> digits, t_CNNType digType = Digital100,
bool checkConsistency=false, bool extendedResolution=false, int decimal_shift=0);
/**
* @brief creates a testobject an run do flow (including setup). AnalogType is Class100, because all analog types do the same.
*
* @param analog the analog recognitions
* @param digits the digit recognitions
* @param digType the digit model type (default Digital100)
* @param checkConsistency sets property checkConsistency (default = false)
* @param extendedResolution sets property extendedResolution (default = false)
* @param decimal_shift set property decimal_shift (Nachkommastellen, default = 0)
* @return std::string the return value of do_Flow is the Value as string
*/
std::string process_doFlow(std::vector<float> analog, std::vector<float> digits, t_CNNType digType = Digital100,
bool checkConsistency=false, bool extendedResolution=false, int decimal_shift=0);
/**
* @brief run do_Flow on the testobject
*
* @param _underTestPost the testobject
* @return std::string the return value of do_Flow is the Value as string
*/
std::string process_doFlow(UnderTestPost* _underTestPost);
/**
* @brief Set the Consitency Check on testobject
*
* @param _UnderTestPost the testobject
* @param _checkConsistency true/false if checkConsistency
*/
void setConsitencyCheck(UnderTestPost* _UnderTestPost, bool _checkConsistency);
/**
* @brief Set the Pre Value on testobject
*
* @param _UnderTestPost the testobject
* @param _preValue the previous value
*/
void setPreValue(UnderTestPost* _UnderTestPost, double _preValue);
/**
* @brief Set the Extended Resolution on undertest
*
* @param _UnderTestPost the testobject
* @param _extendedResolution true/false
*/
void setExtendedResolution(UnderTestPost* _UnderTestPost, bool _extendedResolution);
/**
* @brief Set the Decimal Shift (Nachkomma)
*
* @param _UnderTestPost the testobject
* @param decimal_shift count of nachkomma
*/
void setDecimalShift(UnderTestPost* _UnderTestPost, int decimal_shift);
#endif // TEST_FLOW_H

View File

@@ -0,0 +1,75 @@
#include "test_flow.h"
/**
* @brief Testfall für Überprüfung allowNegatives
*
*/
void testNegative() {
// Ohne decimal_shift
std::vector<float> digits = { 1.2, 6.7};
std::vector<float> analogs = { 9.5, 8.4};
double preValue_extended = 16.985;
double preValue = 16.98;
const char* expected = "16.98";
// extendResolution=false
// da kein negativ, sollte kein Error auftreten
UnderTestPost* underTestPost = init_do_flow(analogs, digits, Digital100, false, false, 0);
setAllowNegatives(underTestPost, false);
setPreValue(underTestPost, preValue);
std::string result = process_doFlow(underTestPost);
TEST_ASSERT_EQUAL_STRING("no error", underTestPost->getReadoutError().c_str());
TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
delete underTestPost;
// extendResolution=true
// da negativ im Rahmen (letzte Stelle -0.2 > ergebnis), kein Error
// Aber der PreValue wird gesetzt
underTestPost = init_do_flow(analogs, digits, Digital100, false, true, 0);
setAllowNegatives(underTestPost, false);
setPreValue(underTestPost, preValue_extended);
result = process_doFlow(underTestPost);
TEST_ASSERT_EQUAL_STRING("no error", underTestPost->getReadoutError().c_str());
TEST_ASSERT_EQUAL_STRING(underTestPost->RundeOutput(preValue_extended, analogs.size()+1).c_str(), result.c_str());
delete underTestPost;
// extendResolution=true
// Tolleranz überschritten, Error wird gesetzt, kein ReturnValue
preValue_extended = 16.988; // zu groß
underTestPost = init_do_flow(analogs, digits, Digital100, false, true, 0);
setAllowNegatives(underTestPost, false);
setPreValue(underTestPost, preValue_extended);
result = process_doFlow(underTestPost);
TEST_ASSERT_EQUAL_STRING("Neg. Rate - Read: - Raw: 16.984 - Pre: 16.988 ", underTestPost->getReadoutError().c_str());
TEST_ASSERT_EQUAL_STRING("", result.c_str());
delete underTestPost;
// extendResolution=false
// value < preValue
preValue = 16.99; // zu groß
underTestPost = init_do_flow(analogs, digits, Digital100, false, false, 0);
setAllowNegatives(underTestPost, false);
setPreValue(underTestPost, preValue_extended);
result = process_doFlow(underTestPost);
TEST_ASSERT_EQUAL_STRING("Neg. Rate - Read: - Raw: 16.98 - Pre: 16.99 ", underTestPost->getReadoutError().c_str());
TEST_ASSERT_EQUAL_STRING("", result.c_str());
delete underTestPost;
// extendResolution=false
// value < preValue
// Aber Prüfung abgeschaltet => kein Fehler
preValue = 16.99; // zu groß
underTestPost = init_do_flow(analogs, digits, Digital100, false, false, 0);
setAllowNegatives(underTestPost, true);
setPreValue(underTestPost, preValue_extended);
result = process_doFlow(underTestPost);
TEST_ASSERT_EQUAL_STRING("no error", underTestPost->getReadoutError().c_str());
TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
delete underTestPost;
}

View File

@@ -1,27 +1,6 @@
#include <unity.h> #include "test_flow.h"
#include <ClassFlowPostProcessing.h>
#include <ClassFlowCNNGeneral.h>
#include <ClassFlowCNNGeneral.h>
#include <ClassFlowMakeImage.h>
void setUpClassFlowPostprocessing(void);
string process_doFlow(std::vector<float> analog, std::vector<float> digits, t_CNNType digType = Digital100,
bool checkConsistency=false, bool extendedResolution=false, int decimal_shift=0);
ClassFlowCNNGeneral* _analog;
ClassFlowCNNGeneral* _digit;
std::vector<ClassFlow*> FlowControll;
ClassFlowMakeImage* flowmakeimage;
class UnderTestPost : public ClassFlowPostProcessing {
public:
UnderTestPost(std::vector<ClassFlow*>* lfc, ClassFlowCNNGeneral *_analog, ClassFlowCNNGeneral *_digit)
: ClassFlowPostProcessing::ClassFlowPostProcessing(lfc, _analog, _digit) {}
using ClassFlowPostProcessing::InitNUMBERS;
};
UnderTestPost* undertestPost;
/** /**
@@ -32,6 +11,7 @@ UnderTestPost* undertestPost;
* *
*/ */
void test_doFlow() { void test_doFlow() {
/* /*
* *
* digit1 = 1.2 * digit1 = 1.2
@@ -458,96 +438,24 @@ void test_doFlow() {
result = process_doFlow(analogs, digits, Digital100, false, true, 0); result = process_doFlow(analogs, digits, Digital100, false, true, 0);
TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str());
// 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";
// 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());
} }
void setUpClassFlowPostprocessing(t_CNNType digType, t_CNNType anaType)
{
// wird im doFlow verwendet
flowmakeimage = new ClassFlowMakeImage(&FlowControll);
FlowControll.push_back(flowmakeimage);
// Die Modeltypen werden gesetzt, da keine Modelle verwendet werden.
_analog = new ClassFlowCNNGeneral(nullptr, anaType);
_digit = new ClassFlowCNNGeneral(nullptr, digType);
undertestPost = new UnderTestPost(&FlowControll, _analog, _digit);
}
std::string process_doFlow(std::vector<float> analog, std::vector<float> digits, t_CNNType digType,
bool checkConsistency, bool extendedResolution, int decimal_shift) {
// setup the classundertest
setUpClassFlowPostprocessing(digType, Analogue100);
printf("SetupClassFlowPostprocessing completed.\n");
// digits
if (digits.size()>0) {
general* gen_digit = _digit->GetGENERAL("default", true);
gen_digit->ROI.clear();
for (int i = 0; i<digits.size(); i++) {
roi* digitROI = new roi();
string name = "digit_" + std::to_string(i);
digitROI->name = name;
digitROI->result_klasse = (int) digits[i];
digitROI->result_float = digits[i];
gen_digit->ROI.push_back(digitROI);
}
}
// analog
if (analog.size()>0) {
general* gen_analog = _analog->GetGENERAL("default", true);
gen_analog->ROI.clear();
for (int i = 0; i<analog.size(); i++) {
roi* anaROI = new roi();
string name = "ana_" + std::to_string(i);
anaROI->name = name;
anaROI->result_float = analog[i];
gen_analog->ROI.push_back(anaROI);
}
}
printf("Setting up of ROIs completed.\n");
undertestPost->InitNUMBERS();
if (checkConsistency) {
printf("checkConsistency=true\n");
std::vector<NumberPost*>* NUMBERS = undertestPost->GetNumbers();
for (int _n = 0; _n < (*NUMBERS).size(); ++_n) {
printf("Setting checkConsistency on number: %d\n", _n);
(*NUMBERS)[_n]->checkDigitIncreaseConsistency = true;
}
}
if (extendedResolution ) {
std::vector<NumberPost*>* NUMBERS = undertestPost->GetNumbers();
for (int _n = 0; _n < (*NUMBERS).size(); ++_n) {
printf("Setting extendedResolution on number: %d\n", _n);
(*NUMBERS)[_n]->isExtendedResolution = true;
}
}
if (decimal_shift!=0) {
std::vector<NumberPost*>* NUMBERS = undertestPost->GetNumbers();
for (int _n = 0; _n < (*NUMBERS).size(); ++_n) {
printf("Setting decimal shift on number: %d to %d\n", _n, decimal_shift);
(*NUMBERS)[_n]->DecimalShift = decimal_shift;
(*NUMBERS)[_n]->DecimalShiftInitial = decimal_shift;
}
}
string time;
// run test
TEST_ASSERT_TRUE(undertestPost->doFlow(time));
return undertestPost->getReadout(0);
}

View File

@@ -1,5 +1,8 @@
#include <unity.h> #include <unity.h>
#include "components/jomjol-flowcontroll/test_flow.cpp"
#include "components/jomjol-flowcontroll/test_flowpostprocessing.cpp" #include "components/jomjol-flowcontroll/test_flowpostprocessing.cpp"
#include "components/jomjol-flowcontroll/test_flow_pp_negative.cpp"
// SD-Card //////////////////// // SD-Card ////////////////////
#include "nvs_flash.h" #include "nvs_flash.h"
#include "esp_vfs_fat.h" #include "esp_vfs_fat.h"
@@ -101,6 +104,7 @@ extern "C" void app_main()
Init_NVS_SDCard(); Init_NVS_SDCard();
UNITY_BEGIN(); UNITY_BEGIN();
RUN_TEST(testNegative);
RUN_TEST(test_doFlow); RUN_TEST(test_doFlow);
UNITY_END(); UNITY_END();