///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
using System;
namespace TBF.UiBridge
{
public class TestProgressEventArgs : EventArgs
{
public string TestName;
public int Part;
public int Repeats;
public int RepetitionNr;
public Config.Entities.Progress Phase;
public int Progress; /// value in the range 0..100
public float OveralProgress;
#region Static and base constructor part
static int[] estimatedTime; /// Estimated time of each phase to calculate the progress [s]
static int[] cumulativeSumsOfEstimates;
static int currentPhaseStartTime;
static Config.Entities.Progress currentPhase;
static TestProgressEventArgs()
{
int[] estTime = new int[(int)Config.Entities.Progress.Count];
for (int i = 0; i < estTime.Length; i++) estTime[i] = 10;
cumulativeSumsOfEstimates = new int[(int)Config.Entities.Progress.Count];
SetEstimatedTimes(estTime);
currentPhaseStartTime = BenchControl.StateMachine.Time;
currentPhase = Config.Entities.Progress.JustStarted;
}
///
/// Set estimated time of each phase in [s] (see Config.Entities.Progress).
///
/// Array: estimated time of each phase in [s]
public static void SetEstimatedTimes(int[] estTime)
{
if (estTime.Length != (int)Config.Entities.Progress.Count) return;
estimatedTime = estTime;
for (int i = 0; i < estTime.Length; i++)
{
cumulativeSumsOfEstimates[i] = (i > 0) ? cumulativeSumsOfEstimates[i - 1] : 0;
cumulativeSumsOfEstimates[i] += estTime[i];
}
}
///
/// Base constructor which maintains currentPhase, currentPhaseStartTime
/// and calculates 'Progress'.
///
///
private TestProgressEventArgs(Config.Entities.Progress phase)
{
if (phase != currentPhase)
{
currentPhase = phase;
currentPhaseStartTime = BenchControl.StateMachine.Time;
}
Phase = phase;
int phaseNr = (int)phase;
int currentPhaseTime = Math.Min(BenchControl.StateMachine.Time - currentPhaseStartTime, estimatedTime[phaseNr]);
int currentTestTime = currentPhaseTime + ((phaseNr == 0) ? 0 : cumulativeSumsOfEstimates[phaseNr - 1]);
int add10pct = cumulativeSumsOfEstimates[(int)Config.Entities.Progress.Count - 1] / 9;
Progress = 100 * (currentTestTime + add10pct)
/ (cumulativeSumsOfEstimates[(int)Config.Entities.Progress.Count - 1] + add10pct);
}
#endregion
public TestProgressEventArgs(Config.Entities.Test test, int repetitionNr, Config.Entities.Progress progress)
: this(progress)
{
TestName = Results.Utils.GetTestName(test.Name, test.Repeats, repetitionNr);
Part = test.Part;
Repeats = test.Repeats;
RepetitionNr = repetitionNr;
}
public TestProgressEventArgs(Config.Entities.Test test, Config.Entities.Progress progress)
: this(test, 1, progress)
{
}
///
/// Used by iPearl communication dialog
///
public TestProgressEventArgs(string testName, Config.Entities.Progress progress)
: this(progress)
{
TestName = testName;
Part = 0;
Repeats = 1;
RepetitionNr = 1;
}
}
}