コード例 #1
0
 public void GetData(OutData od)
 {
     MHi = od.MHi;
     MSc = od.MSc;
     MLi = od.MLi;
     MDlm = od.MDlm;
     MFom = od.MFom;
     MDlms = od.MDlms;
     IsFound = od.IsFound;
 }
コード例 #2
0
 public static OutData ConverToKg(OutData od)
 {
     var k = 1000;
     od.MDlm *= k;
     od.MDlms *= k;
     od.MFom *= k;
     od.MHi *= k;
     od.MLi *= k;
     od.MSc *= k;
     return od;
 }
コード例 #3
0
        public static void SendResultCalc(OutData outData)
        {
            var fex = new FlexHelper("Charge5.ResultCalc");

            fex.AddArg("MDlm", outData.MDlm); // int
            fex.AddArg("MDlms", outData.MDlms); // int
            fex.AddArg("MFom", outData.MFom); // int
            fex.AddArg("MHi", outData.MHi); // int
            fex.AddArg("MLi", outData.MLi); // int
            fex.AddArg("MSc", outData.MSc); // int
            fex.AddArg("IsFound", outData.IsFound); // bool

            fex.Fire(Program.MainGate);

            Implements.InstantLogger.msg(fex.evt.ToString());
        }
コード例 #4
0
        public static void Iterate()
        {
            if (CalcModeIsAutomatic && VerifiInData(AutoInData) && IsRefrashData) {
                var outData = new OutData();
                var table = Program.Tables[AutoInData.SteelType];
                Alg(table, AutoInData, out outData);
                outData = ConverToKg(outData);
                SendResultCalc(outData);

                Saver.GetData(outData);
                Saver.SiHi = AutoInData.SiHi;
                Saver.THi = AutoInData.THi;
                Saver.SaveArch();

                IsRefrashData = false;
            }
        }
コード例 #5
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;
                }
            }
        }
コード例 #6
0
        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
                }
            }
        }