diff --git a/TBF/BenchControl/GenericDevices/IPlotter.cs b/TBF/BenchControl/GenericDevices/IPlotter.cs new file mode 100644 index 000000000..53352dcb3 --- /dev/null +++ b/TBF/BenchControl/GenericDevices/IPlotter.cs @@ -0,0 +1,16 @@ +/// +/// Copyright (c) 2018 Sensus Slovensko a.s. +/// +using System; + +namespace TBF.BenchControl.GenericDevices +{ + public interface IPlotter + { + int StartGraph(int batchNr, string testName, int repetition); + + void UpdateGraph(int graphId, float x, float y); + + void StopGraph(int graphId); + } +} diff --git a/TBF/BenchControl/Sequences/Plotter.cs b/TBF/BenchControl/Sequences/Plotter.cs new file mode 100644 index 000000000..ab81df4e3 --- /dev/null +++ b/TBF/BenchControl/Sequences/Plotter.cs @@ -0,0 +1,77 @@ +/// +/// Copyright (c) 2018 Sensus Slovensko a.s. +/// +using System; +using System.IO; +using System.Collections.Generic; +using log4net; + +namespace TBF.BenchControl.Sequences +{ + public class Plotter : BenchControl.GenericDevices.IPlotter + { + static readonly ILog log = LogManager.GetLogger(typeof(Plotter)); + + static readonly Dictionary writers = new Dictionary(); + static int nextGraphId = 1; + + + + readonly string caption; + /// + public Plotter(string caption) + { + this.caption = caption; + } + + + + public int StartGraph(int batchNr, string testName, int repetition) + { + try + { + int graphId = nextGraphId++; + string directory = Path.Combine(TBF.Program.GraphsDir, batchNr.ToString(), testName, repetition.ToString()); + Directory.CreateDirectory(directory); + writers.Add(graphId, new BinaryWriter(File.Open(Path.Combine(directory, caption), FileMode.Create))); + log.InfoFormat("Graph file #{0} successfully created (batch={1} test={2} repet={3} caption={4})", + graphId, batchNr, testName, repetition, caption); + return graphId; + } + catch (Exception exc) + { + log.ErrorFormat("Failed to create a graph file (batch={0} test={1} repet={2} caption={3}): {4}", + batchNr, testName, repetition, caption, exc.Message); + return 0; + } + } + + public void UpdateGraph(int graphId, float x, float y) + { + try + { + BinaryWriter writer = writers[graphId]; + writer.Write(x); + writer.Write(y); + } + catch (Exception exc) + { + log.ErrorFormat("Failed to update graph file #{0}: {1}", graphId, exc.Message); + } + } + + public void StopGraph(int graphId) + { + try + { + BinaryWriter writer = writers[graphId]; + writer.Close(); + writers.Remove(graphId); + } + catch (Exception exc) + { + log.ErrorFormat("Failed to close graph file #{0}: {1}", graphId, exc.Message); + } + } + } +} diff --git a/TBF/BenchControl/Sequences/ProcessData.cs b/TBF/BenchControl/Sequences/ProcessData.cs index bcdf4d067..1342a33a5 100644 --- a/TBF/BenchControl/Sequences/ProcessData.cs +++ b/TBF/BenchControl/Sequences/ProcessData.cs @@ -77,49 +77,49 @@ namespace TBF.BenchControl.Sequences /// /// Statistics of 'continuous' variables (temperature, pressure, flow, etc.) /// - public static Statistics AmbTempStat = new Statistics(); - public static Statistics AmbPressStat = new Statistics(); - public static Statistics AmbHumiStat = new Statistics(); + public static Statistics AmbTempStat = new Statistics(new Plotter("Ambient temperature")); + public static Statistics AmbPressStat = new Statistics(new Plotter("Ambient pressure")); + public static Statistics AmbHumiStat = new Statistics(new Plotter("Ambient humidity")); - public static Statistics TempUpStat = new Statistics(0, 5, true); - public static Statistics TempDownStat = new Statistics(0, 5, true); - public static Statistics TempDiffStat = new Statistics(0, 5, true); - public static Statistics TempDivStat = new Statistics(0, 5, true); - public static Statistics PressUpStat = new Statistics(5, 5, true); - public static Statistics PressDownStat = new Statistics(5, 5, true); - public static Statistics PressDeltaStat = new Statistics(5, 5, true); - public static Statistics RefFlowStat = new Statistics(5, 5, true); + public static Statistics TempUpStat = new Statistics(0, 5, true, new Plotter("Temperature up")); + public static Statistics TempDownStat = new Statistics(0, 5, true, new Plotter("Temperature down")); + public static Statistics TempDiffStat = new Statistics(0, 5, true); + public static Statistics TempDivStat = new Statistics(0, 5, true, new Plotter("Temperature div")); + public static Statistics PressUpStat = new Statistics(5, 5, true, new Plotter("Pressure up")); + public static Statistics PressDownStat = new Statistics(5, 5, true, new Plotter("Pressure down")); + public static Statistics PressDeltaStat = new Statistics(5, 5, true); + public static Statistics RefFlowStat = new Statistics(5, 5, true, new Plotter("Flow")); - public static Statistics TempRefHiStat = new Statistics(); - public static Statistics TempRefLoStat = new Statistics(); - public static Statistics Energy = new Statistics(); + public static Statistics TempRefHiStat = new Statistics(); + public static Statistics TempRefLoStat = new Statistics(); + public static Statistics Energy = new Statistics(); public static Statistics VolumeForEnergy = new Statistics(); public static int lastEnergyUpdateTime; public static int machineTimeStart; public static int lastMachineTime; - protected static void ClearAllStatistics(int machineTime) + protected static void StartNewStatistics(int machineTime, int batchNr, string testName, int repetition) { lastMachineTime = machineTimeStart = machineTime; - AmbTempStat.Clear(); - AmbPressStat.Clear(); - AmbHumiStat.Clear(); + AmbTempStat.Start(batchNr, testName, repetition); + AmbPressStat.Start(batchNr, testName, repetition); + AmbHumiStat.Start(batchNr, testName, repetition); - TempUpStat.Clear(); - TempDownStat.Clear(); - TempDiffStat.Clear(); - TempDivStat.Clear(); - PressUpStat.Clear(); - PressDownStat.Clear(); - PressDeltaStat.Clear(); - RefFlowStat.Clear(); + TempUpStat.Start(batchNr, testName, repetition); + TempDownStat.Start(batchNr, testName, repetition); + TempDiffStat.Start(batchNr, testName, repetition); + TempDivStat.Start(batchNr, testName, repetition); + PressUpStat.Start(batchNr, testName, repetition); + PressDownStat.Start(batchNr, testName, repetition); + PressDeltaStat.Start(batchNr, testName, repetition); + RefFlowStat.Start(batchNr, testName, repetition); - TempRefHiStat.Clear(); - TempRefLoStat.Clear(); - Energy.Clear(); - VolumeForEnergy.Clear(); + TempRefHiStat.Start(batchNr, testName, repetition); + TempRefLoStat.Start(batchNr, testName, repetition); + Energy.Start(batchNr, testName, repetition); + VolumeForEnergy.Start(batchNr, testName, repetition); lastEnergyUpdateTime = 0; } @@ -148,5 +148,26 @@ namespace TBF.BenchControl.Sequences lastMachineTime = machineTime; } + + protected static void StopRecordingStatistics() + { + AmbTempStat.Stop(); + AmbPressStat.Stop(); + AmbHumiStat.Stop(); + + TempUpStat.Stop(); + TempDownStat.Stop(); + TempDiffStat.Stop(); + TempDivStat.Stop(); + PressUpStat.Stop(); + PressDownStat.Stop(); + PressDeltaStat.Stop(); + RefFlowStat.Stop(); + + TempRefHiStat.Stop(); + TempRefLoStat.Stop(); + Energy.Stop(); + VolumeForEnergy.Stop(); + } } } diff --git a/TBF/BenchControl/Sequences/SequenceBase.cs b/TBF/BenchControl/Sequences/SequenceBase.cs index 6f59a88fd..dce7b5f62 100644 --- a/TBF/BenchControl/Sequences/SequenceBase.cs +++ b/TBF/BenchControl/Sequences/SequenceBase.cs @@ -1130,8 +1130,11 @@ namespace TBF.BenchControl.Sequences tstRslt.TempDownMax = 20.0f; tstRslt.TempDivMax = 20.0f; - tstRslt.FlowMean = 0; /// TODO - tstRslt.FlowMax = 0; /// TODO + tstRslt.FlowMean = (float)RefFlowStat.Average; + tstRslt.FlowStart = (float)RefFlowStat.First; + tstRslt.FlowEnd = (float)RefFlowStat.Last; + tstRslt.FlowMin = (float)RefFlowStat.Min; + tstRslt.FlowMax = (float)RefFlowStat.Max; for (int i = 0; i < BatchRslts.WMPositionsCount; i++) { @@ -1235,9 +1238,11 @@ namespace TBF.BenchControl.Sequences tstRslt.TempDownMax = 20.0f; tstRslt.TempDivMax = 20.0f; - tstRslt.FlowMean = 0; /// TODO - tstRslt.FlowMax = 0; /// TODO - + tstRslt.FlowMean = (float)RefFlowStat.Average; + tstRslt.FlowStart = (float)RefFlowStat.First; + tstRslt.FlowEnd = (float)RefFlowStat.Last; + tstRslt.FlowMin = (float)RefFlowStat.Min; + tstRslt.FlowMax = (float)RefFlowStat.Max; for (int i = 0; i < BatchRslts.WMPositionsCount; i++) { diff --git a/TBF/BenchControl/Sequences/Statistics.cs b/TBF/BenchControl/Sequences/Statistics.cs index 2f99f4adf..ca44d25ee 100644 --- a/TBF/BenchControl/Sequences/Statistics.cs +++ b/TBF/BenchControl/Sequences/Statistics.cs @@ -1,14 +1,16 @@ using System; +using TBF.BenchControl.GenericDevices; namespace TBF.BenchControl.Sequences { 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 - + 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 + public readonly IPlotter plotter; + bool recordingInProgress; double[] fifo; double[] sorted; double first; @@ -16,42 +18,58 @@ namespace TBF.BenchControl.Sequences double min; double max; double sum; - UInt32 totalCount; /// Number of samples passed to Update() - UInt32 count; /// Number of processed and filtered samples - UInt32 fifoCount; /// Number of samples inserted into FIFO + int totalCount; /// Number of samples passed to Update() + int count; /// Number of processed and filtered samples + int fifoCount; /// Number of samples inserted into FIFO + int graphId; + public bool RecordingIProgress { get { return recordingInProgress; } } public double First { get { return first; } } public double Last { get { return last; } } public double Min { get { return (count > 0) ? min : 0; } } /// 0 when there were no samples public double Max { get { return (count > 0) ? max : 0; } } /// 0 when there were no samples public double Average { get { return (count > 0) ? (sum / (double)count) : 0; } } - public UInt32 Count { get { return count; } } + public int Count { get { return count; } } public double Sum { get { return sum; } } - public Statistics(int skippedSamplesCount, int filterSize, bool medianFilter) + public Statistics(int skippedSamplesCount, int filterSize, bool medianFilter, IPlotter plotter) { this.SkippedSamplesCount = skippedSamplesCount; this.FilterSize = filterSize; this.MedianFilter = medianFilter; + this.plotter = plotter; - Clear(); - if (FilterSize > 0) + if (filterSize > 0) { fifo = new double[FilterSize]; sorted = new double[FilterSize]; } + + recordingInProgress = false; } - public Statistics() : this(0, 0, false) + public Statistics(int skippedSamplesCount, int filterSize, bool medianFilter) + : this(skippedSamplesCount, filterSize, medianFilter, new DummyPlotter()) { } + public Statistics(IPlotter plotter) + : this(0, 0, false, plotter) + { + } + + public Statistics() + : this(0, 0, false, new DummyPlotter()) + { + } + + /// - /// Resets statistics + /// Resets statistics and start collecting /// - public void Clear() + public void Start(int batchNr, string testName, int repetition) { sum = 0; min = double.MaxValue; @@ -61,6 +79,22 @@ namespace TBF.BenchControl.Sequences totalCount = 0; count = 0; fifoCount = 0; + + recordingInProgress = true; + + graphId = plotter.StartGraph(batchNr, testName, repetition); + } + + /// + /// Resets statistics + /// + public void Stop() + { + if (recordingInProgress) + { + recordingInProgress = false; + plotter.StopGraph(graphId); + } } @@ -88,11 +122,14 @@ namespace TBF.BenchControl.Sequences /// New value public void Update(double value) { - if (totalCount >= SkippedSamplesCount) + if (recordingInProgress) { - Process(value); + if (totalCount >= SkippedSamplesCount) + { + Process(value); + } + totalCount++; } - totalCount++; } @@ -112,6 +149,8 @@ namespace TBF.BenchControl.Sequences if (value < min) min = filteredValue; if (value > max) max = filteredValue; + plotter.UpdateGraph(graphId, (float)(count + SkippedSamplesCount + FilterSize / 2), (float)value); + count++; } } @@ -162,4 +201,13 @@ namespace TBF.BenchControl.Sequences } } } + + class DummyPlotter : IPlotter + { + public DummyPlotter() { } + + public int StartGraph(int batchNr, string testName, int repetition) { return 1; } + public void UpdateGraph(int graphId, float x, float y) { } + public void StopGraph(int graphId) { } + } } diff --git a/TBF/BenchControl/TestMethods/Adjustment/AdjustmentSeq.cs b/TBF/BenchControl/TestMethods/Adjustment/AdjustmentSeq.cs index f2b17b1a1..aebbacfc1 100644 --- a/TBF/BenchControl/TestMethods/Adjustment/AdjustmentSeq.cs +++ b/TBF/BenchControl/TestMethods/Adjustment/AdjustmentSeq.cs @@ -326,7 +326,7 @@ namespace TBF.BenchControl.TestMethods.Adjustment queryEnd1 = cBrd.QueryMeasurementEndOp(); queryEnd2 = cBrd.QueryMeasurementEndOp(); - ClearAllStatistics(StateMachine.Time); + StartNewStatistics(StateMachine.Time, BatchRslts.Batch.BatchNr, test.Name, repetitionNr); /// Measurement loop - begin while (true) diff --git a/TBF/BenchControl/TestMethods/CombinedWithDetection/CombinedWithDetectionSeq.cs b/TBF/BenchControl/TestMethods/CombinedWithDetection/CombinedWithDetectionSeq.cs index ad5bd3a5a..83331633f 100644 --- a/TBF/BenchControl/TestMethods/CombinedWithDetection/CombinedWithDetectionSeq.cs +++ b/TBF/BenchControl/TestMethods/CombinedWithDetection/CombinedWithDetectionSeq.cs @@ -491,7 +491,7 @@ namespace TBF.BenchControl.TestMethods.CombinedWithDetection queryEnd1 = cBrd.QueryMeasurementEndOp(); queryEnd2 = cBrd.QueryMeasurementEndOp(); - ClearAllStatistics(StateMachine.Time); + StartNewStatistics(StateMachine.Time, BatchRslts.Batch.BatchNr, test.Name, repetitionNr); int estimtdEndTime = StateMachine.Time + (int)test.TstTime; /// Read the diverter switch time diff --git a/TBF/BenchControl/TestMethods/Endurance/EnduranceSeq.cs b/TBF/BenchControl/TestMethods/Endurance/EnduranceSeq.cs index ee407fb14..c10773184 100644 --- a/TBF/BenchControl/TestMethods/Endurance/EnduranceSeq.cs +++ b/TBF/BenchControl/TestMethods/Endurance/EnduranceSeq.cs @@ -267,7 +267,7 @@ namespace TBF.BenchControl.TestMethods.Endurance queryEnd1 = cBrd.QueryMeasurementEndOp(); int estimtdEndTime = StateMachine.Time + (int)test.TstTime; - ClearAllStatistics(StateMachine.Time); + StartNewStatistics(StateMachine.Time, BatchRslts.Batch.BatchNr, test.Name, repetitionNr); /// Measurement loop - begin State.Create(string.Format("{0}({1}) : Reading watermeters", test.Method, test.Name)) @@ -323,6 +323,8 @@ namespace TBF.BenchControl.TestMethods.Endurance test_completed: + StopRecordingStatistics(); + //------------------------------------------------ Bridge.OnActivity(this, Strings.Test_completed); //------------------------------------------------ @@ -492,7 +494,7 @@ namespace TBF.BenchControl.TestMethods.Endurance while (!e.Contains(Event.PreviousStopped)); int estimtdEndTime = StateMachine.Time + (int)test.TstTime; - ClearAllStatistics(StateMachine.Time); + StartNewStatistics(StateMachine.Time, BatchRslts.Batch.BatchNr, test.Name, repetitionNr); /// @@ -642,6 +644,8 @@ namespace TBF.BenchControl.TestMethods.Endurance stopTest: + StopRecordingStatistics(); + /// /// Quit this sequence /// diff --git a/TBF/BenchControl/TestMethods/FixedStartAdvanced/FixedStartAdvancedSeq.cs b/TBF/BenchControl/TestMethods/FixedStartAdvanced/FixedStartAdvancedSeq.cs index 1254ebb18..f02563c6d 100644 --- a/TBF/BenchControl/TestMethods/FixedStartAdvanced/FixedStartAdvancedSeq.cs +++ b/TBF/BenchControl/TestMethods/FixedStartAdvanced/FixedStartAdvancedSeq.cs @@ -325,7 +325,7 @@ namespace TBF.BenchControl.TestMethods.FixedStartAdvanced queryEnd1 = cBrd.QueryMeasurementEndOp(); queryEnd2 = cBrd.QueryMeasurementEndOp(); - ClearAllStatistics(StateMachine.Time); + StartNewStatistics(StateMachine.Time, BatchRslts.Batch.BatchNr, test.Name, repetitionNr); int estimtdEndTime = StateMachine.Time + (int)test.TstTime; /// Measurement loop - begin @@ -368,6 +368,8 @@ namespace TBF.BenchControl.TestMethods.FixedStartAdvanced test_completed: + StopRecordingStatistics(); + State.Create("FixedStartAdvanced : Closing the start/stop valve at the end of the fixed start test") .AddOperation(checkUiOp) .AddOperation(StateMachine.ControlBoard.SetValvesOp(null, outPath.StartValve)) @@ -587,6 +589,8 @@ namespace TBF.BenchControl.TestMethods.FixedStartAdvanced stopTest: + StopRecordingStatistics(); + /// /// Quit this sequence /// diff --git a/TBF/BenchControl/TestMethods/FixedStartDeferredEvaluation/FixedStartDeferredEvaluationSeq.cs b/TBF/BenchControl/TestMethods/FixedStartDeferredEvaluation/FixedStartDeferredEvaluationSeq.cs index a5eb649bb..52d966d82 100644 --- a/TBF/BenchControl/TestMethods/FixedStartDeferredEvaluation/FixedStartDeferredEvaluationSeq.cs +++ b/TBF/BenchControl/TestMethods/FixedStartDeferredEvaluation/FixedStartDeferredEvaluationSeq.cs @@ -614,8 +614,8 @@ namespace TBF.BenchControl.TestMethods.FixedStartDeferredEvaluation queryEnd1 = cBrd.QueryMeasurementEndOp(); queryEnd2 = cBrd.QueryMeasurementEndOp(); - ClearAllStatistics(StateMachine.Time); - int estimtdEndTime = StateMachine.Time + (int)test.TstTime; + StartNewStatistics(StateMachine.Time, BatchRslts.Batch.BatchNr, test.Name, repetitionNr); + int estimtdEndTime = StateMachine.Time + (int)test.TstTime; /// Measurement loop - begin do @@ -692,6 +692,8 @@ namespace TBF.BenchControl.TestMethods.FixedStartDeferredEvaluation test_completed: + StopRecordingStatistics(); + EndTime = (double)StateMachine.Time; State.Create(string.Format("{0}({1}) : Closing the start/stop valve at the end of the fixed start test", test.Method, test.Name)) @@ -944,6 +946,8 @@ namespace TBF.BenchControl.TestMethods.FixedStartDeferredEvaluation stopTest: + StopRecordingStatistics(); + /// /// Quit this sequence /// diff --git a/TBF/BenchControl/TestMethods/FixedStartMassCollection/FixedStartMassCollectionSeq.cs b/TBF/BenchControl/TestMethods/FixedStartMassCollection/FixedStartMassCollectionSeq.cs index 5a6446081..31032f827 100644 --- a/TBF/BenchControl/TestMethods/FixedStartMassCollection/FixedStartMassCollectionSeq.cs +++ b/TBF/BenchControl/TestMethods/FixedStartMassCollection/FixedStartMassCollectionSeq.cs @@ -611,8 +611,8 @@ namespace TBF.BenchControl.TestMethods.FixedStartMassCollection queryEnd1 = cBrd.QueryMeasurementEndOp(); queryEnd2 = cBrd.QueryMeasurementEndOp(); - ClearAllStatistics(StateMachine.Time); - int estimtdEndTime = StateMachine.Time + (int)test.TstTime; + StartNewStatistics(StateMachine.Time, BatchRslts.Batch.BatchNr, test.Name, repetitionNr); + int estimtdEndTime = StateMachine.Time + (int)test.TstTime; /// Measurement loop - begin do @@ -689,6 +689,8 @@ namespace TBF.BenchControl.TestMethods.FixedStartMassCollection test_completed: + StopRecordingStatistics(); + EndTime = (double)StateMachine.Time; State.Create(string.Format("{0}({1}) : Closing the start/stop valve at the end of the fixed start test", test.Method, test.Name)) @@ -1148,6 +1150,8 @@ namespace TBF.BenchControl.TestMethods.FixedStartMassCollection stopTest: + StopRecordingStatistics(); + /// /// Quit this sequence /// diff --git a/TBF/BenchControl/TestMethods/FlyingStart/FlyingStartSeq.cs b/TBF/BenchControl/TestMethods/FlyingStart/FlyingStartSeq.cs index 876c25e5f..4b041196c 100644 --- a/TBF/BenchControl/TestMethods/FlyingStart/FlyingStartSeq.cs +++ b/TBF/BenchControl/TestMethods/FlyingStart/FlyingStartSeq.cs @@ -416,7 +416,7 @@ namespace TBF.BenchControl.TestMethods.FlyingStart queryEnd1 = cBrd.QueryMeasurementEndOp(); int estimtdEndTime = StateMachine.Time + (int)test.TstTime; - ClearAllStatistics(StateMachine.Time); + StartNewStatistics(StateMachine.Time, BatchRslts.Batch.BatchNr, test.Name, repetitionNr); /// Measurement loop - begin State.Create("Read water meters") @@ -490,6 +490,8 @@ namespace TBF.BenchControl.TestMethods.FlyingStart test_completed: + StopRecordingStatistics(); + //------------------------------------------------ Bridge.OnActivity(this, Strings.Test_completed); //------------------------------------------------ @@ -754,6 +756,8 @@ namespace TBF.BenchControl.TestMethods.FlyingStart stopTest: + StopRecordingStatistics(); + /// /// Quit this sequence /// diff --git a/TBF/BenchControl/TestMethods/FlyingStartFirstRepetWithMassColl/FlyingStartFirstRepetWithMassCollSeq.cs b/TBF/BenchControl/TestMethods/FlyingStartFirstRepetWithMassColl/FlyingStartFirstRepetWithMassCollSeq.cs index c17f53387..8b52ea7da 100644 --- a/TBF/BenchControl/TestMethods/FlyingStartFirstRepetWithMassColl/FlyingStartFirstRepetWithMassCollSeq.cs +++ b/TBF/BenchControl/TestMethods/FlyingStartFirstRepetWithMassColl/FlyingStartFirstRepetWithMassCollSeq.cs @@ -582,7 +582,7 @@ namespace TBF.BenchControl.TestMethods.FlyingStartFirstRepetWithMassColl queryEnd1 = cBrd.QueryMeasurementEndOp(); /// ??? int estimtdEndTime = StateMachine.Time + (int)((repetitionNr == 1) ? test.TstTime : (test.TstTime * nextTestVolume / test.Volume)); - ClearAllStatistics(StateMachine.Time); + StartNewStatistics(StateMachine.Time, BatchRslts.Batch.BatchNr, test.Name, repetitionNr); if (repetitionNr == 1) { @@ -667,6 +667,8 @@ namespace TBF.BenchControl.TestMethods.FlyingStartFirstRepetWithMassColl test_completed: + StopRecordingStatistics(); + if (repetitionNr == 1) { /// @@ -1093,6 +1095,8 @@ namespace TBF.BenchControl.TestMethods.FlyingStartFirstRepetWithMassColl stopTest: + StopRecordingStatistics(); + /// /// Quit this sequence /// diff --git a/TBF/BenchControl/TestMethods/FlyingStartMassCollProlonged/FlyingStartMassCollProlongedSeq.cs b/TBF/BenchControl/TestMethods/FlyingStartMassCollProlonged/FlyingStartMassCollProlongedSeq.cs index 1356d91b9..169c7cf9f 100644 --- a/TBF/BenchControl/TestMethods/FlyingStartMassCollProlonged/FlyingStartMassCollProlongedSeq.cs +++ b/TBF/BenchControl/TestMethods/FlyingStartMassCollProlonged/FlyingStartMassCollProlongedSeq.cs @@ -585,7 +585,7 @@ namespace TBF.BenchControl.TestMethods.FlyingStartMassCollProlonged readRegistersOp = new Operations.ReadMoreRegistersOp(sensPath.RegisterReaders); int estimtdEndTime = StateMachine.Time + (int)test.TstTime; - ClearAllStatistics(StateMachine.Time); + StartNewStatistics(StateMachine.Time, BatchRslts.Batch.BatchNr, test.Name, repetitionNr); /// Read the diverter switch time switchTimeStart = 0.001f * (float)cBrd.DivTime(0); @@ -667,6 +667,8 @@ namespace TBF.BenchControl.TestMethods.FlyingStartMassCollProlonged test_completed: + StopRecordingStatistics(); + /// /// (Berlin:) Water is stopped immediately after the test and before the 2nd mass measurement in case: /// - no 'transition sequence after test' is used @@ -1061,6 +1063,8 @@ namespace TBF.BenchControl.TestMethods.FlyingStartMassCollProlonged stopTest: + StopRecordingStatistics(); + /// /// Quit this sequence /// diff --git a/TBF/BenchControl/TestMethods/FlyingStartMassCollection/FlyingStartMassCollectionSeq.cs b/TBF/BenchControl/TestMethods/FlyingStartMassCollection/FlyingStartMassCollectionSeq.cs index 26e332822..4335fb437 100644 --- a/TBF/BenchControl/TestMethods/FlyingStartMassCollection/FlyingStartMassCollectionSeq.cs +++ b/TBF/BenchControl/TestMethods/FlyingStartMassCollection/FlyingStartMassCollectionSeq.cs @@ -90,8 +90,8 @@ namespace TBF.BenchControl.TestMethods.FlyingStartMassCollection //------------------------------------------------------------------- State.Create(string.Format("{0}({1}) : Simulation", test.Method, test.Name)) - .AddOperation(checkUiOp) - .EnterState(); + .AddOperation(checkUiOp) + .EnterState(); e = StateMachine.WaitRunDevsRunOps(); if (TestAndLogUiCmdStop(test, e)) retVal = Event.UiCmdStop; @@ -101,6 +101,67 @@ namespace TBF.BenchControl.TestMethods.FlyingStartMassCollection retListSim.Add(retVal); return retListSim; } + else if (debugLevel == Config.Entities.DebugMode.Inherit) + { + /// + /// Test method with flow chart simulation + /// + Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.FlowSetting)); + + + /// Simulate flow + StartNewStatistics(StateMachine.Time, BatchRslts.Batch.BatchNr, test.Name, repetitionNr); + + IntBox remainingTime = new IntBox((int)test.TstTime); + State.Create(string.Format("{0}({1}) : Simulation", test.Method, test.Name)) + .AddOperation(checkUiOp) + .AddOperation(new Operations.TimerOp((int)test.TstTime, remainingTime)) + .EnterState(); + do + { + e = StateMachine.WaitRunDevsRunOps(); + if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; break; } + + Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.Test)); + + if (remainingTime.Val > 60) + { + Bridge.OnActivity(this, string.Format("{0} ... {1} {2} {3} {4}", Strings.Test_in_progress, remainingTime.Val / 60, "min", remainingTime.Val % 60, Strings.sec)); + } + else + { + Bridge.OnActivity(this, string.Format("{0} ... {1} s", Strings.Test_in_progress, remainingTime.Val)); + } + //------------------------------------------------ + + RefFlow.Val = (1.0 + 0.2 * Math.Sin(2 * Math.PI * (float)remainingTime.Val / test.TstTime)) * (test.Qfrom + test.Qto) / 2.0; + + UpdateAllStatistics(StateMachine.Time); + } + while (!e.Contains(Event.TimerExpired)); + + StopRecordingStatistics(); + + if (retVal != Event.UiCmdStop) + { + float errorPctBase = -1.0f; + + if (test.Name.ToLower().Contains("q3")) errorPctBase = -0.5f; + else if (test.Name.ToLower().Contains("q2")) errorPctBase = 0.5f; + else if (test.Name.ToLower().Contains("q1")) errorPctBase = -5.1f; + + MakeSimulated(test.Name, test.Repeats, repetitionNr, 0, errorPctBase + repetitionNr * 0.1f); + + Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.Completed)); + Bridge.OnTestCompleted(this, new TestCompletedEventArgs(test.Name, BatchRslts.GetTestRslt(Results.Utils.GetTestName(test.Name, 1, 1), 0))); + allResults.Info(TestResult2CsvLine(test.Name, 0)); /// Append the results to the CSV-file + } + + /// Create a list with one item 'retVal' (default is Event.Done) and return it + IList retListSim = new List(1); + retListSim.Add(retVal); + return retListSim; + } Elde.ControlBoardDev cBrd = StateMachine.ControlBoard; @@ -573,7 +634,7 @@ namespace TBF.BenchControl.TestMethods.FlyingStartMassCollection readRegistersOp = new Operations.ReadMoreRegistersOp(sensPath.RegisterReaders); int estimtdEndTime = StateMachine.Time + (int)test.TstTime; - ClearAllStatistics(StateMachine.Time); + StartNewStatistics(StateMachine.Time, BatchRslts.Batch.BatchNr, test.Name, repetitionNr); /// Read the diverter switch time switchTimeStart = 0.001f * (float)cBrd.DivTime(0); @@ -655,6 +716,8 @@ namespace TBF.BenchControl.TestMethods.FlyingStartMassCollection test_completed: + StopRecordingStatistics(); + /// /// (Berlin:) Water is stopped immediately after the test and before the 2nd mass measurement in case: /// - no 'transition sequence after test' is used @@ -1071,6 +1134,8 @@ namespace TBF.BenchControl.TestMethods.FlyingStartMassCollection stopTest: + StopRecordingStatistics(); /// Make sure graph files are closed + /// /// Quit this sequence /// diff --git a/TBF/BenchControl/TestMethods/LeakTest/LeakTestSeq.cs b/TBF/BenchControl/TestMethods/LeakTest/LeakTestSeq.cs index b1a6e4cd9..b9d55c0d1 100644 --- a/TBF/BenchControl/TestMethods/LeakTest/LeakTestSeq.cs +++ b/TBF/BenchControl/TestMethods/LeakTest/LeakTestSeq.cs @@ -121,7 +121,7 @@ namespace TBF.BenchControl.TestMethods.LeakTest pressure_set: - ClearAllStatistics(StateMachine.Time); + StartNewStatistics(StateMachine.Time, BatchRslts.Batch.BatchNr, test.Name, repetitionNr); UpdateAllStatistics(StateMachine.Time); startTime = StateMachine.Time; @@ -216,7 +216,7 @@ namespace TBF.BenchControl.TestMethods.LeakTest TestStartTime = DateTime.Now; startTime = StateMachine.Time; estimtdEndTime = startTime + testParams.DurationLeak; - ClearAllStatistics(StateMachine.Time); + StartNewStatistics(StateMachine.Time, BatchRslts.Batch.BatchNr, test.Name, repetitionNr); //------------------------------------------------ Bridge.OnActivity(this, Strings.Test_in_progress); @@ -255,6 +255,8 @@ namespace TBF.BenchControl.TestMethods.LeakTest test_completed: + StopRecordingStatistics(); + //------------------------------------------------ Bridge.OnActivity(this, Strings.Test_completed); //------------------------------------------------ @@ -364,6 +366,8 @@ namespace TBF.BenchControl.TestMethods.LeakTest stopTest: + StopRecordingStatistics(); + Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.TransitionAfter)); /// diff --git a/TBF/BenchControl/TestMethods/PMaxTest/PMaxTestSeq.cs b/TBF/BenchControl/TestMethods/PMaxTest/PMaxTestSeq.cs index 9c06d3330..1450a45e6 100644 --- a/TBF/BenchControl/TestMethods/PMaxTest/PMaxTestSeq.cs +++ b/TBF/BenchControl/TestMethods/PMaxTest/PMaxTestSeq.cs @@ -122,7 +122,7 @@ namespace TBF.BenchControl.TestMethods.PMaxTest pressure_set: - ClearAllStatistics(StateMachine.Time); + StartNewStatistics(StateMachine.Time, BatchRslts.Batch.BatchNr, test.Name, repetitionNr); UpdateAllStatistics(StateMachine.Time); startTime = StateMachine.Time; @@ -166,6 +166,8 @@ namespace TBF.BenchControl.TestMethods.PMaxTest test_completed: + StopRecordingStatistics(); + TestEndTime = DateTime.Now; //------------------------------------------------ @@ -275,6 +277,8 @@ namespace TBF.BenchControl.TestMethods.PMaxTest stopTest: + StopRecordingStatistics(); + Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.TransitionAfter)); /// diff --git a/TBF/BenchControl/TestMethods/ReferenceFlowmeterCalibration/ReferenceFlowmeterCalibrationSeq.cs b/TBF/BenchControl/TestMethods/ReferenceFlowmeterCalibration/ReferenceFlowmeterCalibrationSeq.cs index 06564fe58..32900a641 100644 --- a/TBF/BenchControl/TestMethods/ReferenceFlowmeterCalibration/ReferenceFlowmeterCalibrationSeq.cs +++ b/TBF/BenchControl/TestMethods/ReferenceFlowmeterCalibration/ReferenceFlowmeterCalibrationSeq.cs @@ -206,7 +206,7 @@ namespace TBF.BenchControl.TestMethods.ReferenceFlowmeterCalibration queryEnd1 = cBrd.QueryMeasurementEndOp(); queryEnd2 = cBrd.QueryMeasurementEndOp(); - ClearAllStatistics(StateMachine.Time); + StartNewStatistics(StateMachine.Time, BatchRslts.Batch.BatchNr, test.Name, repetitionNr); /// Read the diverter switch time switchTimeStart = 0.001f * (float)cBrd.DivTime(0); @@ -233,6 +233,9 @@ namespace TBF.BenchControl.TestMethods.ReferenceFlowmeterCalibration /// Measurement loop - end test_completed: + + StopRecordingStatistics(); + State.Create("ReferenceFlowmeterCalibration : Waiting before mass measurement") .AddOperation(checkUiOp) .AddOperation(benchPath.TempMtrUp.ReadTempOp(ref TempUp)) @@ -378,6 +381,8 @@ namespace TBF.BenchControl.TestMethods.ReferenceFlowmeterCalibration stopTest: + StopRecordingStatistics(); + /// /// Quit this sequence /// diff --git a/TBF/Boxes/FloatBox.cs b/TBF/Boxes/FloatBox.cs index 0697e1a9b..0e860445a 100644 --- a/TBF/Boxes/FloatBox.cs +++ b/TBF/Boxes/FloatBox.cs @@ -54,10 +54,10 @@ namespace TBF.Boxes /// string.Format(FormatEx, val.ToString(Format)) /// If the value is invalid, the conversion result is 'FormatInvalid'. /// - public string Format = null; /// Used as an argument of ToString.) function - public string FormatEx = "{0}"; /// Used as the first argument of string.Format(...), can be modified to contain units, etc. + public string Format = null; /// Used as an argument of ToString.) function + public string FormatEx = "{0}"; /// Used as the first argument of string.Format(...), can be modified to contain units, etc. public string FormatInvalid = "---"; - public float Factor = 1.0f; + public float Factor = 1.0f; /// Factor is used when converting to/from string by ToString(), UpdateParam() and ValidateParam() public float LimitLo = float.MinValue; public float LimitHi = float.MaxValue; diff --git a/TBF/Program.cs b/TBF/Program.cs index 059a8a931..0dca768c4 100644 --- a/TBF/Program.cs +++ b/TBF/Program.cs @@ -16,7 +16,8 @@ namespace TBF public class Program { public const string HomeDir = "C:\\Tbf\\"; /// Contains subdirectories Results, Logs, Images, ... - public const string ImagesDir = "C:\\Tbf\\Images\\"; + public const string GraphsDir = "C:\\Tbf\\Graphs\\"; + public const string ImagesDir = "C:\\Tbf\\Images\\"; public const string TempImagesDir = "C:\\Tbf\\Images\\Temp\\"; /// log4net diff --git a/TBF/Screens/Graph.cs b/TBF/Screens/Graph.cs new file mode 100644 index 000000000..362bc1a48 --- /dev/null +++ b/TBF/Screens/Graph.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace TBF.Screens +{ + public class Graph + { + public Graph(string fileName) + { + + } + } +} diff --git a/TBF/TBF.csproj b/TBF/TBF.csproj index 930010975..263ddec9f 100644 --- a/TBF/TBF.csproj +++ b/TBF/TBF.csproj @@ -523,6 +523,7 @@ + @@ -865,6 +866,7 @@ WriterCfgCtrl.cs + @@ -1573,6 +1575,7 @@ True Strings.zh-CN.resx + UserControl