ClassFlowPostProcessing.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  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. handleDecimalSeparator(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->FlowRateAct = 0; // m3 / min
  354. _number->PreValue = 0; // letzter Wert, der gut ausgelesen wurde
  355. _number->Value = 0; // letzer ausgelesener Wert, inkl. Korrekturen
  356. _number->ReturnRawValue = ""; // Rohwert (mit N & führenden 0)
  357. _number->ReturnValue = ""; // korrigierter Rückgabewert, ggf. mit Fehlermeldung
  358. _number->ReturnValueNoError = ""; // korrigierter Rückgabewert ohne Fehlermeldung
  359. _number->ErrorMessageText = ""; // Fehlermeldung bei Consistency Check
  360. _number->Nachkomma = _number->AnzahlAnalog;
  361. NUMBERS.push_back(_number);
  362. }
  363. for (int i = 0; i < NUMBERS.size(); ++i)
  364. printf("Number %s, Anz DIG: %d, Anz ANA %d\n", NUMBERS[i]->name.c_str(), NUMBERS[i]->AnzahlDigital, NUMBERS[i]->AnzahlAnalog);
  365. }
  366. string ClassFlowPostProcessing::ShiftDecimal(string in, int _decShift){
  367. if (_decShift == 0){
  368. return in;
  369. }
  370. int _pos_dec_org, _pos_dec_neu;
  371. _pos_dec_org = findDelimiterPos(in, ".");
  372. if (_pos_dec_org == std::string::npos) {
  373. _pos_dec_org = in.length();
  374. }
  375. else
  376. {
  377. in = in.erase(_pos_dec_org, 1);
  378. }
  379. _pos_dec_neu = _pos_dec_org + _decShift;
  380. if (_pos_dec_neu <= 0) { // Komma ist vor der ersten Ziffer
  381. for (int i = 0; i > _pos_dec_neu; --i){
  382. in = in.insert(0, "0");
  383. }
  384. in = "0." + in;
  385. return in;
  386. }
  387. if (_pos_dec_neu > in.length()){ // Komma soll hinter String (123 --> 1230)
  388. for (int i = in.length(); i < _pos_dec_neu; ++i){
  389. in = in.insert(in.length(), "0");
  390. }
  391. return in;
  392. }
  393. string zw;
  394. zw = in.substr(0, _pos_dec_neu);
  395. zw = zw + ".";
  396. zw = zw + in.substr(_pos_dec_neu, in.length() - _pos_dec_neu);
  397. return zw;
  398. }
  399. bool ClassFlowPostProcessing::doFlow(string zwtime)
  400. {
  401. string result = "";
  402. string digit = "";
  403. string analog = "";
  404. string zwvalue;
  405. string zw;
  406. time_t imagetime = 0;
  407. string rohwert;
  408. // ErrorMessageText = "";
  409. imagetime = flowMakeImage->getTimeImageTaken();
  410. if (imagetime == 0)
  411. time(&imagetime);
  412. struct tm* timeinfo;
  413. timeinfo = localtime(&imagetime);
  414. char strftime_buf[64];
  415. strftime(strftime_buf, sizeof(strftime_buf), "%Y-%m-%dT%H:%M:%S", timeinfo);
  416. zwtime = std::string(strftime_buf);
  417. printf("Anzahl NUMBERS: %d\n", NUMBERS.size());
  418. for (int j = 0; j < NUMBERS.size(); ++j)
  419. {
  420. NUMBERS[j]->ReturnRawValue = "";
  421. NUMBERS[j]->ErrorMessageText = "";
  422. if (NUMBERS[j]->digit_roi)
  423. NUMBERS[j]->ReturnRawValue = flowDigit->getReadout(j);
  424. if (NUMBERS[j]->digit_roi && NUMBERS[j]->analog_roi)
  425. NUMBERS[j]->ReturnRawValue = NUMBERS[j]->ReturnRawValue + ".";
  426. if (NUMBERS[j]->analog_roi)
  427. NUMBERS[j]->ReturnRawValue = NUMBERS[j]->ReturnRawValue + flowAnalog->getReadout(j);
  428. NUMBERS[j]->ReturnRawValue = ShiftDecimal(NUMBERS[j]->ReturnRawValue, NUMBERS[j]->DecimalShift);
  429. rohwert = NUMBERS[j]->ReturnRawValue;
  430. if (!PreValueUse || !NUMBERS[j]->PreValueOkay)
  431. {
  432. NUMBERS[j]->ReturnValue = NUMBERS[j]->ReturnRawValue;
  433. NUMBERS[j]->ReturnValueNoError = NUMBERS[j]->ReturnRawValue;
  434. if ((findDelimiterPos(NUMBERS[j]->ReturnValue, "N") == std::string::npos) && (NUMBERS[j]->ReturnValue.length() > 0))
  435. {
  436. while ((NUMBERS[j]->ReturnValue.length() > 1) && (NUMBERS[j]->ReturnValue[0] == '0'))
  437. {
  438. NUMBERS[j]->ReturnValue.erase(0, 1);
  439. }
  440. NUMBERS[j]->Value = std::stof(NUMBERS[j]->ReturnValue);
  441. NUMBERS[j]->ReturnValueNoError = NUMBERS[j]->ReturnValue;
  442. NUMBERS[j]->PreValueOkay = true;
  443. NUMBERS[j]->PreValue = NUMBERS[j]->Value;
  444. NUMBERS[j]->ReturnPreValue = RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma);
  445. NUMBERS[j]->lastvalue = flowMakeImage->getTimeImageTaken();
  446. zwtime = ConvertTimeToString(NUMBERS[j]->lastvalue, PREVALUE_TIME_FORMAT_OUTPUT);
  447. UpdatePreValueINI = true;
  448. SavePreValue();
  449. }
  450. }
  451. else
  452. {
  453. zw = ErsetzteN(NUMBERS[j]->ReturnRawValue, NUMBERS[j]->PreValue);
  454. NUMBERS[j]->Value = std::stof(zw);
  455. if (NUMBERS[j]->checkDigitIncreaseConsistency)
  456. {
  457. NUMBERS[j]->Value = checkDigitConsistency(NUMBERS[j]->Value, NUMBERS[j]->DecimalShift, NUMBERS[j]->analog_roi != NULL, NUMBERS[j]->PreValue);
  458. }
  459. zwvalue = RundeOutput(NUMBERS[j]->Value, NUMBERS[j]->AnzahlAnalog - NUMBERS[j]->DecimalShift);
  460. if ((!NUMBERS[j]->AllowNegativeRates) && (NUMBERS[j]->Value < NUMBERS[j]->PreValue))
  461. {
  462. NUMBERS[j]->ErrorMessageText = NUMBERS[j]->ErrorMessageText + "Neg. Rate - Read: " + zwvalue + " - Raw: " + NUMBERS[j]->ReturnRawValue + " - Pre: " + std::to_string(NUMBERS[j]->Value) + " ";
  463. NUMBERS[j]->Value = NUMBERS[j]->PreValue;
  464. zwvalue = RundeOutput(NUMBERS[j]->Value, NUMBERS[j]->AnzahlAnalog - NUMBERS[j]->DecimalShift);
  465. }
  466. if (NUMBERS[j]->useMaxRateValue && (abs(NUMBERS[j]->Value - NUMBERS[j]->PreValue) > NUMBERS[j]->MaxRateValue))
  467. {
  468. 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) + " ";
  469. NUMBERS[j]->Value = NUMBERS[j]->PreValue;
  470. zwvalue = RundeOutput(NUMBERS[j]->Value, NUMBERS[j]->Nachkomma);
  471. }
  472. NUMBERS[j]->ReturnValueNoError = zwvalue;
  473. NUMBERS[j]->ReturnValue = zwvalue;
  474. if (NUMBERS[j]->ErrorMessage && (NUMBERS[j]->ErrorMessageText.length() > 0))
  475. NUMBERS[j]->ReturnValue = NUMBERS[j]->ReturnValue + "\t" + NUMBERS[j]->ErrorMessageText;
  476. double difference = difftime(imagetime, NUMBERS[j]->lastvalue); // in Sekunden
  477. difference /= 60; // in Minuten
  478. NUMBERS[j]->FlowRateAct = (NUMBERS[j]->Value - NUMBERS[j]->PreValue) / difference;
  479. NUMBERS[j]->lastvalue = imagetime;
  480. if (NUMBERS[j]->ErrorMessageText.length() == 0)
  481. {
  482. NUMBERS[j]->PreValue = NUMBERS[j]->Value;
  483. NUMBERS[j]->ReturnPreValue = RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma);
  484. NUMBERS[j]->ErrorMessageText = "no error";
  485. UpdatePreValueINI = true;
  486. }
  487. }
  488. }
  489. SavePreValue();
  490. return true;
  491. }
  492. string ClassFlowPostProcessing::getReadout(int _number)
  493. {
  494. return NUMBERS[_number]->ReturnValue;
  495. }
  496. string ClassFlowPostProcessing::getReadoutParam(bool _rawValue, bool _noerror, int _number)
  497. {
  498. if (_rawValue)
  499. return NUMBERS[_number]->ReturnRawValue;
  500. if (_noerror)
  501. return NUMBERS[_number]->ReturnValueNoError;
  502. return NUMBERS[_number]->ReturnValue;
  503. }
  504. string ClassFlowPostProcessing::RundeOutput(float _in, int _anzNachkomma){
  505. std::stringstream stream;
  506. int _zw = _in;
  507. // printf("AnzNachkomma: %d\n", _anzNachkomma);
  508. if (_anzNachkomma < 0) {
  509. _anzNachkomma = 0;
  510. }
  511. if (_anzNachkomma > 0)
  512. {
  513. stream << std::fixed << std::setprecision(_anzNachkomma) << _in;
  514. return stream.str();
  515. }
  516. else
  517. {
  518. stream << _zw;
  519. }
  520. return stream.str();
  521. }
  522. string ClassFlowPostProcessing::ErsetzteN(string input, float _prevalue)
  523. {
  524. int posN, posPunkt;
  525. int pot, ziffer;
  526. float zw;
  527. posN = findDelimiterPos(input, "N");
  528. posPunkt = findDelimiterPos(input, ".");
  529. if (posPunkt == std::string::npos){
  530. posPunkt = input.length();
  531. }
  532. while (posN != std::string::npos)
  533. {
  534. if (posN < posPunkt) {
  535. pot = posPunkt - posN - 1;
  536. }
  537. else {
  538. pot = posPunkt - posN;
  539. }
  540. zw =_prevalue / pow(10, pot);
  541. ziffer = ((int) zw) % 10;
  542. input[posN] = ziffer + 48;
  543. posN = findDelimiterPos(input, "N");
  544. }
  545. return input;
  546. }
  547. float ClassFlowPostProcessing::checkDigitConsistency(float input, int _decilamshift, bool _isanalog, float _preValue){
  548. int aktdigit, olddigit;
  549. int aktdigit_before, olddigit_before;
  550. int pot, pot_max;
  551. float zw;
  552. bool no_nulldurchgang = false;
  553. pot = _decilamshift;
  554. if (!_isanalog) // falls es keine analogwerte gibt, kann die letzte nicht bewertet werden
  555. {
  556. pot++;
  557. }
  558. pot_max = ((int) log10(input)) + 1;
  559. while (pot <= pot_max)
  560. {
  561. zw = input / pow(10, pot-1);
  562. aktdigit_before = ((int) zw) % 10;
  563. zw = _preValue / pow(10, pot-1);
  564. olddigit_before = ((int) zw) % 10;
  565. zw = input / pow(10, pot);
  566. aktdigit = ((int) zw) % 10;
  567. zw = _preValue / pow(10, pot);
  568. olddigit = ((int) zw) % 10;
  569. no_nulldurchgang = (olddigit_before <= aktdigit_before);
  570. if (no_nulldurchgang)
  571. {
  572. if (aktdigit != olddigit)
  573. {
  574. input = input + ((float) (olddigit - aktdigit)) * pow(10, pot); // Neue Digit wird durch alte Digit ersetzt;
  575. }
  576. }
  577. else
  578. {
  579. if (aktdigit == olddigit) // trotz Nulldurchgang wurde Stelle nicht hochgezählt --> addiere 1
  580. {
  581. input = input + ((float) (1)) * pow(10, pot); // addiere 1 an der Stelle
  582. }
  583. }
  584. pot++;
  585. }
  586. return input;
  587. }
  588. string ClassFlowPostProcessing::getReadoutRate(int _number)
  589. {
  590. return std::to_string(NUMBERS[_number]->FlowRateAct);
  591. }
  592. string ClassFlowPostProcessing::getReadoutTimeStamp(int _number)
  593. {
  594. return NUMBERS[_number]->timeStamp;
  595. }
  596. string ClassFlowPostProcessing::getReadoutError(int _number)
  597. {
  598. return NUMBERS[_number]->ErrorMessageText;
  599. }