Пример #1
0
        public void QueueTablesCorrectlyCreated()
        {
            var now   = new DateTime(2018, 7, 12, 5, 6, 7, DateTimeKind.Utc);
            var matId = _log.AllocateMaterialID("uuu5", "part5", 1);
            var mat   = new LogMaterial(matId, "uuu5", 1, "part5", 1, "", "", "");

            _log.RecordAddMaterialToQueue(JobLogDB.EventLogMaterial.FromLogMat(mat), "queue", 5, now.AddHours(2));

            _log.GetMaterialInQueue("queue").Should().BeEquivalentTo(new[] {
                new JobLogDB.QueuedMaterial()
                {
                    MaterialID   = matId,
                    Queue        = "queue",
                    Position     = 0,
                    Unique       = "uuu5",
                    PartName     = "part5",
                    NumProcesses = 1,
                }
            });
        }
Пример #2
0
        private static void AddLoads(JobLogDB log, IEnumerable <LoadAction> currentLoads, string pallet, PalletLocation palLoc, TimeSpan?elapsedLoadTime, CurrentStatus curStatus)
        {
            var queuedMats = new Dictionary <string, List <BlackMaple.MachineFramework.JobLogDB.QueuedMaterial> >();

            //process remaining loads/unloads (already processed ones have been removed from currentLoads)
            foreach (var operation in currentLoads)
            {
                if (!operation.LoadEvent || operation.LoadStation != palLoc.Num)
                {
                    continue;
                }
                for (int i = 0; i < operation.Qty; i++)
                {
                    List <BlackMaple.MachineFramework.JobLogDB.QueuedMaterial> queuedMat = null;
                    if (curStatus.Jobs.ContainsKey(operation.Unique))
                    {
                        var queue = curStatus.Jobs[operation.Unique].GetInputQueue(process: operation.Process, path: operation.Path);
                        if (!string.IsNullOrEmpty(queue))
                        {
                            //only lookup each queue once
                            if (queuedMats.ContainsKey(queue))
                            {
                                queuedMat = queuedMats[queue];
                            }
                            else
                            {
                                queuedMat = log.GetMaterialInQueue(queue).ToList();
                                queuedMats.Add(queue, queuedMat);
                            }
                        }
                    }
                    long   matId  = -1;
                    string serial = null;
                    string workId = null;
                    var    loc    = new InProcessMaterialLocation()
                    {
                        Type = InProcessMaterialLocation.LocType.Free
                    };
                    if (queuedMat != null)
                    {
                        var mat = queuedMat
                                  .Where(m => m.Unique == operation.Unique)
                                  .Select(m => (JobLogDB.QueuedMaterial?)m)
                                  .DefaultIfEmpty(null)
                                  .First();
                        if (mat.HasValue)
                        {
                            matId = mat.Value.MaterialID;
                            loc   = new InProcessMaterialLocation()
                            {
                                Type          = InProcessMaterialLocation.LocType.InQueue,
                                CurrentQueue  = mat.Value.Queue,
                                QueuePosition = mat.Value.Position,
                            };
                            queuedMat.RemoveAll(m => m.MaterialID == mat.Value.MaterialID);
                            var matDetails = log.GetMaterialDetails(matId);
                            serial = matDetails?.Serial;
                            workId = matDetails?.Workorder;
                        }
                    }
                    var inProcMat = new InProcessMaterial()
                    {
                        MaterialID  = matId,
                        JobUnique   = operation.Unique,
                        PartName    = operation.Part,
                        Process     = operation.Process,
                        Path        = operation.Path,
                        Serial      = serial,
                        WorkorderId = workId,
                        Location    = loc,
                        Action      = new InProcessMaterialAction()
                        {
                            Type                  = InProcessMaterialAction.ActionType.Loading,
                            LoadOntoPallet        = pallet,
                            LoadOntoFace          = operation.Process,
                            ProcessAfterLoad      = operation.Process,
                            PathAfterLoad         = operation.Path,
                            ElapsedLoadUnloadTime = elapsedLoadTime
                        }
                    };
                    curStatus.Material.Add(inProcMat);
                }
            }
        }
