private void InitializeData() { var modelContext = this._result.GetCtx <ModelDataContext>(); _totalWoListDic = new Dictionary <string, List <WoData.WorkOrder> >(); string filter = Globals.CreateFilter(string.Empty, SimResultData.EqpPlan.Schema.SHOP_ID, "=", this.SelectedShopID); filter = Globals.CreateFilter(filter, SimResultData.EqpPlan.Schema.EQP_ID, "<>", Consts.NULL_ID, "AND"); filter = Globals.CreateFilter(filter, SimResultData.EqpPlan.Schema.START_TIME, ">=", this.FromTime.ToString(), "AND"); filter = Globals.CreateFilter(filter, SimResultData.EqpPlan.Schema.START_TIME, "<", this.ToTime.ToString(), "AND"); DataTable dtEqpPlan = _result.LoadOutput(SimResultData.OutputName.EqpPlan, filter); string sorter = SimResultData.EqpPlan.Schema.SHOP_ID + "," + SimResultData.EqpPlan.Schema.EQP_ID + "," + SimResultData.EqpPlan.Schema.START_TIME + "," + SimResultData.EqpPlan.Schema.PRODUCT_ID + "," + SimResultData.EqpPlan.Schema.LAYER_ID + "," + SimResultData.EqpPlan.Schema.STEP_ID; DataView eqpPlanView = new DataView(dtEqpPlan, "", sorter, DataViewRowState.CurrentRows); dtEqpPlan = eqpPlanView.ToTable(); int totalRowCnt = dtEqpPlan.Rows.Count; bool isLast = false; WoData.WorkOrder workOrder = new WoData.WorkOrder(); int rowCnt = 0; string preShopEqp = string.Empty; string preShopEqpProd = string.Empty; string preStepInfo = string.Empty; DateTime preEndTime = DateTime.MaxValue; foreach (DataRow row in dtEqpPlan.Rows) { rowCnt++; SimResultData.EqpPlan eqpPlan = new SimResultData.EqpPlan(row); if (eqpPlan.EqpID == "8APPH13") { } string shift = ShopCalendar.ClassifyShift(eqpPlan.StartTime) == 1 ? WoData.Const.DAY : WoData.Const.NIGHT; if (rowCnt == 1) { string eqpGrpIdInEqp; if (_eqpGrpInEqpDic.TryGetValue(eqpPlan.ShopID + eqpPlan.EqpID, out eqpGrpIdInEqp) == false) { eqpGrpIdInEqp = string.Empty; } workOrder.SetBaseInfo(eqpPlan.ShopID, eqpPlan.EqpID, eqpPlan.EqpGroupID, eqpGrpIdInEqp, eqpPlan.ProductID, shift, eqpPlan.StartTime, eqpPlan.LayerID, eqpPlan.StepID); } string shopEqp = eqpPlan.ShopID + eqpPlan.EqpID; string shopEqpProd = eqpPlan.ShopID + eqpPlan.EqpID + eqpPlan.ProductID; string stepInfo = eqpPlan.LayerID + eqpPlan.StepID; bool isNew = false; if (shopEqp != preShopEqp) { isNew = true; } else if (shopEqpProd != preShopEqpProd) { isNew = true; } else if (eqpPlan.StartTime > preEndTime) { isNew = true; } else if (preStepInfo != stepInfo) { isNew = true; } if (rowCnt == totalRowCnt) { isLast = true; } bool savePreVal = false; bool newWorkOrder = false; if ((isNew == false && isLast == false) || rowCnt == 1) { workOrder.AddQty(eqpPlan.Qty); } else if (isNew && isLast == false) { savePreVal = true; // 여태까지꺼 rlst에 기록 newWorkOrder = true; // workOrder 새로 만들기 + Qty추가 } else if (isNew == false && isLast) { savePreVal = true; workOrder.AddQty(eqpPlan.Qty); } else if (isNew && isLast) { savePreVal = true; // 여태까지꺼 rlst에 기록 newWorkOrder = true; // workOrder 새로 만들고 + Qty추가하고 + rlst에 기록 } if (savePreVal) { List <WoData.WorkOrder> woList; if (_totalWoListDic.TryGetValue(preShopEqp, out woList) == false) { _totalWoListDic.Add(preShopEqp, woList = new List <WoData.WorkOrder>()); } woList.Add(workOrder); } if (newWorkOrder) { string eqpGrpIdInEqp; if (_eqpGrpInEqpDic.TryGetValue(eqpPlan.ShopID + eqpPlan.EqpID, out eqpGrpIdInEqp) == false) { eqpGrpIdInEqp = string.Empty; } workOrder = new WoData.WorkOrder(); workOrder.SetBaseInfo(eqpPlan.ShopID, eqpPlan.EqpID, eqpPlan.EqpGroupID, eqpGrpIdInEqp, eqpPlan.ProductID, shift, eqpPlan.StartTime, eqpPlan.LayerID, eqpPlan.StepID); workOrder.AddQty(eqpPlan.Qty); if (isLast) { List <WoData.WorkOrder> woList; if (_totalWoListDic.TryGetValue(shopEqp, out woList) == false) { _totalWoListDic.Add(shopEqp, woList = new List <WoData.WorkOrder>()); } woList.Add(workOrder); } } preShopEqp = shopEqp; preShopEqpProd = shopEqpProd; preEndTime = eqpPlan.EndTime; preStepInfo = stepInfo; } }
private void InitializeData() { var modelContext = this._result.GetCtx <ModelDataContext>(); _stdStepDic = new Dictionary <string, TcData.StepInfo>(); var stdStep = modelContext.StdStep.Where(x => x.STEP_SEQ > 0) .OrderBy(x => x.SHOP_ID);//.OrderByDescending(x => x.STEP_SEQ); foreach (var step in stdStep) { if (_stdStepDic.ContainsKey(step.SHOP_ID + step.STEP_ID) == false) { _stdStepDic.Add(step.SHOP_ID + step.STEP_ID, new TcData.StepInfo(step.SHOP_ID, step.STEP_ID, step.STEP_DESC, step.STEP_TYPE, (int)step.STEP_SEQ, step.LAYER_ID)); } } try { _defaultRunTat = this.IsUseDefaultTatChecked ? Convert.ToDouble(_result.Experiment.GetArgument("DefaultRunTAT")) : 0.0; _defaultWaitTat = this.IsUseDefaultTatChecked ? Convert.ToDouble(_result.Experiment.GetArgument("DefaultWaitTAT")) : 0.0; } catch { _defaultWaitTat = 0; _defaultRunTat = 0; } var dtProduct = modelContext.Product; Dictionary <string, string> mainProcByProdDic = new Dictionary <string, string>(); foreach (var prod in dtProduct) { if (mainProcByProdDic.ContainsKey(prod.SHOP_ID + prod.PRODUCT_ID) == false) { mainProcByProdDic.Add(prod.SHOP_ID + prod.PRODUCT_ID, prod.PROCESS_ID); } } var dtTat = modelContext.Tat;//modelContext.Tat.Where(x => x.PRODUCT_TYPE == Consts.Production); Dictionary <string, TcData.TatInfo> tatAllDic = new Dictionary <string, TcData.TatInfo>(); foreach (var row in dtTat) { TcData.TatInfo tatInfo = new TcData.TatInfo(row.WAIT_TAT, row.RUN_TAT); if (tatAllDic.ContainsKey(row.SHOP_ID + row.PRODUCT_ID + row.PROCESS_ID + row.STEP_ID) == false) { tatAllDic.Add(row.SHOP_ID + row.PRODUCT_ID + row.PROCESS_ID + row.STEP_ID, tatInfo); } } var dtProcStepMand = modelContext.ProcStep.OrderBy(x => x.SHOP_ID + x.PROCESS_ID).OrderBy(x => x.STEP_SEQ); _procStepDic = new Dictionary <string, List <ProcStep> >(); foreach (var row in dtProcStepMand) { string key = CommonHelper.CreateKey(row.SHOP_ID, row.PROCESS_ID); List <ProcStep> list; if (_procStepDic.TryGetValue(key, out list) == false) { _procStepDic.Add(key, list = new List <ProcStep>()); } list.Add(row); } List <string> mainProcInEqpPlanList = new List <string>(); DataTable dtEqpPlan = _result.LoadOutput(SimResultData.OutputName.EqpPlan); foreach (DataRow drow in dtEqpPlan.Rows) { SimResultData.EqpPlan eqpPlan = new SimResultData.EqpPlan(drow); string mainProcID = string.Empty; mainProcByProdDic.TryGetValue(eqpPlan.ShopID + eqpPlan.ProductID, out mainProcID); if (string.IsNullOrEmpty(mainProcID)) { continue; } string item = CommonHelper.CreateKey(eqpPlan.ShopID, eqpPlan.ProductID, mainProcID); if (mainProcInEqpPlanList.Contains(item) == false) { mainProcInEqpPlanList.Add(item); } } // 기준정보 Tat 집계 _tatDic = new Dictionary <string, TcData.ProcStepTatInfo>(); foreach (string item in mainProcInEqpPlanList) { string shopID = item.Split('@')[0]; string prodID = item.Split('@')[1]; string mainProcID = item.Split('@')[2]; string key = CommonHelper.CreateKey(shopID, mainProcID); List <ProcStep> procStepList; if (_procStepDic.TryGetValue(key, out procStepList) == false) { continue; } double cumTat = 0; List <string> keyList = new List <string>(); foreach (ProcStep procStep in procStepList) { double waitTat = _defaultWaitTat; double runTat = _defaultWaitTat; double tat = waitTat + runTat; string key2 = procStep.SHOP_ID + prodID + procStep.PROCESS_ID + procStep.STEP_ID; TcData.TatInfo tatInfo; if (tatAllDic.TryGetValue(key2, out tatInfo)) { waitTat = tatInfo.WaitTat; runTat = tatInfo.RunTat; tat = tatInfo.Tat; } cumTat += tat; TcData.ProcStepTatInfo psTatInfo; if (_tatDic.TryGetValue(key2, out psTatInfo) == false) { _tatDic.Add(key2, psTatInfo = new TcData.ProcStepTatInfo(procStep.SHOP_ID, prodID, procStep.PROCESS_ID, procStep.STEP_ID, procStep.STEP_SEQ, waitTat, runTat, cumTat)); } if (keyList.Contains(key2) == false) { keyList.Add(key2); } } double totalTat = cumTat; foreach (string k in keyList) { TcData.ProcStepTatInfo psTatInfo; if (_tatDic.TryGetValue(k, out psTatInfo) == false) { continue; // 있을 수 없음 } psTatInfo.SetTotalTat(totalTat); } } // Simuation Run, Wait TAT 산출 && 시뮬레이션에서 FabIn부터 FabOut까지 흐른 Product 집계 _simTatInfoDic = new Dictionary <string, TcData.SimTatInfo>(); _allStepRunProdInSimList = new List <string>(); var eqpPlanDic = dtEqpPlan.AsEnumerable() .GroupBy(x => x.GetString(SimResultData.EqpPlanSchema.LOT_ID)) .ToDictionary(x => x.Key); foreach (string lotID in eqpPlanDic.Keys) { var sortedList = eqpPlanDic[lotID].OrderBy(x => x.GetDateTime(SimResultData.EqpPlanSchema.START_TIME)); if (sortedList.Count() >= 2) { var firstRow = sortedList.ToList()[0]; foreach (var row in sortedList) { string rowShopID = row.GetString(SimResultData.EqpPlanSchema.SHOP_ID); string rowStepID = row.GetString(SimResultData.EqpPlanSchema.STEP_ID); if (_stdStepDic.ContainsKey(rowShopID + rowStepID)) { firstRow = row; break; } } var lastRow = sortedList.ToList()[sortedList.Count() - 1]; string shopID = firstRow.GetString(SimResultData.EqpPlanSchema.SHOP_ID); string prodID = firstRow.GetString(SimResultData.EqpPlanSchema.PRODUCT_ID); string mainProcID = string.Empty; mainProcByProdDic.TryGetValue(shopID + prodID, out mainProcID); if (string.IsNullOrEmpty(mainProcID) == false) { string key = CommonHelper.CreateKey(shopID, mainProcID); List <ProcStep> procStepList; if (_procStepDic.TryGetValue(key, out procStepList) && procStepList.Count() >= 2) { string firstStepReal = procStepList[0].STEP_ID; string lastStepReal = procStepList[procStepList.Count() - 1].STEP_ID; string firstStepLot = firstRow.GetString(SimResultData.EqpPlanSchema.STEP_ID); string lastStepLot = lastRow.GetString(SimResultData.EqpPlanSchema.STEP_ID); if (firstStepReal == firstStepLot && lastStepReal == lastStepLot) { if (_allStepRunProdInSimList.Contains(shopID + prodID) == false) { _allStepRunProdInSimList.Add(shopID + prodID); } } } } } DateTime preRowEndTime = DateTime.MinValue; foreach (var row in sortedList) { string shopID = row.GetString(SimResultData.EqpPlanSchema.SHOP_ID); string prodID = row.GetString(SimResultData.EqpPlanSchema.PRODUCT_ID); string procID = row.GetString(SimResultData.EqpPlanSchema.PROCESS_ID); string stepID = row.GetString(SimResultData.EqpPlanSchema.STEP_ID); DateTime startTime = row.GetDateTime(SimResultData.EqpPlanSchema.START_TIME); DateTime endTime = row.GetDateTime(SimResultData.EqpPlanSchema.END_TIME); // 시뮬레이션 투입 Lot은 EqpPlan에 ARRAY/ARRAY00000 이런 식으로 정보가 한 줄 더 찍힘 -> 이에 대한 예외처리 if (_stdStepDic.ContainsKey(shopID + stepID) == false) { continue; } string mainChecker = CommonHelper.CreateKey(shopID, prodID, procID); if (mainProcInEqpPlanList.Contains(mainChecker) == false) { preRowEndTime = endTime; continue; } double runTAT = endTime > startTime ? (endTime - startTime).TotalSeconds : 0; double waitTAT = preRowEndTime == DateTime.MinValue ? 0 : startTime > preRowEndTime ? (startTime - preRowEndTime).TotalSeconds : 0; if (runTAT <= 0 && preRowEndTime == DateTime.MinValue) { preRowEndTime = endTime; continue; } DateTime targetShift = ShopCalendar.ShiftStartTimeOfDayT(startTime); TcData.SimTatInfo simTatInfo; if (_simTatInfoDic.TryGetValue(shopID + targetShift + prodID + procID + stepID, out simTatInfo) == false) { _simTatInfoDic.Add(shopID + targetShift + prodID + procID + stepID, simTatInfo = new TcData.SimTatInfo(shopID, targetShift, prodID, procID, stepID)); } if (runTAT > 0) { simTatInfo.AddRunTatToList(runTAT); } if (preRowEndTime != DateTime.MinValue) { simTatInfo.AddWaitTatToList(waitTAT); } preRowEndTime = endTime; } } }