From bed0046618fff4759c98107477c675d7d351a798 Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Tue, 12 Sep 2017 15:39:22 +0200 Subject: [PATCH] (1) More logging, (2) Bug fixes in Statistics, (3) Bug fixes in ErrorFlags.Errors, ver. 2.16.655 --- Results/DB.cs | 12 ++++++ Results/Entities/Batch.cs | 9 +++++ Results/Entities/TestRslt.cs | 22 +++++++++- .../Network/Camera/Display/DisplayForm.cs | 11 +++++ .../BenchControl/Sequences/Statistics.cs | 22 +++++----- .../BenchControl/Various/ErrorFlags/Errors.cs | 40 ++++++++++--------- TestBenchFramework/Properties/AssemblyInfo.cs | 4 +- 7 files changed, 89 insertions(+), 31 deletions(-) diff --git a/Results/DB.cs b/Results/DB.cs index 86631c224..597ec6d4c 100644 --- a/Results/DB.cs +++ b/Results/DB.cs @@ -254,6 +254,12 @@ namespace Results foreach (var cd in ComponentsList) if (cd.Id == 0) session.SaveOrUpdate(cd); foreach (var wd in WaterMeterDataList) if (wd.Id == 0) session.SaveOrUpdate(wd); + log.Debug(batch.ToString(1)); + foreach (var tstRslt in batch.TestRslts) + { + log.Debug(tstRslt.ToString(1)); + } + session.SaveOrUpdate(batch); transaction.Commit(); @@ -261,7 +267,13 @@ namespace Results catch (Exception exc) { transaction.Rollback(); + log.FatalFormat("Saving results of batch #{0} into the results DB failed: {1}", batch.BatchNr, exc.Message); + if (exc.InnerException != null && !string.IsNullOrEmpty(exc.InnerException.Message)) + { + log.FatalFormat("Inner exception message: {0}", exc.InnerException.Message); + } + return false; } diff --git a/Results/Entities/Batch.cs b/Results/Entities/Batch.cs index 067c61409..d38f85729 100644 --- a/Results/Entities/Batch.cs +++ b/Results/Entities/Batch.cs @@ -126,5 +126,14 @@ namespace Results.Entities { return string.Format("Batch #{0}, Start:{1}, End:{2}, Procedure:{3}", BatchNr, StartTime, EndTime, ProcedureName); } + + public virtual string ToString(int i) + { + return string.Format("Batch: BatchNr={0} TestBenchId={1} ProgramVersion={2} UserName={3} UserNumber={4} ProcedureName={5} ProcedureRevision={6} ProtocolTitle={7} Remark={8} DensityCorr={9} Custom2={10} Custom3={11} StartTime={12} EndTime={13} Dirty={14} RsltsSent={15} RsltsPrinted={16}", + BatchNr, TestBenchId, ProgramVersion, UserName, UserNumber, + ProcedureName, ProcedureRevision, ProtocolTitle, Remark, DensityCorr, + Custom2, Custom3, StartTime, EndTime, Dirty, + RsltsSent, RsltsPrinted); + } } } diff --git a/Results/Entities/TestRslt.cs b/Results/Entities/TestRslt.cs index fc20ef6f8..99ee9a1a6 100644 --- a/Results/Entities/TestRslt.cs +++ b/Results/Entities/TestRslt.cs @@ -255,5 +255,25 @@ namespace Results.Entities { return string.Format("batch={0}, procedure={1}, test={2}, {3} {4}", Batch.BatchNr, Batch.ProcedureName, Name(), StartTime.ToShortDateString(), StartTime.ToShortTimeString()); } - } + + public virtual string ToString(int i) + { + return string.Format("TestRslt: Part={0} RepetitionNr={1} TestDone={2} Remark={3} StartTime={4} EndTime={5} FlowSetTime={6} TestTime={7} PulsesMaster={8} ConstMaster={9} MassStartRaw={10} MassStart={11} MassEndRaw={12} MassEnd={13} DensityIn={14} DensityOut={15} DensityDiv={16} Buoyancy={17} FlowMass={18} FlowVolume={19} VolumeCTV={20} VolumeMaster={21} ErrorMaster={22} ErrorFlags={23} ErrorFlagsMd={24} AmbTempMean={25} AmbTempStart={26} AmbTempEnd={27} AmbTempMin={28} AmbTempMax={29} AmbPressMean={30} AmbPressStart={31} AmbPressEnd={32} AmbPressMin={33} AmbPressMax={34} AmbHumiMean={35} AmbHumiStart={36} AmbHumiEnd={37} AmbHumiMin={38} AmbHumiMax={39} PressUpMean={40} PressUpStart={41} PressUpEnd={42} PressUpMin={43} PressUpMax={44} PressDownMean={45} PressDownStart={46} PressDownEnd={47} PressDownMin={48} PressDownMax={49} PressDeltaMean={50} PressDeltaStart={51} PressDeltaEnd={52} PressDeltaMin={53} PressDeltaMax={54} TempUpMean={55} TempUpStart={56} TempUpEnd={57} TempUpMin={58} TempUpMax={59} TempDownMean={60} TempDownStart={61} TempDownEnd={62} TempDownMin={63} TempDownMax={64} TempDivMean={65} TempDivStart={66} TempDivEnd={67} TempDivMin={68} TempDivMax={69} FlowMean={70} FlowStart={71} FlowEnd={72} FlowMin={73} FlowMax={74} Custom1={75} Custom2={76} Custom3={77} Custom4={78} Custom5={79} Custom6={80} Custom7={81} Custom8={82} Custom9={83} Custom10={84}", + Part, RepetitionNr, TestDone, Remark, StartTime, EndTime, FlowSetTime, TestTime, + PulsesMaster, ConstMaster, MassStartRaw, MassStart, MassEndRaw, MassEnd, + DensityIn, DensityOut, DensityDiv, Buoyancy, FlowMass, FlowVolume, + VolumeCTV, VolumeMaster, ErrorMaster, ErrorFlags, ErrorFlagsMd, + AmbTempMean, AmbTempStart, AmbTempEnd, AmbTempMin, AmbTempMax, + AmbPressMean, AmbPressStart, AmbPressEnd, AmbPressMin, AmbPressMax, + AmbHumiMean, AmbHumiStart, AmbHumiEnd, AmbHumiMin, AmbHumiMax, + PressUpMean, PressUpStart, PressUpEnd, PressUpMin, PressUpMax, + PressDownMean, PressDownStart, PressDownEnd, PressDownMin, PressDownMax, + PressDeltaMean, PressDeltaStart, PressDeltaEnd, PressDeltaMin, PressDeltaMax, + TempUpMean, TempUpStart, TempUpEnd, TempUpMin, TempUpMax, + TempDownMean, TempDownStart, TempDownEnd, TempDownMin, TempDownMax, + TempDivMean, TempDivStart, TempDivEnd, TempDivMin, TempDivMax, + FlowMean, FlowStart, FlowEnd, FlowMin, FlowMax, + Custom1, Custom2, Custom3, Custom4, Custom5, Custom6, Custom7, Custom8, Custom9, Custom10); + } + } } diff --git a/TestBenchFramework/BenchControl/Network/Camera/Display/DisplayForm.cs b/TestBenchFramework/BenchControl/Network/Camera/Display/DisplayForm.cs index dd6a72ac2..120a08abe 100644 --- a/TestBenchFramework/BenchControl/Network/Camera/Display/DisplayForm.cs +++ b/TestBenchFramework/BenchControl/Network/Camera/Display/DisplayForm.cs @@ -7,6 +7,7 @@ using System.Windows.Forms; using log4net; using TBF.Resources; using System.Drawing; +using System.Text; namespace TBF.BenchControl.Network.Camera.Display { @@ -144,18 +145,21 @@ namespace TBF.BenchControl.Network.Camera.Display private void okButton_Click(object sender, EventArgs e) { + log.Warn("OK clicked"); Result = DialogResult.OK; CloseAfterButtonClick(); } private void abortButton_Click(object sender, EventArgs e) { + log.Warn("Abort clicked"); Result = DialogResult.Abort; CloseAfterButtonClick(); } private void retryButton_Click(object sender, EventArgs e) { + log.Warn("Retry clicked"); Result = DialogResult.Retry; CloseAfterButtonClick(); } @@ -170,10 +174,17 @@ namespace TBF.BenchControl.Network.Camera.Display void UpdateData() { + StringBuilder sb = new StringBuilder(); + + sb.Append("1 "); for (int i = 0; i < Math.Min(imagesCount, boxesCount); i++) { SelectedImages[i] = checkBoxes[i].Checked; + sb.AppendFormat("{0}", checkBoxes[i].Checked ? "x" : "-"); } + sb.AppendFormat(" {0}", Math.Min(imagesCount, boxesCount)); + + log.WarnFormat("Data updated: {0}", sb.ToString()); } } } diff --git a/TestBenchFramework/BenchControl/Sequences/Statistics.cs b/TestBenchFramework/BenchControl/Sequences/Statistics.cs index 9286926fc..2f99f4adf 100644 --- a/TestBenchFramework/BenchControl/Sequences/Statistics.cs +++ b/TestBenchFramework/BenchControl/Sequences/Statistics.cs @@ -22,9 +22,9 @@ namespace TBF.BenchControl.Sequences public double First { get { return first; } } public double Last { get { return last; } } - public double Min { get { return min; } } - public double Max { get { return max; } } - public double Average { get { if (count > 0) return (sum / (double)count); else return 0; } } + 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 double Sum { get { return sum; } } @@ -88,7 +88,10 @@ namespace TBF.BenchControl.Sequences /// New value public void Update(double value) { - if (totalCount >= SkippedSamplesCount) Process(value); + if (totalCount >= SkippedSamplesCount) + { + Process(value); + } totalCount++; } @@ -103,11 +106,12 @@ namespace TBF.BenchControl.Sequences 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; + sum += filteredValue; + if (count == 0) first = filteredValue; + last = filteredValue; + if (value < min) min = filteredValue; + if (value > max) max = filteredValue; + count++; } } diff --git a/TestBenchFramework/BenchControl/Various/ErrorFlags/Errors.cs b/TestBenchFramework/BenchControl/Various/ErrorFlags/Errors.cs index f60b3fa35..3d65e773e 100644 --- a/TestBenchFramework/BenchControl/Various/ErrorFlags/Errors.cs +++ b/TestBenchFramework/BenchControl/Various/ErrorFlags/Errors.cs @@ -29,38 +29,40 @@ namespace TBF.BenchControl.Various.ErrorFlags public int GetErrorFlags(Test test, double testTime) { + /// Any E# is 'true' on error, 'false' when OK + if (Mode != ErrorFlagsMode.Info && Mode != ErrorFlagsMode.On) return 0; /// return 0 when Mode == ErrorFlagsMode.Off /// Max. and min. flow - bool E1 = ProcessData.RefFlowStat.Min >= test.Qfrom - && ProcessData.RefFlowStat.Max <= test.Qto; + bool E1 = ProcessData.RefFlowStat.Min < test.Qfrom + || ProcessData.RefFlowStat.Max > test.Qto; /// Max. and min. up and down water temperature - bool E2 = ProcessData.TempUpStat.Min >= test.TempLimLo - && ProcessData.TempUpStat.Min <= test.TempLimHi - && ProcessData.TempDownStat.Min >= test.TempLimLo - && ProcessData.TempDownStat.Min <= test.TempLimHi; + bool E2 = ProcessData.TempUpStat.Min < test.TempLimLo + || ProcessData.TempUpStat.Max > test.TempLimHi + || ProcessData.TempDownStat.Min < test.TempLimLo + || ProcessData.TempDownStat.Max > test.TempLimHi; /// Max. flow deviation - bool E3 = ProcessData.RefFlowStat.Min >= ProcessData.RefFlowStat.Average * (1.0f - errorsCfg.TestParams.Delta_Q_pct / 100.0f) - && ProcessData.RefFlowStat.Max <= ProcessData.RefFlowStat.Average * (1.0f + errorsCfg.TestParams.Delta_Q_pct / 100.0f); + bool E3 = ProcessData.RefFlowStat.Min < ProcessData.RefFlowStat.Average * (1.0f - errorsCfg.TestParams.Delta_Q_pct / 100.0f) + || ProcessData.RefFlowStat.Max > ProcessData.RefFlowStat.Average * (1.0f + errorsCfg.TestParams.Delta_Q_pct / 100.0f); /// Max. up and down water temperature deviation - bool E4 = ProcessData.TempUpStat.Min >= ProcessData.TempUpStat.Average - errorsCfg.TestParams.Delta_T - && ProcessData.TempUpStat.Min <= ProcessData.TempUpStat.Average + errorsCfg.TestParams.Delta_T - && ProcessData.TempDownStat.Min >= ProcessData.TempDownStat.Average - errorsCfg.TestParams.Delta_T - && ProcessData.TempDownStat.Min <= ProcessData.TempDownStat.Average + errorsCfg.TestParams.Delta_T; + bool E4 = ProcessData.TempUpStat.Min < ProcessData.TempUpStat.Average - errorsCfg.TestParams.Delta_T + || ProcessData.TempUpStat.Max > ProcessData.TempUpStat.Average + errorsCfg.TestParams.Delta_T + || ProcessData.TempDownStat.Min < ProcessData.TempDownStat.Average - errorsCfg.TestParams.Delta_T + || ProcessData.TempDownStat.Max > ProcessData.TempDownStat.Average + errorsCfg.TestParams.Delta_T; /// Max. absolute value of up and down water temperature difference - bool E5 = ProcessData.TempDiffStat.Max <= errorsCfg.TestParams.Delta_Tup_Tdn; + bool E5 = ProcessData.TempDiffStat.Max > errorsCfg.TestParams.Delta_Tup_Tdn; bool E6 = false; /// Test time (min) - bool E7 = testTime >= errorsCfg.TestParams.TestTime_min; + bool E7 = testTime < errorsCfg.TestParams.TestTime_min; /// Test time (max) - bool E8 = testTime <= errorsCfg.TestParams.TestTime_max; + bool E8 = testTime > errorsCfg.TestParams.TestTime_max; bool E9 = false; bool E10 = false; @@ -68,12 +70,12 @@ namespace TBF.BenchControl.Various.ErrorFlags bool E12 = false; /// Ambient temperature - bool E13 = ProcessData.AmbTempStat.Min >= errorsCfg.TestParams.AmbTemp_min - && ProcessData.AmbTempStat.Max <= errorsCfg.TestParams.AmbTemp_max; + bool E13 = ProcessData.AmbTempStat.Min < errorsCfg.TestParams.AmbTemp_min + || ProcessData.AmbTempStat.Max > errorsCfg.TestParams.AmbTemp_max; /// Water pressure - bool E14 = ProcessData.PressUpStat.Min >= errorsCfg.TestParams.Pressure_min - && ProcessData.PressUpStat.Max <= errorsCfg.TestParams.Pressure_max; + bool E14 = ProcessData.PressUpStat.Min < errorsCfg.TestParams.Pressure_min + || ProcessData.PressUpStat.Max > errorsCfg.TestParams.Pressure_max; bool E15 = false; bool E16 = false; diff --git a/TestBenchFramework/Properties/AssemblyInfo.cs b/TestBenchFramework/Properties/AssemblyInfo.cs index 770b02fe4..90ac9219f 100644 --- a/TestBenchFramework/Properties/AssemblyInfo.cs +++ b/TestBenchFramework/Properties/AssemblyInfo.cs @@ -29,5 +29,5 @@ using System.Runtime.InteropServices; // Build Number // Revision // -[assembly: AssemblyVersion("2.16.651.1")] -[assembly: AssemblyFileVersion("2.16.651.1")] +[assembly: AssemblyVersion("2.16.655.1")] +[assembly: AssemblyFileVersion("2.16.655.1")]