From 0d475784411444ff8a0ea117b0a07fc18ca32905 Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Thu, 13 Apr 2023 17:59:05 +0200 Subject: [PATCH] Production tracing bug fix : Previous workstep result was not checked, mere existence of a record was sufficient for a WM to pass --- .../Output/DB/ProductionTracing/Tracing.cs | 44 ++++++++----------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/TBF/Rig/Output/DB/ProductionTracing/Tracing.cs b/TBF/Rig/Output/DB/ProductionTracing/Tracing.cs index 3cadbca15..71fb853b8 100644 --- a/TBF/Rig/Output/DB/ProductionTracing/Tracing.cs +++ b/TBF/Rig/Output/DB/ProductionTracing/Tracing.cs @@ -35,6 +35,7 @@ namespace TBF.Rig.Output.DB.ProductionTracing public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(-1)); } public const string WorkstepName = "Test_bench"; + public const int WorkstepRsltOK = 0; MonitoringCfg tracingCfg; string workplace @@ -394,22 +395,24 @@ namespace TBF.Rig.Output.DB.ProductionTracing Workstep workstep = null; ProjectionList projections = Projections.ProjectionList(); - projections.Add(Projections.Property(() => refRecord.Id)); /// rslt[0] = reference record ID - projections.Add(Projections.Property(() => workstep.Id)); /// rslt[1] = workstep ID - projections.Add(Projections.Property(() => refRecord.Process.Id)); /// rslt[2] = process ID - projections.Add(Projections.Property(() => refRecord.TimeStamp)); /// rslt[3] = reference record time stamp + projections.Add(Projections.Property(() => refRecord.Id)); /// rcrd[0] = reference record ID + projections.Add(Projections.Property(() => workstep.Id)); /// rcrd[1] = workstep ID + projections.Add(Projections.Property(() => refRecord.Process.Id)); /// rcrd[2] = process ID + projections.Add(Projections.Property(() => refRecord.TimeStamp)); /// rcrd[3] = reference record time stamp + projections.Add(Projections.Property(() => refRecord.Result)); /// rcrd[4] = result: =0...OK, >0...error code /// /// Get all reference records with Code == SerialNr from all worksteps different from 'Test_bench' /// - IList results = session.QueryOver(() => refRecord) + IList records = session.QueryOver(() => refRecord) .Where(rr => (rr.Code == wm.SerialNr)) + .OrderBy(rr => rr.TimeStamp).Asc .JoinQueryOver(rr => rr.Workstep, () => workstep) .And(ws => (ws.Name != WorkstepName)) .Select(projections) .List(); - if (results.Count == 0) + if (records.Count == 0) { /// No records found wm.ProcessId = 0; @@ -422,27 +425,18 @@ namespace TBF.Rig.Output.DB.ProductionTracing /// /// Get processId of the last record /// - int processId = 0; - DateTime lastTimeStamp = DateTime.MinValue; - foreach (var rslt in results) - { - if (DateTime.Compare((DateTime)rslt[3], lastTimeStamp) > 0) - { - lastTimeStamp = (DateTime)rslt[3]; - processId = (int)rslt[2]; - } - } - - if (processId == 0) return Retv.Error; /// This should never happen + int lastProcessId = (int)records[records.Count - 1][2]; + DateTime lastTimeStamp = (DateTime)records[records.Count - 1][3]; + if (lastProcessId == 0) return Retv.Error; /// This should never happen - if ((currentProcess == null) || (currentProcess.Id != processId)) + if ((currentProcess == null) || (currentProcess.Id != lastProcessId)) { /// /// Process changed ==> update currentProcess / currentWorkstep / verifiedWorkstep / verifiedPart / verifyReferencePart /// var processes = session.QueryOver() - .Where(p => (p.Id == processId)) + .Where(p => (p.Id == lastProcessId)) .List(); if (processes.Count != 1) return Retv.Error; @@ -472,13 +466,13 @@ namespace TBF.Rig.Output.DB.ProductionTracing wm.ProcessId = currentProcess.Id; wm.SessionId = sessionId; wm.LastRecordIsNok = true; /// NOK (=default if no matching record found) - foreach (var rslt in results) + foreach (var rcrd in records) { - if ((verifiedWorkstep.Id == (int)rslt[1]) && (processId == (int)rslt[2])) + if ((verifiedWorkstep.Id == (int)rcrd[1]) && (lastProcessId == (int)rcrd[2])) { - /// This record fits verification requirements - wm.LastRecordIsNok = false; /// OK - break; + /// This record fits verification requirements. + /// As records are ordered by time, the result of the last one determines the verification result. + wm.LastRecordIsNok = ((int)rcrd[4] != WorkstepRsltOK); } }