mirror of
https://github.com/jomjol/AI-on-the-edge-device.git
synced 2025-12-08 20:46:52 +03:00
Implementation of DecimalShift
This commit is contained in:
@@ -29,7 +29,12 @@ A 3d-printable housing can be found here: https://www.thingiverse.com/thing:4571
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
##### Rolling - (2020-09-12)
|
##### Rolling - (2020-09-13)
|
||||||
|
|
||||||
|
* Implementation of decimal shift (New Parameter "DecimalShift = 1" in [PostProcessing])
|
||||||
|
DecimalShift = 1 --> Result: 123.456 --> 1234.56
|
||||||
|
DecimalShift = -1 --> Result: 12.3456
|
||||||
|
The shift is done at the very first step of merging digital and analog, so all following number already will work on the shifted number.
|
||||||
|
|
||||||
* based on v2.0.0 (2020-09-12)
|
* based on v2.0.0 (2020-09-12)
|
||||||
|
|
||||||
|
|||||||
@@ -135,6 +135,7 @@ ClassFlowPostProcessing::ClassFlowPostProcessing()
|
|||||||
PreValueOkay = false;
|
PreValueOkay = false;
|
||||||
useMaxRateValue = false;
|
useMaxRateValue = false;
|
||||||
checkDigitIncreaseConsistency = false;
|
checkDigitIncreaseConsistency = false;
|
||||||
|
DecimalShift = 0;
|
||||||
FilePreValue = FormatFileName("/sdcard/config/prevalue.ini");
|
FilePreValue = FormatFileName("/sdcard/config/prevalue.ini");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,10 +150,12 @@ ClassFlowPostProcessing::ClassFlowPostProcessing(std::vector<ClassFlow*>* lfc)
|
|||||||
PreValueOkay = false;
|
PreValueOkay = false;
|
||||||
useMaxRateValue = false;
|
useMaxRateValue = false;
|
||||||
checkDigitIncreaseConsistency = false;
|
checkDigitIncreaseConsistency = false;
|
||||||
|
DecimalShift = 0;
|
||||||
FilePreValue = FormatFileName("/sdcard/config/prevalue.ini");
|
FilePreValue = FormatFileName("/sdcard/config/prevalue.ini");
|
||||||
ListFlowControll = lfc;
|
ListFlowControll = lfc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool ClassFlowPostProcessing::ReadParameter(FILE* pfile, string& aktparamgraph)
|
bool ClassFlowPostProcessing::ReadParameter(FILE* pfile, string& aktparamgraph)
|
||||||
{
|
{
|
||||||
std::vector<string> zerlegt;
|
std::vector<string> zerlegt;
|
||||||
@@ -170,34 +173,39 @@ bool ClassFlowPostProcessing::ReadParameter(FILE* pfile, string& aktparamgraph)
|
|||||||
while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
|
while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
|
||||||
{
|
{
|
||||||
zerlegt = this->ZerlegeZeile(aktparamgraph);
|
zerlegt = this->ZerlegeZeile(aktparamgraph);
|
||||||
if ((zerlegt[0] == "PreValueUse") && (zerlegt.size() > 1))
|
if ((toUpper(zerlegt[0]) == "DECIMALSHIFT") && (zerlegt.size() > 1))
|
||||||
{
|
{
|
||||||
if ((zerlegt[1] == "True") || (zerlegt[1] == "true"))
|
DecimalShift = stoi(zerlegt[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((toUpper(zerlegt[0]) == "PREVALUEUSE") && (zerlegt.size() > 1))
|
||||||
|
{
|
||||||
|
if (toUpper(zerlegt[1]) == "TRUE")
|
||||||
{
|
{
|
||||||
PreValueUse = true;
|
PreValueUse = true;
|
||||||
PreValueOkay = LoadPreValue();
|
PreValueOkay = LoadPreValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((zerlegt[0] == "CheckDigitIncreaseConsistency") && (zerlegt.size() > 1))
|
if ((toUpper(zerlegt[0]) == "CHECKDIGITINCREASECONSISTENCY") && (zerlegt.size() > 1))
|
||||||
{
|
{
|
||||||
if (toUpper(zerlegt[1]) == "TRUE")
|
if (toUpper(zerlegt[1]) == "TRUE")
|
||||||
checkDigitIncreaseConsistency = true;
|
checkDigitIncreaseConsistency = true;
|
||||||
}
|
}
|
||||||
if ((zerlegt[0] == "AllowNegativeRates") && (zerlegt.size() > 1))
|
if ((toUpper(zerlegt[0]) == "ALLOWNEGATIVERATES") && (zerlegt.size() > 1))
|
||||||
{
|
{
|
||||||
if (toUpper(zerlegt[1]) == "TRUE")
|
if (toUpper(zerlegt[1]) == "TRUE")
|
||||||
AllowNegativeRates = true;
|
AllowNegativeRates = true;
|
||||||
}
|
}
|
||||||
if ((zerlegt[0] == "ErrorMessage") && (zerlegt.size() > 1))
|
if ((toUpper(zerlegt[0]) == "ERRORMESSAGE") && (zerlegt.size() > 1))
|
||||||
{
|
{
|
||||||
if (toUpper(zerlegt[1]) == "TRUE")
|
if (toUpper(zerlegt[1]) == "TRUE")
|
||||||
ErrorMessage = true;
|
ErrorMessage = true;
|
||||||
}
|
}
|
||||||
if ((zerlegt[0] == "PreValueAgeStartup") && (zerlegt.size() > 1))
|
if ((toUpper(zerlegt[0]) == "PREVALUEAGESTARTUP") && (zerlegt.size() > 1))
|
||||||
{
|
{
|
||||||
PreValueAgeStartup = std::stoi(zerlegt[1]);
|
PreValueAgeStartup = std::stoi(zerlegt[1]);
|
||||||
}
|
}
|
||||||
if ((zerlegt[0] == "MaxRateValue") && (zerlegt.size() > 1))
|
if ((toUpper(zerlegt[0]) == "MAXRATEVALUE") && (zerlegt.size() > 1))
|
||||||
{
|
{
|
||||||
useMaxRateValue = true;
|
useMaxRateValue = true;
|
||||||
MaxRateValue = std::stof(zerlegt[1]);
|
MaxRateValue = std::stof(zerlegt[1]);
|
||||||
@@ -206,6 +214,48 @@ bool ClassFlowPostProcessing::ReadParameter(FILE* pfile, string& aktparamgraph)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string ClassFlowPostProcessing::ShiftDecimal(string in, int _decShift){
|
||||||
|
|
||||||
|
if (_decShift == 0){
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
|
||||||
|
int _pos_dec_org, _pos_dec_neu;
|
||||||
|
|
||||||
|
_pos_dec_org = findDelimiterPos(in, ".");
|
||||||
|
if (_pos_dec_org == std::string::npos) {
|
||||||
|
_pos_dec_org = in.length();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
in = in.erase(_pos_dec_org, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
_pos_dec_neu = _pos_dec_org + _decShift;
|
||||||
|
|
||||||
|
if (_pos_dec_neu <= 0) { // Komma ist vor der ersten Ziffer
|
||||||
|
for (int i = 0; i > _pos_dec_neu; --i){
|
||||||
|
in = in.insert(0, "0");
|
||||||
|
}
|
||||||
|
in = "0." + in;
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_pos_dec_neu > in.length()){ // Komma soll hinter String (123 --> 1230)
|
||||||
|
for (int i = in.length(); i < _pos_dec_neu; ++i){
|
||||||
|
in = in.insert(in.length(), "0");
|
||||||
|
}
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
|
||||||
|
string zw;
|
||||||
|
zw = in.substr(0, _pos_dec_neu);
|
||||||
|
zw = zw + ".";
|
||||||
|
zw = zw + in.substr(_pos_dec_neu, in.length() - _pos_dec_neu);
|
||||||
|
|
||||||
|
return zw;
|
||||||
|
}
|
||||||
|
|
||||||
bool ClassFlowPostProcessing::doFlow(string zwtime)
|
bool ClassFlowPostProcessing::doFlow(string zwtime)
|
||||||
{
|
{
|
||||||
string result = "";
|
string result = "";
|
||||||
@@ -260,6 +310,8 @@ bool ClassFlowPostProcessing::doFlow(string zwtime)
|
|||||||
if (isanalog)
|
if (isanalog)
|
||||||
ReturnRawValue = ReturnRawValue + analog;
|
ReturnRawValue = ReturnRawValue + analog;
|
||||||
|
|
||||||
|
ReturnRawValue = ShiftDecimal(ReturnRawValue, DecimalShift);
|
||||||
|
|
||||||
if (!PreValueUse || !PreValueOkay)
|
if (!PreValueUse || !PreValueOkay)
|
||||||
{
|
{
|
||||||
ReturnValue = ReturnRawValue;
|
ReturnValue = ReturnRawValue;
|
||||||
@@ -374,7 +426,7 @@ string ClassFlowPostProcessing::ErsetzteN(string input, int lastvalueanalog = -1
|
|||||||
if (checkDigitIncreaseConsistency && lastvalueanalog > -1)
|
if (checkDigitIncreaseConsistency && lastvalueanalog > -1)
|
||||||
{
|
{
|
||||||
int zifferIST;
|
int zifferIST;
|
||||||
int substrakt = 0;
|
// int substrakt = 0;
|
||||||
bool lastcorrected = false;
|
bool lastcorrected = false;
|
||||||
for (int i = input.length() - 1; i >= 0; --i)
|
for (int i = input.length() - 1; i >= 0; --i)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ protected:
|
|||||||
bool ErrorMessage;
|
bool ErrorMessage;
|
||||||
bool PreValueOkay;
|
bool PreValueOkay;
|
||||||
bool checkDigitIncreaseConsistency;
|
bool checkDigitIncreaseConsistency;
|
||||||
|
int DecimalShift;
|
||||||
|
|
||||||
string FilePreValue;
|
string FilePreValue;
|
||||||
float PreValue; // letzter Wert, der gut ausgelesen wurde
|
float PreValue; // letzter Wert, der gut ausgelesen wurde
|
||||||
@@ -25,6 +26,7 @@ protected:
|
|||||||
string ReturnValueNoError; // korrigierter Rückgabewert ohne Fehlermeldung
|
string ReturnValueNoError; // korrigierter Rückgabewert ohne Fehlermeldung
|
||||||
|
|
||||||
bool LoadPreValue(void);
|
bool LoadPreValue(void);
|
||||||
|
string ShiftDecimal(string in, int _decShift);
|
||||||
|
|
||||||
string ErsetzteN(string, int lastvalueanalog);
|
string ErsetzteN(string, int lastvalueanalog);
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -31,6 +31,7 @@ analog3, 294, 369, 92, 92
|
|||||||
analog4, 168, 326, 92, 92
|
analog4, 168, 326, 92, 92
|
||||||
|
|
||||||
[PostProcessing]
|
[PostProcessing]
|
||||||
|
DecimalShift = 0
|
||||||
PreValueUse = True
|
PreValueUse = True
|
||||||
PreValueAgeStartup = 30
|
PreValueAgeStartup = 30
|
||||||
AllowNegativeRates = False
|
AllowNegativeRates = False
|
||||||
|
|||||||
Reference in New Issue
Block a user