63 lines
2.4 KiB
C#
63 lines
2.4 KiB
C#
///
|
|
/// Copyright (c) 2021 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Common
|
|
{
|
|
public class Utils
|
|
{
|
|
public static string GetTestName(string name, int repeats, int repetitionNr)
|
|
{
|
|
if (name == null) return null;
|
|
if (repeats == 1) return name;
|
|
return string.Format("{0} ({1}/{2})", name, repetitionNr, repeats);
|
|
}
|
|
|
|
public static void CalculateFeatureVector(Iperl.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 == Iperl.OptoTelegramFlags.OK ||
|
|
optoData[ix].Flags == Iperl.OptoTelegramFlags.OK_TestStart ||
|
|
optoData[ix].Flags == Iperl.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);
|
|
}
|
|
}
|
|
}
|
|
}
|