ClassFlowPostProcessing.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. #include "ClassFlowPostProcessing.h"
  2. #include "Helper.h"
  3. #include "ClassFlowMakeImage.h"
  4. #include "ClassLogFile.h"
  5. #include <iomanip>
  6. #include <sstream>
  7. #include <time.h>
  8. #include "time_sntp.h"
  9. #define PREVALUE_TIME_FORMAT_OUTPUT "%Y-%m-%dT%H:%M:%S"
  10. #define PREVALUE_TIME_FORMAT_INPUT "%d-%d-%dT%d:%d:%d"
  11. string ClassFlowPostProcessing::GetPreValue(std::string _number)
  12. {
  13. std::string result;
  14. int index = -1;
  15. if (_number == "")
  16. _number = "default";
  17. for (int i = 0; i < NUMBERS.size(); ++i)
  18. if (NUMBERS[i]->name == _number)
  19. index = i;
  20. // result = RundeOutput(NUMBERS[index]->PreValue, -NUMBERS[index]->DecimalShift);
  21. result = RundeOutput(NUMBERS[index]->PreValue, NUMBERS[index]->Nachkomma);
  22. // if (NUMBERS[index]->digit_roi && NUMBERS[index]->analog_roi)
  23. // result = RundeOutput(NUMBERS[index]->PreValue, NUMBERS[index]->AnzahlAnalog - NUMBERS[index]->DecimalShift);
  24. return result;
  25. }
  26. void ClassFlowPostProcessing::SetPreValue(float zw, string _numbers)
  27. {
  28. for (int j = 0; j < NUMBERS.size(); ++j)
  29. {
  30. if (NUMBERS[j]->name == _numbers)
  31. NUMBERS[j]->PreValue = zw;
  32. }
  33. UpdatePreValueINI = true;
  34. SavePreValue();
  35. }
  36. bool ClassFlowPostProcessing::LoadPreValue(void)
  37. {
  38. std::vector<string> zerlegt;
  39. FILE* pFile;
  40. char zw[1024];
  41. string zwtime, zwvalue, name;
  42. bool _done = false;
  43. UpdatePreValueINI = false; // Konvertierung ins neue Format
  44. pFile = fopen(FilePreValue.c_str(), "r");
  45. if (pFile == NULL)
  46. return false;
  47. fgets(zw, 1024, pFile);
  48. printf("Read Zeile Prevalue.ini: %s", zw);
  49. zwtime = trim(std::string(zw));
  50. if (zwtime.length() == 0)
  51. return false;
  52. zerlegt = HelperZerlegeZeile(zwtime, "\t");
  53. if (zerlegt.size() > 1) // neues Format
  54. {
  55. while ((zerlegt.size() > 1) && !_done)
  56. {
  57. name = trim(zerlegt[0]);
  58. zwtime = trim(zerlegt[1]);
  59. zwvalue = trim(zerlegt[2]);
  60. for (int j = 0; j < NUMBERS.size(); ++j)
  61. {
  62. if (NUMBERS[j]->name == name)
  63. {
  64. NUMBERS[j]->PreValue = stof(zwvalue.c_str());
  65. NUMBERS[j]->ReturnPreValue = RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma);
  66. time_t tStart;
  67. int yy, month, dd, hh, mm, ss;
  68. struct tm whenStart;
  69. sscanf(zwtime.c_str(), PREVALUE_TIME_FORMAT_INPUT, &yy, &month, &dd, &hh, &mm, &ss);
  70. whenStart.tm_year = yy - 1900;
  71. whenStart.tm_mon = month - 1;
  72. whenStart.tm_mday = dd;
  73. whenStart.tm_hour = hh;
  74. whenStart.tm_min = mm;
  75. whenStart.tm_sec = ss;
  76. whenStart.tm_isdst = -1;
  77. NUMBERS[j]->lastvalue = mktime(&whenStart);
  78. time(&tStart);
  79. localtime(&tStart);
  80. double difference = difftime(tStart, NUMBERS[j]->lastvalue);
  81. difference /= 60;
  82. if (difference > PreValueAgeStartup)
  83. {
  84. NUMBERS[j]->PreValueOkay = false;
  85. }
  86. else
  87. {
  88. NUMBERS[j]->PreValueOkay = true;
  89. NUMBERS[j]->Value = NUMBERS[j]->PreValue;
  90. NUMBERS[j]->ReturnValue = to_string(NUMBERS[j]->Value);
  91. NUMBERS[j]->ReturnValueNoError = NUMBERS[j]->ReturnValue;
  92. if (NUMBERS[j]->digit_roi || NUMBERS[j]->analog_roi)
  93. {
  94. NUMBERS[j]->ReturnValue = RundeOutput(NUMBERS[j]->Value, NUMBERS[j]->AnzahlAnalog - NUMBERS[j]->DecimalShift);
  95. NUMBERS[j]->ReturnValueNoError = NUMBERS[j]->ReturnValue;
  96. }
  97. }
  98. }
  99. }
  100. if (!fgets(zw, 1024, pFile))
  101. _done = true;
  102. else
  103. {
  104. printf("Read Zeile Prevalue.ini: %s", zw);
  105. zerlegt = HelperZerlegeZeile(trim(std::string(zw)), "\t");
  106. if (zerlegt.size() > 1)
  107. {
  108. name = trim(zerlegt[0]);
  109. zwtime = trim(zerlegt[1]);
  110. zwvalue = trim(zerlegt[2]);
  111. }
  112. }
  113. }
  114. fclose(pFile);
  115. }
  116. else // altes Format
  117. {
  118. fgets(zw, 1024, pFile);
  119. fclose(pFile);
  120. printf("%s", zw);
  121. zwvalue = trim(std::string(zw));
  122. NUMBERS[0]->PreValue = stof(zwvalue.c_str());
  123. time_t tStart;
  124. int yy, month, dd, hh, mm, ss;
  125. struct tm whenStart;
  126. sscanf(zwtime.c_str(), PREVALUE_TIME_FORMAT_INPUT, &yy, &month, &dd, &hh, &mm, &ss);
  127. whenStart.tm_year = yy - 1900;
  128. whenStart.tm_mon = month - 1;
  129. whenStart.tm_mday = dd;
  130. whenStart.tm_hour = hh;
  131. whenStart.tm_min = mm;
  132. whenStart.tm_sec = ss;
  133. whenStart.tm_isdst = -1;
  134. printf("TIME: %d, %d, %d, %d, %d, %d\n", whenStart.tm_year, whenStart.tm_mon, whenStart.tm_wday, whenStart.tm_hour, whenStart.tm_min, whenStart.tm_sec);
  135. NUMBERS[0]->lastvalue = mktime(&whenStart);
  136. time(&tStart);
  137. localtime(&tStart);
  138. double difference = difftime(tStart, NUMBERS[0]->lastvalue);
  139. difference /= 60;
  140. if (difference > PreValueAgeStartup)
  141. return false;
  142. NUMBERS[0]->Value = NUMBERS[0]->PreValue;
  143. NUMBERS[0]->ReturnValue = to_string(NUMBERS[0]->Value);
  144. NUMBERS[0]->ReturnValueNoError = NUMBERS[0]->ReturnValue;
  145. if (NUMBERS[0]->digit_roi || NUMBERS[0]->analog_roi)
  146. {
  147. NUMBERS[0]->ReturnValue = RundeOutput(NUMBERS[0]->Value, NUMBERS[0]->AnzahlAnalog - NUMBERS[0]->DecimalShift);
  148. NUMBERS[0]->ReturnValueNoError = NUMBERS[0]->ReturnValue;
  149. }
  150. UpdatePreValueINI = true; // Konvertierung ins neue Format
  151. SavePreValue();
  152. }
  153. return true;
  154. }
  155. void ClassFlowPostProcessing::SavePreValue()
  156. {
  157. FILE* pFile;
  158. string _zw;
  159. if (!UpdatePreValueINI) // PreValues unverändert --> File muss nicht neu geschrieben werden
  160. return;
  161. pFile = fopen(FilePreValue.c_str(), "w");
  162. for (int j = 0; j < NUMBERS.size(); ++j)
  163. {
  164. char buffer[80];
  165. struct tm* timeinfo = localtime(&NUMBERS[j]->lastvalue);
  166. strftime(buffer, 80, PREVALUE_TIME_FORMAT_OUTPUT, timeinfo);
  167. NUMBERS[j]->timeStamp = std::string(buffer);
  168. _zw = NUMBERS[j]->name + "\t" + NUMBERS[j]->timeStamp + "\t" + to_string(NUMBERS[j]->PreValue) + "\n";
  169. printf("Write PreValue Zeile: %s\n", _zw.c_str());
  170. fputs(_zw.c_str(), pFile);
  171. }
  172. UpdatePreValueINI = false;
  173. fclose(pFile);
  174. }
  175. ClassFlowPostProcessing::ClassFlowPostProcessing(std::vector<ClassFlow*>* lfc)
  176. {
  177. // FlowRateAct = 0;
  178. PreValueUse = false;
  179. PreValueAgeStartup = 30;
  180. ErrorMessage = false;
  181. ListFlowControll = NULL;
  182. // PreValueOkay = false;
  183. // DecimalShift = 0;
  184. // ErrorMessageText = "";
  185. // timeStamp = "";
  186. FilePreValue = FormatFileName("/sdcard/config/prevalue.ini");
  187. ListFlowControll = lfc;
  188. flowMakeImage = NULL;
  189. UpdatePreValueINI = false;
  190. for (int i = 0; i < ListFlowControll->size(); ++i)
  191. {
  192. if (((*ListFlowControll)[i])->name().compare("ClassFlowMakeImage") == 0)
  193. {
  194. flowMakeImage = (ClassFlowMakeImage*) (*ListFlowControll)[i];
  195. }
  196. }
  197. }
  198. void ClassFlowPostProcessing::handleDecimalSeparator(string _decsep, string _value)
  199. {
  200. string _digit, _decpos;
  201. int _pospunkt = _decsep.find_first_of(".");
  202. // printf("Name: %s, Pospunkt: %d\n", _decsep.c_str(), _pospunkt);
  203. if (_pospunkt > -1)
  204. _digit = _decsep.substr(0, _pospunkt);
  205. else
  206. _digit = "default";
  207. for (int j = 0; j < NUMBERS.size(); ++j)
  208. {
  209. if (_digit == "default") // erstmal auf default setzen (falls sonst nichts gesetzt)
  210. NUMBERS[j]->DecimalShift = stoi(_value);
  211. if (NUMBERS[j]->name == _digit)
  212. NUMBERS[j]->DecimalShift = stoi(_value);
  213. NUMBERS[j]->Nachkomma = NUMBERS[j]->AnzahlAnalog - NUMBERS[j]->DecimalShift;
  214. }
  215. }
  216. void ClassFlowPostProcessing::handleMaxRateValue(string _decsep, string _value)
  217. {
  218. string _digit, _decpos;
  219. int _pospunkt = _decsep.find_first_of(".");
  220. // printf("Name: %s, Pospunkt: %d\n", _decsep.c_str(), _pospunkt);
  221. if (_pospunkt > -1)
  222. _digit = _decsep.substr(0, _pospunkt);
  223. else
  224. _digit = "default";
  225. for (int j = 0; j < NUMBERS.size(); ++j)
  226. {
  227. if (_digit == "default") // erstmal auf default setzen (falls sonst nichts gesetzt)
  228. {
  229. NUMBERS[j]->useMaxRateValue = true;
  230. NUMBERS[j]->MaxRateValue = stof(_value);
  231. }
  232. if (NUMBERS[j]->name == _digit)
  233. {
  234. NUMBERS[j]->useMaxRateValue = true;
  235. NUMBERS[j]->MaxRateValue = stof(_value);
  236. }
  237. }
  238. }
  239. bool ClassFlowPostProcessing::ReadParameter(FILE* pfile, string& aktparamgraph)
  240. {
  241. std::vector<string> zerlegt;
  242. int _n;
  243. aktparamgraph = trim(aktparamgraph);
  244. if (aktparamgraph.size() == 0)
  245. if (!this->GetNextParagraph(pfile, aktparamgraph))
  246. return false;
  247. if (aktparamgraph.compare("[PostProcessing]") != 0) // Paragraph passt nich zu MakeImage
  248. return false;
  249. InitNUMBERS();
  250. while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
  251. {
  252. zerlegt = this->ZerlegeZeile(aktparamgraph);
  253. std::string _param = GetParameterName(zerlegt[0]);
  254. if ((toUpper(_param) == "DECIMALSHIFT") && (zerlegt.size() > 1))
  255. {
  256. handleDecimalSeparator(zerlegt[0], zerlegt[1]);
  257. }
  258. if ((toUpper(_param) == "MAXRATEVALUE") && (zerlegt.size() > 1))
  259. {
  260. handleMaxRateValue(zerlegt[0], zerlegt[1]);
  261. }
  262. if ((toUpper(_param) == "PREVALUEUSE") && (zerlegt.size() > 1))
  263. {
  264. if (toUpper(zerlegt[1]) == "TRUE")
  265. {
  266. PreValueUse = true;
  267. }
  268. }
  269. if ((toUpper(_param) == "CHECKDIGITINCREASECONSISTENCY") && (zerlegt.size() > 1))
  270. {
  271. if (toUpper(zerlegt[1]) == "TRUE")
  272. for (_n = 0; _n < NUMBERS.size(); ++_n)
  273. NUMBERS[_n]->checkDigitIncreaseConsistency = true;
  274. }
  275. if ((toUpper(_param) == "ALLOWNEGATIVERATES") && (zerlegt.size() > 1))
  276. {
  277. if (toUpper(zerlegt[1]) == "TRUE")
  278. for (_n = 0; _n < NUMBERS.size(); ++_n)
  279. NUMBERS[_n]->AllowNegativeRates = true;
  280. }
  281. if ((toUpper(_param) == "ERRORMESSAGE") && (zerlegt.size() > 1))
  282. {
  283. if (toUpper(zerlegt[1]) == "TRUE")
  284. ErrorMessage = true;
  285. }
  286. if ((toUpper(_param) == "PREVALUEAGESTARTUP") && (zerlegt.size() > 1))
  287. {
  288. PreValueAgeStartup = std::stoi(zerlegt[1]);
  289. }
  290. }
  291. if (PreValueUse) {
  292. LoadPreValue();
  293. }
  294. return true;
  295. }
  296. void ClassFlowPostProcessing::InitNUMBERS()
  297. {
  298. // ClassFlowDigit* _cdigit = NULL;
  299. // ClassFlowAnalog* _canalog = NULL;
  300. int anzDIGIT = 0;
  301. int anzANALOG = 0;
  302. std::vector<std::string> name_numbers;
  303. flowAnalog = NULL;
  304. flowDigit = NULL;
  305. for (int i = 0; i < ListFlowControll->size(); ++i)
  306. {
  307. if (((*ListFlowControll)[i])->name().compare("ClassFlowDigit") == 0)
  308. {
  309. flowDigit = (ClassFlowDigit*) (*ListFlowControll)[i];
  310. anzDIGIT = flowDigit->getAnzahlDIGIT();
  311. }
  312. if (((*ListFlowControll)[i])->name().compare("ClassFlowAnalog") == 0)
  313. {
  314. flowAnalog = (ClassFlowAnalog*)(*ListFlowControll)[i];
  315. anzANALOG = flowAnalog->getAnzahlANALOG();
  316. }
  317. }
  318. if (flowDigit)
  319. flowDigit->UpdateNameNumbers(&name_numbers);
  320. if (flowAnalog)
  321. flowAnalog->UpdateNameNumbers(&name_numbers);
  322. printf("Anzahl NUMBERS: %d - DIGITS: %d, ANALOG: %d\n", name_numbers.size(), anzDIGIT, anzANALOG);
  323. for (int _num = 0; _num < name_numbers.size(); ++_num)
  324. {
  325. NumberPost *_number = new NumberPost;
  326. _number->name = name_numbers[_num];
  327. _number->digit_roi = NULL;
  328. if (flowDigit)
  329. _number->digit_roi = flowDigit->FindDIGIT(name_numbers[_num]);
  330. if (_number->digit_roi)
  331. _number->AnzahlDigital = _number->digit_roi->ROI.size();
  332. else
  333. _number->AnzahlDigital = 0;
  334. _number->analog_roi = NULL;
  335. if (flowAnalog)
  336. _number->analog_roi = flowAnalog->FindANALOG(name_numbers[_num]);
  337. if (_number->analog_roi)
  338. _number->AnzahlAnalog = _number->analog_roi->ROI.size();
  339. else
  340. _number->AnzahlAnalog = 0;
  341. _number->ReturnRawValue = ""; // Rohwert (mit N & führenden 0)
  342. _number->ReturnValue = ""; // korrigierter Rückgabewert, ggf. mit Fehlermeldung
  343. _number->ReturnValueNoError = ""; // korrigierter Rückgabewert ohne Fehlermeldung
  344. _number->ErrorMessageText = ""; // Fehlermeldung bei Consistency Check
  345. _number->ReturnPreValue = "";
  346. _number->PreValueOkay = false;
  347. _number->AllowNegativeRates = false;
  348. _number->MaxRateValue = 0.1;
  349. _number->useMaxRateValue = false;
  350. _number->checkDigitIncreaseConsistency = false;
  351. _number->PreValueOkay = false;
  352. _number->useMaxRateValue = false;
  353. _number->DecimalShift = 0;
  354. _number->FlowRateAct = 0; // m3 / min
  355. _number->PreValue = 0; // letzter Wert, der gut ausgelesen wurde
  356. _number->Value = 0; // letzer ausgelesener Wert, inkl. Korrekturen
  357. _number->ReturnRawValue = ""; // Rohwert (mit N & führenden 0)
  358. _number->ReturnValue = ""; // korrigierter Rückgabewert, ggf. mit Fehlermeldung
  359. _number->ReturnValueNoError = ""; // korrigierter Rückgabewert ohne Fehlermeldung
  360. _number->ErrorMessageText = ""; // Fehlermeldung bei Consistency Check
  361. _number->Nachkomma = _number->AnzahlAnalog;
  362. NUMBERS.push_back(_number);
  363. }
  364. for (int i = 0; i < NUMBERS.size(); ++i)
  365. printf("Number %s, Anz DIG: %d, Anz ANA %d\n", NUMBERS[i]->name.c_str(), NUMBERS[i]->AnzahlDigital, NUMBERS[i]->AnzahlAnalog);
  366. }
  367. string ClassFlowPostProcessing::ShiftDecimal(string in, int _decShift){
  368. if (_decShift == 0){
  369. return in;
  370. }
  371. int _pos_dec_org, _pos_dec_neu;
  372. _pos_dec_org = findDelimiterPos(in, ".");
  373. if (_pos_dec_org == std::string::npos) {
  374. _pos_dec_org = in.length();
  375. }
  376. else
  377. {
  378. in = in.erase(_pos_dec_org, 1);
  379. }
  380. _pos_dec_neu = _pos_dec_org + _decShift;
  381. if (_pos_dec_neu <= 0) { // Komma ist vor der ersten Ziffer
  382. for (int i = 0; i > _pos_dec_neu; --i){
  383. in = in.insert(0, "0");
  384. }
  385. in = "0." + in;
  386. return in;
  387. }
  388. if (_pos_dec_neu > in.length()){ // Komma soll hinter String (123 --> 1230)
  389. for (int i = in.length(); i < _pos_dec_neu; ++i){
  390. in = in.insert(in.length(), "0");
  391. }
  392. return in;
  393. }
  394. string zw;
  395. zw = in.substr(0, _pos_dec_neu);
  396. zw = zw + ".";
  397. zw = zw + in.substr(_pos_dec_neu, in.length() - _pos_dec_neu);
  398. return zw;
  399. }
  400. bool ClassFlowPostProcessing::doFlow(string zwtime)
  401. {
  402. string result = "";
  403. string digit = "";
  404. string analog = "";
  405. string zwvalue;
  406. string zw;
  407. time_t imagetime = 0;
  408. string rohwert;
  409. // ErrorMessageText = "";
  410. imagetime = flowMakeImage->getTimeImageTaken();
  411. if (imagetime == 0)
  412. time(&imagetime);
  413. struct tm* timeinfo;
  414. timeinfo = localtime(&imagetime);
  415. char strftime_buf[64];
  416. strftime(strftime_buf, sizeof(strftime_buf), "%Y-%m-%dT%H:%M:%S", timeinfo);
  417. zwtime = std::string(strftime_buf);
  418. printf("Anzahl NUMBERS: %d\n", NUMBERS.size());
  419. for (int j = 0; j < NUMBERS.size(); ++j)
  420. {
  421. NUMBERS[j]->ReturnRawValue = "";
  422. NUMBERS[j]->ErrorMessageText = "";
  423. if (NUMBERS[j]->digit_roi)
  424. NUMBERS[j]->ReturnRawValue = flowDigit->getReadout(j);
  425. if (NUMBERS[j]->digit_roi && NUMBERS[j]->analog_roi)
  426. NUMBERS[j]->ReturnRawValue = NUMBERS[j]->ReturnRawValue + ".";
  427. if (NUMBERS[j]->analog_roi)
  428. NUMBERS[j]->ReturnRawValue = NUMBERS[j]->ReturnRawValue + flowAnalog->getReadout(j);
  429. NUMBERS[j]->ReturnRawValue = ShiftDecimal(NUMBERS[j]->ReturnRawValue, NUMBERS[j]->DecimalShift);
  430. rohwert = NUMBERS[j]->ReturnRawValue;
  431. if (!PreValueUse || !NUMBERS[j]->PreValueOkay)
  432. {
  433. NUMBERS[j]->ReturnValue = NUMBERS[j]->ReturnRawValue;
  434. NUMBERS[j]->ReturnValueNoError = NUMBERS[j]->ReturnRawValue;
  435. if ((findDelimiterPos(NUMBERS[j]->ReturnValue, "N") == std::string::npos) && (NUMBERS[j]->ReturnValue.length() > 0))
  436. {
  437. while ((NUMBERS[j]->ReturnValue.length() > 1) && (NUMBERS[j]->ReturnValue[0] == '0'))
  438. {
  439. NUMBERS[j]->ReturnValue.erase(0, 1);
  440. }
  441. NUMBERS[j]->Value = std::stof(NUMBERS[j]->ReturnValue);
  442. NUMBERS[j]->ReturnValueNoError = NUMBERS[j]->ReturnValue;
  443. NUMBERS[j]->PreValueOkay = true;
  444. NUMBERS[j]->PreValue = NUMBERS[j]->Value;
  445. NUMBERS[j]->ReturnPreValue = RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma);
  446. NUMBERS[j]->lastvalue = flowMakeImage->getTimeImageTaken();
  447. zwtime = ConvertTimeToString(NUMBERS[j]->lastvalue, PREVALUE_TIME_FORMAT_OUTPUT);
  448. UpdatePreValueINI = true;
  449. SavePreValue();
  450. }
  451. }
  452. else
  453. {
  454. zw = ErsetzteN(NUMBERS[j]->ReturnRawValue, NUMBERS[j]->PreValue);
  455. NUMBERS[j]->Value = std::stof(zw);
  456. if (NUMBERS[j]->checkDigitIncreaseConsistency)
  457. {
  458. NUMBERS[j]->Value = checkDigitConsistency(NUMBERS[j]->Value, NUMBERS[j]->DecimalShift, NUMBERS[j]->analog_roi != NULL, NUMBERS[j]->PreValue);
  459. }
  460. zwvalue = RundeOutput(NUMBERS[j]->Value, NUMBERS[j]->AnzahlAnalog - NUMBERS[j]->DecimalShift);
  461. if ((!NUMBERS[j]->AllowNegativeRates) && (NUMBERS[j]->Value < NUMBERS[j]->PreValue))
  462. {
  463. NUMBERS[j]->ErrorMessageText = NUMBERS[j]->ErrorMessageText + "Neg. Rate - Read: " + zwvalue + " - Raw: " + NUMBERS[j]->ReturnRawValue + " - Pre: " + std::to_string(NUMBERS[j]->Value) + " ";
  464. NUMBERS[j]->Value = NUMBERS[j]->PreValue;
  465. zwvalue = RundeOutput(NUMBERS[j]->Value, NUMBERS[j]->AnzahlAnalog - NUMBERS[j]->DecimalShift);
  466. }
  467. if (NUMBERS[j]->useMaxRateValue && (abs(NUMBERS[j]->Value - NUMBERS[j]->PreValue) > NUMBERS[j]->MaxRateValue))
  468. {
  469. NUMBERS[j]->ErrorMessageText = NUMBERS[j]->ErrorMessageText + "Rate too high - Read: " + RundeOutput(NUMBERS[j]->Value, NUMBERS[j]->Nachkomma) + " - Pre: " + RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma) + " ";
  470. NUMBERS[j]->Value = NUMBERS[j]->PreValue;
  471. zwvalue = RundeOutput(NUMBERS[j]->Value, NUMBERS[j]->Nachkomma);
  472. }
  473. NUMBERS[j]->ReturnValueNoError = zwvalue;
  474. NUMBERS[j]->ReturnValue = zwvalue;
  475. if (NUMBERS[j]->ErrorMessage && (NUMBERS[j]->ErrorMessageText.length() > 0))
  476. NUMBERS[j]->ReturnValue = NUMBERS[j]->ReturnValue + "\t" + NUMBERS[j]->ErrorMessageText;
  477. double difference = difftime(imagetime, NUMBERS[j]->lastvalue); // in Sekunden
  478. difference /= 60; // in Minuten
  479. NUMBERS[j]->FlowRateAct = (NUMBERS[j]->Value - NUMBERS[j]->PreValue) / difference;
  480. NUMBERS[j]->lastvalue = imagetime;
  481. if (NUMBERS[j]->ErrorMessageText.length() == 0)
  482. {
  483. NUMBERS[j]->PreValue = NUMBERS[j]->Value;
  484. NUMBERS[j]->ReturnPreValue = RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma);
  485. NUMBERS[j]->ErrorMessageText = "no error";
  486. UpdatePreValueINI = true;
  487. }
  488. }
  489. }
  490. SavePreValue();
  491. return true;
  492. }
  493. string ClassFlowPostProcessing::getReadout(int _number)
  494. {
  495. return NUMBERS[_number]->ReturnValue;
  496. }
  497. string ClassFlowPostProcessing::getReadoutParam(bool _rawValue, bool _noerror, int _number)
  498. {
  499. if (_rawValue)
  500. return NUMBERS[_number]->ReturnRawValue;
  501. if (_noerror)
  502. return NUMBERS[_number]->ReturnValueNoError;
  503. return NUMBERS[_number]->ReturnValue;
  504. }
  505. string ClassFlowPostProcessing::RundeOutput(float _in, int _anzNachkomma){
  506. std::stringstream stream;
  507. int _zw = _in;
  508. // printf("AnzNachkomma: %d\n", _anzNachkomma);
  509. if (_anzNachkomma < 0) {
  510. _anzNachkomma = 0;
  511. }
  512. if (_anzNachkomma > 0)
  513. {
  514. stream << std::fixed << std::setprecision(_anzNachkomma) << _in;
  515. return stream.str();
  516. }
  517. else
  518. {
  519. stream << _zw;
  520. }
  521. return stream.str();
  522. }
  523. string ClassFlowPostProcessing::ErsetzteN(string input, float _prevalue)
  524. {
  525. int posN, posPunkt;
  526. int pot, ziffer;
  527. float zw;
  528. posN = findDelimiterPos(input, "N");
  529. posPunkt = findDelimiterPos(input, ".");
  530. if (posPunkt == std::string::npos){
  531. posPunkt = input.length();
  532. }
  533. while (posN != std::string::npos)
  534. {
  535. if (posN < posPunkt) {
  536. pot = posPunkt - posN - 1;
  537. }
  538. else {
  539. pot = posPunkt - posN;
  540. }
  541. zw =_prevalue / pow(10, pot);
  542. ziffer = ((int) zw) % 10;
  543. input[posN] = ziffer + 48;
  544. posN = findDelimiterPos(input, "N");
  545. }
  546. return input;
  547. }
  548. float ClassFlowPostProcessing::checkDigitConsistency(float input, int _decilamshift, bool _isanalog, float _preValue){
  549. int aktdigit, olddigit;
  550. int aktdigit_before, olddigit_before;
  551. int pot, pot_max;
  552. float zw;
  553. bool no_nulldurchgang = false;
  554. pot = _decilamshift;
  555. if (!_isanalog) // falls es keine analogwerte gibt, kann die letzte nicht bewertet werden
  556. {
  557. pot++;
  558. }
  559. pot_max = ((int) log10(input)) + 1;
  560. while (pot <= pot_max)
  561. {
  562. zw = input / pow(10, pot-1);
  563. aktdigit_before = ((int) zw) % 10;
  564. zw = _preValue / pow(10, pot-1);
  565. olddigit_before = ((int) zw) % 10;
  566. zw = input / pow(10, pot);
  567. aktdigit = ((int) zw) % 10;
  568. zw = _preValue / pow(10, pot);
  569. olddigit = ((int) zw) % 10;
  570. no_nulldurchgang = (olddigit_before <= aktdigit_before);
  571. if (no_nulldurchgang)
  572. {
  573. if (aktdigit != olddigit)
  574. {
  575. input = input + ((float) (olddigit - aktdigit)) * pow(10, pot); // Neue Digit wird durch alte Digit ersetzt;
  576. }
  577. }
  578. else
  579. {
  580. if (aktdigit == olddigit) // trotz Nulldurchgang wurde Stelle nicht hochgezählt --> addiere 1
  581. {
  582. input = input + ((float) (1)) * pow(10, pot); // addiere 1 an der Stelle
  583. }
  584. }
  585. pot++;
  586. }
  587. return input;
  588. }
  589. string ClassFlowPostProcessing::getReadoutRate(int _number)
  590. {
  591. return std::to_string(NUMBERS[_number]->FlowRateAct);
  592. }
  593. string ClassFlowPostProcessing::getReadoutTimeStamp(int _number)
  594. {
  595. return NUMBERS[_number]->timeStamp;
  596. }
  597. string ClassFlowPostProcessing::getReadoutError(int _number)
  598. {
  599. return NUMBERS[_number]->ErrorMessageText;
  600. }