Пример #3
0
        private void CheckCastingsForProc1(IGrouping <string, ScheduleWithQueues> job, MazakSchedulesAndLoadActions mazakData)
        {
            string uniqueStr = job.Key;

            // group the paths for this process by input queue
            var proc1PathsByQueue = job
                                    .Where(s => s.SchRow.PlanQuantity > CountCompletedOrMachiningStarted(s))
                                    .Select(s => s.Procs[1])
                                    .Where(p => !string.IsNullOrEmpty(p.InputQueue))
                                    .GroupBy(p => p.InputQueue);

            foreach (var queueGroup in proc1PathsByQueue)
            {
                var matInQueue =
                    _log.GetMaterialInQueue(queueGroup.Key)
                    .Where(m => m.Unique == uniqueStr && FindNextProcess(m.MaterialID) == 1)
                    .Count()
                ;
                var curMazakSchMat = queueGroup.Select(s => s.SchProcRow.ProcessMaterialQuantity).Sum();

                log.Debug("Calculated {matInQueue} parts in queue and {mazakCnt} parts in mazak for job {uniq} proccess 1",
                          matInQueue, curMazakSchMat, uniqueStr);

                if (queueGroup.Count() == 1)
                {
                    // put all material on the single path
                    if (matInQueue != curMazakSchMat)
                    {
                        queueGroup.First().TargetMaterialCount = matInQueue;
                    }
                }
                else
                {
                    // keep each path at least fixQty piece of material
                    if (matInQueue > curMazakSchMat)
                    {
                        int remain         = matInQueue - curMazakSchMat;
                        var potentialPaths =
                            queueGroup
                            .Where(p => p.SchProcRow.ProcessMaterialQuantity == 0)
                            .OrderBy(p => p.SchProcRow.ProcessExecuteQuantity);
                        foreach (var p in potentialPaths)
                        {
                            int fixQty = p.SchProcRow.FixQuantity;
                            if (fixQty <= remain)
                            {
                                remain -= fixQty;
                                p.TargetMaterialCount = fixQty;
                            }
                            if (remain <= 0)
                            {
                                break;
                            }
                        }
                    }
                    else if (matInQueue < curMazakSchMat)
                    {
                        int toRemove       = curMazakSchMat - matInQueue;
                        var potentialPaths =
                            queueGroup
                            .Where(p => p.SchProcRow.ProcessMaterialQuantity > 0)
                            .OrderByDescending(p => p.SchProcRow.ProcessMaterialQuantity)
                            .ThenBy(p => p.SchProcRow.ProcessExecuteQuantity);
                        foreach (var p in potentialPaths)
                        {
                            if (toRemove >= p.SchProcRow.ProcessMaterialQuantity)
                            {
                                p.TargetMaterialCount = 0;
                                toRemove -= p.SchProcRow.ProcessMaterialQuantity;
                            }
                            else
                            {
                                p.TargetMaterialCount = p.SchProcRow.ProcessMaterialQuantity - toRemove;
                                toRemove = 0;
                            }
                            if (toRemove <= 0)
                            {
                                break;
                            }
                        }
                    }
                }
            }

            // now deal with the non-input-queue parts. They could have larger material than planned quantity
            // if the schedule has been decremented
            foreach (var sch in job)
            {
                if (string.IsNullOrEmpty(sch.Procs[1].InputQueue) &&
                    sch.SchRow.PlanQuantity <= CountCompletedOrMachiningStarted(sch) &&
                    sch.Procs[1].SchProcRow.ProcessMaterialQuantity > 0
                    )
                {
                    sch.Procs[1].TargetMaterialCount = 0;
                }
            }
        }