public static void ReqCalc(Client CoreGate, InData modelInData)
 {
     var fex = new FlexHelper("UI.Calc");
     fex.AddArg("SteelType", modelInData.SteelType);
     fex.AddArg("MHi", modelInData.MHi);
     fex.AddArg("MSc", modelInData.MSc);
     fex.AddArg("SiHi", modelInData.SiHi);
     fex.AddArg("THi", modelInData.THi);
     fex.AddArg("IsProcessingUVS", modelInData.IsProcessingUVS);
     fex.Fire(CoreGate);
 }
예제 #2
0
        public static void Reset()
        {
            AutoInData = new InData();
            AutoInData.SiHi = 0;
            AutoInData.THi = 0;

            //m_autoInDataPrevious = new InData();
            //m_autoInDataPrevious.SteelType = -1;
            //m_autoInDataPrevious.THi = -1;
            //m_autoInDataPrevious.SiHi = -1;
            //m_autoInDataPrevious.MSc = -1;
            //m_autoInDataPrevious.MHi = -1;

            Saver.Reset();

            IsRefrashData = false;
        }
 public static bool VerifiInDataChange(InData inData)
 {
     //var result = (inData.IsProcessingUVS != m_autoInDataPrevious.IsProcessingUVS) &&
     var result = (inData.MHi != m_autoInDataPrevious.MHi) &&
                  (inData.MSc != m_autoInDataPrevious.MSc) &&
                  (inData.SiHi != m_autoInDataPrevious.SiHi) &&
                  (inData.SteelType != m_autoInDataPrevious.SteelType) &&
                  (inData.THi != m_autoInDataPrevious.THi);
     if (m_autoInDataPrevious.MHi != -1)
         result = result && (inData.IsProcessingUVS != m_autoInDataPrevious.IsProcessingUVS);
     if (result) {
         //m_autoInDataPrevious.IsProcessingUVS = inData.IsProcessingUVS;
         m_autoInDataPrevious.MHi = inData.MHi;
         m_autoInDataPrevious.MSc = inData.MSc;
         m_autoInDataPrevious.SiHi = inData.SiHi;
         m_autoInDataPrevious.SteelType = inData.SteelType;
         m_autoInDataPrevious.THi = inData.THi;
     }
     return result;
     //return true;
 }
