Production tracing bug fix : Previous workstep result was not checked, mere existence of a record was sufficient for a WM to pass

This commit is contained in:
Milan Hanajik 2023-04-13 17:59:05 +02:00
parent 07d75b7d00
commit 0d47578441

View File

@ -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<object[]> results = session.QueryOver<ReferenceRecord>(() => refRecord)
IList<object[]> records = session.QueryOver<ReferenceRecord>(() => refRecord)
.Where(rr => (rr.Code == wm.SerialNr))
.OrderBy(rr => rr.TimeStamp).Asc
.JoinQueryOver<Workstep>(rr => rr.Workstep, () => workstep)
.And(ws => (ws.Name != WorkstepName))
.Select(projections)
.List<object[]>();
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<Process>()
.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);
}
}