tbf/TestBenchFramework/BenchControl/Sequences/Statistics.cs

75 lines
1.4 KiB
C#

using System;
namespace TBF.BenchControl.Sequences
{
public class Statistics
{
double first;
double last;
double min;
double max;
double sum;
UInt32 count;
public float First { get { return (float)first; } }
public float Last { get { return (float)last; } }
public float Min { get { return (float)min; } }
public float Max { get { return (float)max; } }
public float Average { get { if (Count > 0) return (float)(sum / (double)count); else return 0; } }
public UInt32 Count { get { return count; } }
public double Sum { get { return sum; } }
public Statistics()
{
Clear();
}
/// <summary>
/// Resets statistics
/// </summary>
public void Clear()
{
sum = 0;
min = float.MaxValue;
max = float.MinValue;
first = 0;
last = 0;
count = 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>
/// Updates statistics
/// </summary>
/// <param name="value">New boxed value</param>
public void Update(TBF.Boxes.DoubleBox box)
{
Update(box.Val);
}
/// <summary>
/// Updates statistics
/// </summary>
/// <param name="value">New boxed value</param>
public void Update(TBF.Boxes.FloatBox box)
{
Update(box.Val);
}
}
}