test_flow_postrocess_helper.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. #include "test_flow_postrocess_helper.h"
  2. #include "esp_log.h"
  3. static const char *TAG = "POSTPROC TEST";
  4. UnderTestPost* setUpClassFlowPostprocessing(t_CNNType digType, t_CNNType anaType)
  5. {
  6. ClassFlowCNNGeneral* _analog;
  7. ClassFlowCNNGeneral* _digit;
  8. std::vector<ClassFlow*> FlowControll;
  9. ClassFlowTakeImage* flowtakeimage;
  10. // wird im doFlow verwendet
  11. flowtakeimage = new ClassFlowTakeImage(&FlowControll);
  12. FlowControll.push_back(flowtakeimage);
  13. // Die Modeltypen werden gesetzt, da keine Modelle verwendet werden.
  14. _analog = new ClassFlowCNNGeneral(nullptr, anaType);
  15. _digit = new ClassFlowCNNGeneral(nullptr, digType);
  16. return new UnderTestPost(&FlowControll, _analog, _digit);
  17. }
  18. std::string process_doFlow(UnderTestPost* _underTestPost) {
  19. string time;
  20. // run test
  21. TEST_ASSERT_TRUE(_underTestPost->doFlow(time));
  22. return _underTestPost->getReadout(0);
  23. }
  24. /**
  25. * @brief setup flow like it runs after recognition.
  26. *
  27. * @param analog the analog recognitions as array begins with the highest ROI
  28. * @param digits the digital regocnitions as array begins with the highest ROI
  29. * @param digType type of the model defaults do Digital100
  30. * @param checkConsistency for Digital type only. Not relvant for newer models
  31. * @param extendedResolution the lowest ROI will directly used (9.7 => 9.7) if false 9.7 => 9
  32. * @param decimal_shift the decimal point offset. -3 corresponds to x.yyy
  33. * @return std::string the value result
  34. */
  35. std::string process_doFlow(std::vector<float> analog, std::vector<float> digits, t_CNNType digType,
  36. bool checkConsistency, bool extendedResolution, int decimal_shift) {
  37. // setup the classundertest
  38. UnderTestPost* _undertestPost = init_do_flow(analog, digits, digType, checkConsistency, extendedResolution, decimal_shift);
  39. ESP_LOGD(TAG, "SetupClassFlowPostprocessing completed.");
  40. string time;
  41. // run test
  42. TEST_ASSERT_TRUE(_undertestPost->doFlow(time));
  43. std::string result = _undertestPost->getReadout(0);
  44. delete _undertestPost;
  45. return result;
  46. }
  47. UnderTestPost* init_do_flow(std::vector<float> analog, std::vector<float> digits, t_CNNType digType,
  48. bool checkConsistency, bool extendedResolution, int decimal_shift) {
  49. UnderTestPost* _undertestPost = setUpClassFlowPostprocessing(digType, Analogue100);
  50. // digits
  51. if (digits.size()>0) {
  52. general* gen_digit = _undertestPost->flowDigit->GetGENERAL("default", true);
  53. gen_digit->ROI.clear();
  54. for (int i = 0; i<digits.size(); i++) {
  55. roi* digitROI = new roi();
  56. string name = "digit_" + std::to_string(i);
  57. digitROI->name = name;
  58. digitROI->result_klasse = (int) digits[i];
  59. digitROI->result_float = digits[i];
  60. gen_digit->ROI.push_back(digitROI);
  61. }
  62. }
  63. // analog
  64. if (analog.size()>0) {
  65. general* gen_analog = _undertestPost->flowAnalog->GetGENERAL("default", true);
  66. gen_analog->ROI.clear();
  67. for (int i = 0; i<analog.size(); i++) {
  68. roi* anaROI = new roi();
  69. string name = "ana_1" + std::to_string(i);
  70. anaROI->name = name;
  71. anaROI->result_float = analog[i];
  72. gen_analog->ROI.push_back(anaROI);
  73. }
  74. } else {
  75. _undertestPost->flowAnalog = NULL;
  76. }
  77. ESP_LOGD(TAG, "Setting up of ROIs completed.");
  78. _undertestPost->InitNUMBERS();
  79. setConsitencyCheck(_undertestPost, checkConsistency);
  80. setExtendedResolution(_undertestPost, extendedResolution);
  81. setDecimalShift(_undertestPost, decimal_shift);
  82. return _undertestPost;
  83. }
  84. void setPreValue(UnderTestPost* _underTestPost, double _preValue) {
  85. if (_preValue>0) {
  86. ESP_LOGD(TAG, "preValue=%f", _preValue);
  87. std::vector<NumberPost*>* NUMBERS = _underTestPost->GetNumbers();
  88. for (int _n = 0; _n < (*NUMBERS).size(); ++_n) {
  89. (*NUMBERS)[_n]->PreValue = _preValue;
  90. }
  91. }
  92. }
  93. void setAllowNegatives(UnderTestPost* _underTestPost, bool _allowNegatives) {
  94. ESP_LOGD(TAG, "checkConsistency=true");
  95. std::vector<NumberPost*>* NUMBERS = _underTestPost->GetNumbers();
  96. for (int _n = 0; _n < (*NUMBERS).size(); ++_n) {
  97. (*NUMBERS)[_n]->AllowNegativeRates = _allowNegatives;
  98. }
  99. }
  100. void setConsitencyCheck(UnderTestPost* _underTestPost, bool _checkConsistency) {
  101. if (_checkConsistency) {
  102. ESP_LOGD(TAG, "checkConsistency=true");
  103. std::vector<NumberPost*>* NUMBERS = _underTestPost->GetNumbers();
  104. for (int _n = 0; _n < (*NUMBERS).size(); ++_n) {
  105. (*NUMBERS)[_n]->checkDigitIncreaseConsistency = true;
  106. }
  107. }
  108. }
  109. void setExtendedResolution(UnderTestPost* _underTestPost, bool _extendedResolution) {
  110. if (_extendedResolution ) {
  111. std::vector<NumberPost*>* NUMBERS = _underTestPost->GetNumbers();
  112. for (int _n = 0; _n < (*NUMBERS).size(); ++_n) {
  113. (*NUMBERS)[_n]->isExtendedResolution = true;
  114. }
  115. }
  116. }
  117. void setDecimalShift(UnderTestPost* _underTestPost, int _decimal_shift) {
  118. if (_decimal_shift!=0) {
  119. std::vector<NumberPost*>* NUMBERS = _underTestPost->GetNumbers();
  120. for (int _n = 0; _n < (*NUMBERS).size(); ++_n) {
  121. ESP_LOGD(TAG, "Setting decimal shift on number: %d to %d", _n, _decimal_shift);
  122. (*NUMBERS)[_n]->DecimalShift = _decimal_shift;
  123. (*NUMBERS)[_n]->DecimalShiftInitial = _decimal_shift;
  124. }
  125. }
  126. }
  127. void setAnalogdigitTransistionStart(UnderTestPost* _underTestPost, float _analogdigitTransistionStart) {
  128. if (_analogdigitTransistionStart!=0) {
  129. std::vector<NumberPost*>* NUMBERS = _underTestPost->GetNumbers();
  130. for (int _n = 0; _n < (*NUMBERS).size(); ++_n) {
  131. ESP_LOGD(TAG, "Setting decimal shift on number: %d to %f", _n, _analogdigitTransistionStart);
  132. (*NUMBERS)[_n]->AnalogDigitalTransitionStart = _analogdigitTransistionStart;
  133. }
  134. }
  135. }