Statistics support filtering, skipping first samples, etc., ver. 2.15.642
This commit is contained in:
@@ -79,13 +79,13 @@ namespace TBF.BenchControl.Sequences
|
|||||||
public static Statistics AmbTempStat = new Statistics();
|
public static Statistics AmbTempStat = new Statistics();
|
||||||
public static Statistics AmbPressStat = new Statistics();
|
public static Statistics AmbPressStat = new Statistics();
|
||||||
public static Statistics AmbHumiStat = new Statistics();
|
public static Statistics AmbHumiStat = new Statistics();
|
||||||
public static Statistics TempUpStat = new Statistics();
|
public static Statistics TempUpStat = new Statistics(5, 5, true);
|
||||||
public static Statistics TempDownStat = new Statistics();
|
public static Statistics TempDownStat = new Statistics(5, 5, true);
|
||||||
public static Statistics TempDivStat = new Statistics();
|
public static Statistics TempDivStat = new Statistics(5, 5, true);
|
||||||
public static Statistics PressUpStat = new Statistics();
|
public static Statistics PressUpStat = new Statistics(5, 5, true);
|
||||||
public static Statistics PressDownStat = new Statistics();
|
public static Statistics PressDownStat = new Statistics(5, 5, true);
|
||||||
public static Statistics PressDeltaStat = new Statistics();
|
public static Statistics PressDeltaStat = new Statistics(5, 5, true);
|
||||||
public static Statistics RefFlowStat = new Statistics();
|
public static Statistics RefFlowStat = new Statistics(5, 5, true);
|
||||||
|
|
||||||
public static Statistics TempRefHiStat = new Statistics();
|
public static Statistics TempRefHiStat = new Statistics();
|
||||||
public static Statistics TempRefLoStat = new Statistics();
|
public static Statistics TempRefLoStat = new Statistics();
|
||||||
|
|||||||
@@ -4,26 +4,48 @@ namespace TBF.BenchControl.Sequences
|
|||||||
{
|
{
|
||||||
public class Statistics
|
public class Statistics
|
||||||
{
|
{
|
||||||
|
public readonly int SkippedSamplesCount; /// 0 = do not skip any samples
|
||||||
|
public readonly int FilterSize; /// 0 = no filter
|
||||||
|
public readonly bool MedianFilter; /// true - median filter instead of average
|
||||||
|
|
||||||
|
|
||||||
|
double[] fifo;
|
||||||
|
double[] sorted;
|
||||||
double first;
|
double first;
|
||||||
double last;
|
double last;
|
||||||
double min;
|
double min;
|
||||||
double max;
|
double max;
|
||||||
double sum;
|
double sum;
|
||||||
UInt32 count;
|
UInt32 totalCount; /// Number of samples passed to Update()
|
||||||
|
UInt32 count; /// Number of processed and filtered samples
|
||||||
|
UInt32 fifoCount; /// Number of samples inserted into FIFO
|
||||||
|
|
||||||
public double First { get { return first; } }
|
public double First { get { return first; } }
|
||||||
public double Last { get { return last; } }
|
public double Last { get { return last; } }
|
||||||
public double Min { get { return min; } }
|
public double Min { get { return min; } }
|
||||||
public double Max { get { return max; } }
|
public double Max { get { return max; } }
|
||||||
public double Average { get { if (Count > 0) return (sum / (double)count); else return 0; } }
|
public double Average { get { if (count > 0) return (sum / (double)count); else return 0; } }
|
||||||
public UInt32 Count { get { return count; } }
|
public UInt32 Count { get { return count; } }
|
||||||
|
|
||||||
public double Sum { get { return sum; } }
|
public double Sum { get { return sum; } }
|
||||||
|
|
||||||
|
|
||||||
public Statistics()
|
public Statistics(int skippedSamplesCount, int filterSize, bool medianFilter)
|
||||||
{
|
{
|
||||||
|
this.SkippedSamplesCount = skippedSamplesCount;
|
||||||
|
this.FilterSize = filterSize;
|
||||||
|
this.MedianFilter = medianFilter;
|
||||||
|
|
||||||
Clear();
|
Clear();
|
||||||
|
if (FilterSize > 0)
|
||||||
|
{
|
||||||
|
fifo = new double[FilterSize];
|
||||||
|
sorted = new double[FilterSize];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Statistics() : this(0, 0, false)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -36,22 +58,11 @@ namespace TBF.BenchControl.Sequences
|
|||||||
max = double.MinValue;
|
max = double.MinValue;
|
||||||
first = 0;
|
first = 0;
|
||||||
last = 0;
|
last = 0;
|
||||||
|
totalCount = 0;
|
||||||
count = 0;
|
count = 0;
|
||||||
|
fifoCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Updates statistics
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="value">New value</param>
|
|
||||||
public void Update(double value)
|
|
||||||
{
|
|
||||||
if (count == 0) first = value;
|
|
||||||
last = value;
|
|
||||||
sum += value;
|
|
||||||
if (value < min) min = value;
|
|
||||||
if (value > max) max = value;
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Updates statistics
|
/// Updates statistics
|
||||||
@@ -70,5 +81,81 @@ namespace TBF.BenchControl.Sequences
|
|||||||
{
|
{
|
||||||
Update(box.Val);
|
Update(box.Val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// All samples are passed to this function
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value">New value</param>
|
||||||
|
public void Update(double value)
|
||||||
|
{
|
||||||
|
if (totalCount >= SkippedSamplesCount) Process(value);
|
||||||
|
totalCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Only samples after first 'SkippedSamplesCount' samples are passed to this function.
|
||||||
|
/// Any filtering is done inside this function.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value">New value</param>
|
||||||
|
void Process(double value)
|
||||||
|
{
|
||||||
|
double filteredValue;
|
||||||
|
if (ApplyFilter(value, out filteredValue))
|
||||||
|
{
|
||||||
|
if (count == 0) first = value;
|
||||||
|
last = value;
|
||||||
|
sum += value;
|
||||||
|
if (value < min) min = value;
|
||||||
|
if (value > max) max = value;
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Inserts values to FIFO and calculates filetered value when FIFO is full.
|
||||||
|
/// Returns true when FIFO is full and calculated values are valid.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value">Input value</param>
|
||||||
|
/// <param name="filteredValue">Output filtered value</param>
|
||||||
|
/// <returns>true when 'fileterdValue' is valid</returns>
|
||||||
|
bool ApplyFilter(double value, out double filteredValue)
|
||||||
|
{
|
||||||
|
filteredValue = value;
|
||||||
|
|
||||||
|
if (FilterSize == 0) return true; /// no filter -> input value is passed to output
|
||||||
|
|
||||||
|
|
||||||
|
/// Shift values in FIFO buffer, put the new value into fifo[0]
|
||||||
|
double sum = 0;
|
||||||
|
for (int i = FilterSize - 1; i > 0; i--)
|
||||||
|
{
|
||||||
|
sorted[i] = fifo[i] = fifo[i - 1];
|
||||||
|
sum += fifo[i];
|
||||||
|
}
|
||||||
|
sorted[0] = fifo[0] = value;
|
||||||
|
sum += value;
|
||||||
|
fifoCount++;
|
||||||
|
|
||||||
|
|
||||||
|
if (fifoCount < FilterSize)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (MedianFilter)
|
||||||
|
{
|
||||||
|
Array.Sort(sorted);
|
||||||
|
filteredValue = sorted[FilterSize / 2];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
filteredValue = sum / FilterSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
|
|||||||
// Build Number
|
// Build Number
|
||||||
// Revision
|
// Revision
|
||||||
//
|
//
|
||||||
[assembly: AssemblyVersion("2.15.641.1")]
|
[assembly: AssemblyVersion("2.15.642.1")]
|
||||||
[assembly: AssemblyFileVersion("2.15.641.1")]
|
[assembly: AssemblyFileVersion("2.15.642.1")]
|
||||||
|
|||||||
Reference in New Issue
Block a user