private static BlackMaple.MachineWatchInterface.LogEntry FindLoadStartFromOldCycles(IEnumerable <BlackMaple.MachineWatchInterface.LogEntry> oldCycles, long?matId = null) { BlackMaple.MachineWatchInterface.LogEntry start = null; var cyclesToSearch = matId != null ? oldCycles.Where(e => e.Material.Any(m => m.MaterialID == matId)) : oldCycles; foreach (var s in cyclesToSearch) { if (s.LogType == LogType.LoadUnloadCycle) { if (s.StartOfCycle) { start = s; } else { start = null; // clear when completed } } } return(start); }
private void HandleMachiningCompleted(BlackMaple.MachineWatchInterface.LogEntry cycle) { foreach (LogMaterial mat in cycle.Material) { if (mat.MaterialID < 0 || mat.JobUniqueStr == null || mat.JobUniqueStr == "") { Log.Debug("HandleMachiningCompleted: Skipping material id " + mat.MaterialID.ToString() + " part " + mat.PartName + " because the job unique string is empty"); continue; } var inspections = new List <JobInspectionData>(); var job = GetJob(mat.JobUniqueStr); if (job == null) { Log.Debug("Couldn't find job for material {uniq}", mat.JobUniqueStr); continue; } foreach (var i in job.GetInspections()) { if (i.InspectSingleProcess <= 0 && mat.Process != mat.NumProcesses) { Log.Debug("Skipping inspection for material " + mat.MaterialID.ToString() + " inspection type " + i.InspectionType + " completed at time " + cycle.EndTimeUTC.ToLocalTime().ToString() + " on pallet " + cycle.Pallet.ToString() + " part " + mat.PartName + " because the process is not the maximum process"); continue; } if (i.InspectSingleProcess >= 1 && mat.Process != i.InspectSingleProcess) { Log.Debug("Skipping inspection for material " + mat.MaterialID.ToString() + " inspection type " + i.InspectionType + " completed at time " + cycle.EndTimeUTC.ToLocalTime().ToString() + " on pallet " + cycle.Pallet.ToString() + " part " + mat.PartName + " process " + mat.Process.ToString() + " because the inspection is only on process " + i.InspectSingleProcess.ToString()); continue; } inspections.Add(i); } _log.MakeInspectionDecisions(mat.MaterialID, mat.Process, inspections); Log.Debug("Making inspection decision for " + string.Join(",", inspections.Select(x => x.InspectionType)) + " material " + mat.MaterialID.ToString() + " completed at time " + cycle.EndTimeUTC.ToLocalTime().ToString() + " on pallet " + cycle.Pallet.ToString() + " part " + mat.PartName); } }
private static BlackMaple.MachineWatchInterface.LogEntry FindMachineStartFromOldCycles(IEnumerable <BlackMaple.MachineWatchInterface.LogEntry> oldCycles, long matId) { BlackMaple.MachineWatchInterface.LogEntry start = null; foreach (var s in oldCycles.Where(e => e.Material.Any(m => m.MaterialID == matId))) { if (s.LogType == LogType.MachineCycle) { if (s.StartOfCycle) { start = s; } else { start = null; // clear when completed } } } return(start); }
private void LoadEvents(string sampleDataPath, TimeSpan offset) { var files = System.IO.Directory.GetFiles(sampleDataPath, "events-*.json"); var evts = new List <BlackMaple.MachineWatchInterface.LogEntry>(); foreach (var f in files) { using (var file = System.IO.File.OpenRead(f)) { var reader = new System.IO.StreamReader(file); while (reader.Peek() >= 0) { var evtJson = reader.ReadLine(); var e = (BlackMaple.MachineWatchInterface.LogEntry)JsonConvert.DeserializeObject( evtJson, typeof(BlackMaple.MachineWatchInterface.LogEntry), _jsonSettings ); evts.Add(e); } } } foreach (var e in evts.OrderBy(e => e.EndTimeUTC)) { foreach (var m in e.Material) { var matDetails = LogDB.GetMaterialDetails(m.MaterialID); if (matDetails == null && !string.IsNullOrEmpty(m.JobUniqueStr)) { LogDB.CreateMaterialID(m.MaterialID, m.JobUniqueStr, m.PartName, m.NumProcesses); } } if (e.LogType == LogType.PartMark) { foreach (var m in e.Material) { LogDB.RecordSerialForMaterialID(JobLogDB.EventLogMaterial.FromLogMat(m), e.Result, e.EndTimeUTC.Add(offset)); } } else if (e.LogType == LogType.OrderAssignment) { foreach (var m in e.Material) { LogDB.RecordWorkorderForMaterialID(JobLogDB.EventLogMaterial.FromLogMat(m), e.Result, e.EndTimeUTC.Add(offset)); } } else if (e.LogType == LogType.FinalizeWorkorder) { LogDB.RecordFinalizedWorkorder(e.Result, e.EndTimeUTC.Add(offset)); } else { if (e.LogType == LogType.InspectionResult && e.Material.Any(m => m.MaterialID == 2965)) { // ignore inspection complete continue; } var e2 = new BlackMaple.MachineWatchInterface.LogEntry( cntr: e.Counter, mat: e.Material, pal: e.Pallet, ty: e.LogType, locName: e.LocationName, locNum: e.LocationNum, prog: e.Program, start: e.StartOfCycle, endTime: e.EndTimeUTC.Add(offset), result: e.Result, endOfRoute: e.EndOfRoute, elapsed: e.ElapsedTime, active: e.ActiveOperationTime ); if (e.ProgramDetails != null) { foreach (var x in e.ProgramDetails) { e2.ProgramDetails.Add(x.Key, x.Value); } } if (e.Tools != null) { foreach (var x in e.Tools) { e2.Tools[x.Key] = x.Value; } } LogDB.AddLogEntryFromUnitTest(e2); } } }