IPERL : Results.Entities.MeterTestRslt.X1 .. X9, ErrorBC added, X1 = flow st. dev., Q_WZ (and VolumeMeter) calculation bug fix, etc.

This commit is contained in:
Milan Hanajik
2021-07-20 09:46:23 +02:00
parent aa04ea620b
commit 3b81f1a143
9 changed files with 177 additions and 26 deletions
@@ -30,6 +30,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
public const int StartOptoDataCount = MaxOptoDataCount / 2;
public const int EndOptoDataCount = MaxOptoDataCount - StartOptoDataCount;
public const int StartEndFilterSamplesCount2 = 20; /// StartEndFilterSamplesCount = 2 * StartEndFilterSamplesCount2 + 1
public const int FeatureVectorSize = 9;
readonly IperlHeadCfg iperlHeadCfg;
@@ -80,6 +81,9 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
string extraDataPath;
public string ExtraDataPath { get { return extraDataPath; } }
float[] x;
public float[] X { get { return x; } }
/// <summary>
/// Passed to OptoTelegramRaw.UpdateFromString(...)
@@ -354,6 +358,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
: base(cfg)
{
iperlHeadCfg = cfg as IperlHeadCfg;
x = new float[FeatureVectorSize];
}
public override void Initialize()
@@ -414,6 +419,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
Q2CorrRL = 0;
Q2CorrLR = 0;
/// Clear the data buffer
optoDataCount = 0;
currentFlowDir = InitFlowDir;
@@ -514,6 +520,9 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
timestampSec = 0;
timestampSec0 = 0;
/// Clear the feature vector
for (int i = 0; i < FeatureVectorSize; i++) x[i] = 0;
ReadPulses();
}
@@ -620,6 +629,8 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
optoData[endIx].Flags = OptoTelegramFlags.OK_TestEnd;
}
log.DebugFormat("Flow filtering start: {0:HH:mm:ss.fff}", DateTime.Now);
StopParsingOptoSerialPort();
if (optoDataCount <= MaxOptoDataCount)
{
@@ -631,8 +642,16 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
OptoTelegramRaw.FIRFilterFlow(optoData, (optoDataCount - EndOptoDataCount), optoDataCount - 1);
}
log.DebugFormat("Flow filtering end, feature vector calculation start: {0:HH:mm:ss.fff}", DateTime.Now);
CalculateFeatureVector(optoData, optoDataCount, startIx, endIx, ref x);
log.DebugFormat("Feature vector calculation end, save opto-file start: {0:HH:mm:ss.fff}", DateTime.Now);
extraDataPath = SaveOptoData();
log.DebugFormat("Save opto-file end: {0:HH:mm:ss.fff}", DateTime.Now);
if (TestStartTelegramIx == 0 || optoDataCount < 100)
{
ResultCode |= (int)Results.Entities.ResultCode.MissingOptoData;
@@ -643,6 +662,47 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
}
}
void CalculateFeatureVector(OptoTelegramRaw[] optoData, int optoDataCount, int startIx, int endIx, ref float[] x)
{
if (startIx < 0 || endIx >= optoDataCount || startIx >= endIx) return;
int n = 0;
Int64 sumFlow = 0;
Int64 sumFlow2 = 0;
Int64 sumEmf = 0;
Int64 sumEmf2 = 0;
Int64 sumMagF = 0;
Int64 sumMagF2 = 0;
Int64 sumImp = 0;
Int64 sumImp2 = 0;
for (int ix = startIx; ix <= endIx; ix++)
{
if (optoData[ix].Flags == OptoTelegramFlags.OK ||
optoData[ix].Flags == OptoTelegramFlags.OK_TestStart ||
optoData[ix].Flags == OptoTelegramFlags.OK_TestEnd)
{
n++;
sumFlow += optoData[ix].FlowRaw;
sumFlow2 += ((int)optoData[ix].FlowRaw * (int)optoData[ix].FlowRaw);
sumEmf += (int)optoData[ix].EmfRaw;
sumEmf2 += ((Int64)optoData[ix].EmfRaw * (Int64)optoData[ix].EmfRaw);
sumMagF += optoData[ix].MagneticFieldRaw;
sumMagF2 += ((int)optoData[ix].MagneticFieldRaw * (int)optoData[ix].MagneticFieldRaw);
sumImp += optoData[ix].Impedance;
sumImp2 += ((int)optoData[ix].Impedance * (int)optoData[ix].Impedance);
}
}
if (n >= 2)
{
if (x.Length > 0) x[0] = ((float)sumFlow2 - (float)sumFlow * (float)sumFlow / n) / (n - 1);
if (x.Length > 1) x[1] = ((float)sumEmf2 - (float)sumEmf * (float)sumEmf / n) / (n - 1);
if (x.Length > 2) x[2] = ((float)sumMagF2 - (float)sumMagF * (float)sumMagF / n) / (n - 1);
if (x.Length > 3) x[3] = ((float)sumImp2 - (float)sumImp * (float)sumImp / n) / (n - 1);
}
}
/// <summary>
/// Save opto data to a file.
/// </summary>