예제 #4
0
        public static void Alg(CSVTableParser table, InData inData, out OutData outData)
        {
            outData = new OutData();
            //const double maxSiHi = 0.8; // максимальный кремний после которого считаем не по таблице

            foreach (var row in table.Rows) {
                var hitDownSiHiRange = (double) (row.Cell["MinSiHotIron"]) <= inData.SiHi;
                var hitUpSiHiRange = (double) (row.Cell["MaxSiHotIron"]) >= inData.SiHi;
                var hitDownTHiRange = (double) (row.Cell["MinTHotIron"]) <= inData.THi;
                var hitUpTHiRange = (double) (row.Cell["MaxTHotIron"]) >= inData.THi;
                outData.IsFound = false;

                if (hitDownSiHiRange && hitUpSiHiRange && hitDownTHiRange && hitUpTHiRange) {
                    outData.IsFound = true;

                    #region новый расчет

                    outData.MHi = (int) Math.Round((double) row.Cell["MassHotIron"]);
                    outData.MSc = (int) Math.Round((double) row.Cell["MassScrap"]);
                    outData.MLi = (int) Math.Round((double) row.Cell["MassLime"]);
                    outData.MDlms = (int) Math.Round((double) row.Cell["MassDolomS"]);
                    outData.MDlm = inData.IsProcessingUVS
                                       ? (int) Math.Round((double) row.Cell["UVSMassDolom"])
                                       : (int) Math.Round((double) row.Cell["MassDolom"]);
                    outData.MFom = inData.IsProcessingUVS
                                       ? (int) Math.Round((double) row.Cell["UVSMassFOM"])
                                       : (int) Math.Round((double) row.Cell["MassFOM"]);

                    #endregion

                    #region старый расчет

                    //double knownTableVal = 1;
                    //double unknownTableVal = 1;
                    //double knownVal = 1;
                    //if (inData.MHi > 0)
                    //{
                    //    outData.MHi = inData.MHi;
                    //    knownVal = inData.MHi;
                    //    knownTableVal = (double) row.Cell["MassHotIron"];
                    //    if (inData.MSc > 0)
                    //    {
                    //        outData.MSc = inData.MSc;
                    //    }
                    //    else
                    //    {
                    //        unknownTableVal = (double)row.Cell["MassScrap"];
                    //        outData.MSc = (int)Math.Round(CalcUnknownVal(knownVal, knownTableVal, unknownTableVal));
                    //    }
                    //}
                    //else if (inData.MSc > 0)
                    //{
                    //    outData.MSc = inData.MSc;
                    //    knownVal = inData.MSc;
                    //    knownTableVal = (double)row.Cell["MassScrap"];
                    //    unknownTableVal = (double)row.Cell["MassHotIron"];
                    //    outData.MHi = (int)Math.Round(CalcUnknownVal(knownVal, knownTableVal, unknownTableVal));
                    //}
                    //else
                    //{
                    //    return;
                    //}

                    //unknownTableVal = (double)row.Cell["MassLime"];
                    //outData.MLi = (int)Math.Round(CalcUnknownVal(knownVal, knownTableVal, unknownTableVal));

                    //unknownTableVal = inData.IsProcessingUVS
                    //                        ? (double)row.Cell["UVSMassDolom"]
                    //                        : (double)row.Cell["MassDolom"];
                    //outData.MDlm = (int)Math.Round(CalcUnknownVal(knownVal, knownTableVal, unknownTableVal));

                    //unknownTableVal = inData.IsProcessingUVS
                    //                        ? (double)row.Cell["UVSMassFOM"]
                    //                        : (double)row.Cell["MassFOM"];
                    //outData.MFom = (int)Math.Round(CalcUnknownVal(knownVal, knownTableVal, unknownTableVal));

                    //unknownTableVal = (double)row.Cell["MassDolomS"];
                    //outData.MDlms = (int)Math.Round(CalcUnknownVal(knownVal, knownTableVal, unknownTableVal));

                    #endregion

                    // досчитываем по замечаниям

                    //######################################################################
                    //Если, при шихтовке, металлолома берётся больше заданного значения,
                    //то убирается «долом С», из расчёта на 1т металлолома – 0,5 т «долом С»
                    if ((inData.MSc > 0) && (inData.MHi > 0)) {
                        var knownTableVal = (double) row.Cell["MassHotIron"];
                        var unknownTableVal = (double) row.Cell["MassScrap"];
                        var calcScrap = (int) Math.Round(CalcUnknownVal(inData.MHi, knownTableVal, unknownTableVal));
                        var scrapDifference = inData.MSc - calcScrap;
                        if (scrapDifference > 0) {
                            var k = 0.5;
                            outData.MDlms -= (int) Math.Round(scrapDifference*k);
                            if (outData.MDlms < 0)
                                outData.MDlms = 0;
                        }
                    }
                    //######################################################################

                    break;
                }
            }
        }
        public void OnEvent(BaseEvent evt)
        {
            using (var l = new Logger("Listener")) {
                #region сбор данных для автоматического режима не FlexEvent

                if (evt is HeatChangeEvent) {
                    var hce = evt as HeatChangeEvent;
                    if (CHeatNumber != hce.HeatNumber) {
                        CHeatNumber = hce.HeatNumber;
                        Program.Reset();
                        l.msg("Heat Changed. New Heat ID: {0}\n", CHeatNumber);
                        Program.Saver.HeatNumber = CHeatNumber;
                    }
                    else
                        l.msg("Heat No Changed. Heat ID: {0}\n", hce.HeatNumber);
                }

                if (evt is ScrapEvent) {
                    var scrapEvent = evt as ScrapEvent;
                    if (scrapEvent.ConverterNumber == Program.ConverterNumber) {
                        Program.AutoInData.MSc = scrapEvent.TotalWeight;
                        l.msg("Scrap mass: {0}", Program.AutoInData.MSc);
                        Program.IsRefrashData = true;
                    }
                }

                #endregion

                if (evt is FlexEvent) {
                    #region интерфейс для визухи

                    var fxe = evt as FlexEvent;
                    if (fxe.Operation.StartsWith("UI.GetNamePatterns")) {
                        l.msg(fxe.ToString());
                        Program.TablePaths = Program.ScanStore(Program.StorePath);
                        var names = Program.GetNamesFromAddress(Program.TablePaths);
                        var fex = new FlexHelper("Charge5.PatternNames");
                        for (int i = 0; i < names.Count; i++)
                            fex.AddArg(i.ToString(), names[i]);
                        fex.Fire(Program.MainGate);
                    }

                    if (fxe.Operation.StartsWith("UI.LoadPattern")) {
                        l.msg(fxe.ToString());
                        try {
                            Program.Tables = Program.LoadTables((string) fxe.Arguments["Name"], ref Program.InitTbl);
                        }
                        catch (Exception e) {
                            l.err("UI.LoadPattern: \n{0}", e.ToString());
                        }

                        var fex = new FlexHelper("Charge5.RespLoadPattern");
                        if (Program.Tables == null) {
                            l.err("pattern not loaded");
                            fex.AddArg("Loaded", false);
                        }
                        else
                            fex.AddArg("Loaded", true);
                        fex.Fire(Program.MainGate);
                    }

                    if (fxe.Operation.StartsWith("UI.Calc")) {
                        var inData = new InData();
                        var outData = new OutData();

                        l.msg(fxe.ToString());
                        try {
                            inData.SteelType = (int) fxe.Arguments["SteelType"]; //

                            inData.MHi = (int) fxe.Arguments["MHi"];
                            inData.MSc = (int) fxe.Arguments["MSc"];
                            inData.SiHi = (double) fxe.Arguments["SiHi"];
                            inData.THi = (int) fxe.Arguments["THi"];

                            inData.IsProcessingUVS = (bool) fxe.Arguments["IsProcessingUVS"]; //
                            var table = Program.Tables[inData.SteelType];
                            Program.Alg(table, inData, out outData);
                            Program.SendResultCalc(outData);
                        }
                        catch (Exception e) {
                            l.err("UI.Calc: \n{0}", e.ToString());
                        }
                    }

                    if (fxe.Operation.StartsWith("UI.GetPattern")) {
                        l.msg(fxe.ToString());
                        try {
                            var name = (string) fxe.Arguments["Name"];
                            Program.LoadTables(name, ref Program.InitTbl);
                            CSVTP_FlexEventConverter.AppName = "Charge5";
                            var flex = CSVTP_FlexEventConverter.PackToFlex(name, Program.InitTbl, Program.Tables);
                            var fex = new FlexHelper(flex.Operation);
                            fex.evt.Arguments = flex.Arguments;
                            fex.Fire(Program.MainGate);
                        }
                        catch (Exception e) {
                            l.err("UI.GetPattern: \n{0}", e.ToString());
                        }
                    }

                    if (fxe.Operation.StartsWith("UI.Tables")) {
                        var fex = new FlexHelper("Charge5.SavePatternResp");
                        l.msg(fxe.ToString());
                        try {
                            var patternName = "";
                            Charge5Classes.CSVTP_FlexEventConverter.UnpackFromFlex(
                                fxe,
                                ref Program.InitTbl,
                                ref Program.Tables,
                                ref patternName
                                );
                            Program.SaveTables(patternName, Program.InitTbl, Program.Tables);
                            fex.AddArg("Saved", true);
                        }
                        catch (Exception e) {
                            l.err("UI.GetPattern: \n{0}", e.ToString());
                            fex.AddArg("Saved", false);
                        }
                        fex.Fire(Program.MainGate);
                    }

                    if (fxe.Operation.StartsWith("UI.RemoovePattern")) {
                        var fex = new FlexHelper("Charge5.RemoovePatternResp");
                        l.msg(fxe.ToString());
                        try {
                            Program.RemooveTables((string) fxe.Arguments["Name"]);
                            fex.AddArg("Remooved", true);
                        }
                        catch (Exception e) {
                            l.err("UI.RemoovePattern: \n{0}", e.ToString());
                            fex.AddArg("Remooved", false);
                        }
                        fex.Fire(Program.MainGate);
                    }

                    #endregion

                    #region интерфейс для визухи в автоматическом режиме

                    if (fxe.Operation.StartsWith("UI.ModeCalc")) {
                        l.msg(fxe.ToString());
                        try {
                            Program.CalcModeIsAutomatic = (bool) fxe.Arguments["IsAutomatic"];
                            Program.IsRefrashData = true;
                        }
                        catch (Exception e) {
                            l.err("UI.CalcMode: \n{0}", e.ToString());
                        }
                    }

                    if (fxe.Operation.StartsWith("UI.DataCalc")) {
                        l.msg(fxe.ToString());
                        try {
                            var steelType = (int) fxe.Arguments["SteelType"];
                            if ((steelType >= 0) && (steelType <= 6)) // имеем только 7 типов стали
                            {
                                Program.AutoInData.SteelType = steelType;
                                Program.IsRefrashData = true;
                            }
                            else
                                throw new Exception("Не верное значение типа стали, >7 или <0");
                            Program.AutoInData.IsProcessingUVS = (bool) fxe.Arguments["IsProcessingUVS"];
                        }
                        catch (Exception e) {
                            l.err("UI.CalcData: \n{0}", e.ToString());
                        }
                    }

                    #endregion

                    #region сбор данных для автоматического режима FlexEvent

                    if (fxe.Operation.StartsWith("PipeCatcher.Call.PCK_DATA.PGET_WGHIRON1")) {
                        if ((string) fxe.Arguments["SHEATNO"] == Convert.ToString(HeatNumberToLong(CHeatNumber))) {
                            l.msg("Iron Correction from Pipe: {0}\n", fxe.Arguments["NWGH_NETTO"]);
                            Program.AutoInData.MHi =
                                (int) Math.Round(Convert.ToDouble(fxe.Arguments["NWGH_NETTO"])*1000);
                            Program.IsRefrashData = true;
                        }
                        else {
                            l.msg(
                                "Iron Correction from Pipe: wrong heat number - expected {0} found {1}",
                                CHeatNumber, fxe.Arguments["SHEATNO"]
                                );
                        }
                    }

                    if (fxe.Operation.StartsWith("PipeCatcher.Call.PCK_DATA.PGET_XIMIRON")) {
                        if ((string) fxe.Arguments["HEAT_NO"] == Convert.ToString(HeatNumberToLong(CHeatNumber))) {
                            l.msg("Xim Iron from Pipe: T = {0}, Si = {1}\n", fxe.Arguments["HM_TEMP"],
                                  fxe.Arguments["ANA_SI"]);
                            Program.AutoInData.SiHi = Convert.ToDouble(fxe.Arguments["ANA_SI"]);
                            Program.AutoInData.THi = Convert.ToInt32(fxe.Arguments["HM_TEMP"]);
                            Program.IsRefrashData = true;
                        }
                        else {
                            l.msg(
                                "Xim Iron from Pipe: wrong heat number - expected {0} found {1}",
                                CHeatNumber, fxe.Arguments["HEAT_NO"]
                                );
                        }
                    }

                    #endregion
                }
            }
        }
 public static bool VerifiInData(InData inData)
 {
     // return ((inData.MHi > 0) || (inData.MSc > 0)) &&
     return (inData.SiHi != 0) &&
            (inData.THi != 0);
 }