public static void UnpackFromFlex(FlexEvent mainFlex, ref CSVTableParser inittbl,
            ref List<CSVTableParser> tables, ref string name)
        {
            inittbl.Rows = new List<Row>();
            for (int i = 0; i < tables.Count; i++)
                tables[i].Rows = new List<Row>();

            try {
                var inittblFlex = (FlexEvent) mainFlex.Arguments[InitTblFlexName];
                name = mainFlex.Operation.Split('.').Last();
                foreach (var initTblPath in inittblFlex.Arguments) {
                    var tbIndex = Int32.Parse(initTblPath.Key);
                    var tbName = (string) initTblPath.Value;
                    var tableFlex = (FlexEvent) mainFlex.Arguments[tbName];

                    var inittblRow = new Row();
                    inittblRow.Cell.Add(inittbl.Description[0].ColumnName, tbIndex);
                    inittblRow.Cell.Add(inittbl.Description[1].ColumnName, tbName);
                    inittbl.Rows.Add(inittblRow);

                    foreach (var trfObj in tableFlex.Arguments) {
                        var tableRowFlex = (FlexEvent) trfObj.Value;
                        var tableRow = new Row();
                        foreach (var columnPath in tables[tbIndex].Description)
                            tableRow.Cell.Add(columnPath.ColumnName, tableRowFlex.Arguments[columnPath.ColumnName]);
                        tables[tbIndex].Rows.Add(tableRow);
                    }
                }
            }
            catch (Exception e) {
                InstantLogger.err("CSVTP_FlexEventConverter.UnpackFromFlex:\n{0}", e.ToString());
            }
        }
 public static FlexEvent PackToFlex(string name, CSVTableParser inittbl, List<CSVTableParser> tables)
 {
     var mainFlex = new FlexEvent(AppName + ".Tables." + name);
     var inittblFlex = new FlexEvent(InitTblFlexName);
     var tablesFlexList = new List<FlexEvent>();
     for (int i = 0; i < tables.Count; i++)
         tablesFlexList.Add(new FlexEvent());
     foreach (var row in inittbl.Rows) {
         var keyIndex = inittbl.Description[0].ColumnName;
         var keyName = inittbl.Description[1].ColumnName;
         var tbIndex = (int) row.Cell[keyIndex];
         inittblFlex.Arguments.Add(tbIndex.ToString(), row.Cell[keyName]);
         var tableFlex = new FlexEvent((string) row.Cell[keyName]);
         for (int index = 0; index < tables[tbIndex].Rows.Count; index++) {
             var tableRow = tables[tbIndex].Rows[index];
             var tableRowFlex = new FlexEvent(index.ToString());
             foreach (var columnPath in tables[tbIndex].Description) {
                 var keyCollumn = columnPath.ColumnName;
                 tableRowFlex.Arguments.Add(keyCollumn, tableRow.Cell[keyCollumn]);
             }
             tableFlex.Arguments.Add(index.ToString(), tableRowFlex);
         }
         mainFlex.Arguments.Add(tableFlex.Operation, tableFlex);
     }
     mainFlex.Arguments.Add(inittblFlex.Operation, inittblFlex);
     return mainFlex;
 }
        public static int CalcC(CSVTableParser matrixC, Estimates data)
        {
            using (var l = new Logger("CalcC")) {
                if (
                    (data.CurrentC == 0) &&
                    (data.TargetC == 0)
                    )
                    return 0;
                foreach (var row in matrixC.Rows) {
                    if ((double) (row.Cell["CMin"]) <= data.CurrentC && data.CurrentC < (double) (row.Cell["CMax"])) {
                        l.msg("C item found --- CMin {0}; CMax {1}", row.Cell["CMin"], row.Cell["CMax"]);

                        var differenceC = data.TargetC - data.CurrentC;
                        if (differenceC < 0) {
                            differenceC = Math.Abs(differenceC);
                            var oxygenOnCarbon = (int) (row.Cell["OxygenOnCarbon"]);
                            const double carbonConsumption = 0.01;
                            double correctionOxy = (oxygenOnCarbon/carbonConsumption)*differenceC;
                            l.msg("Correction Oxygen C = {0}", correctionOxy);
                            return (int) Math.Round(correctionOxy);
                        }
                        else
                            return 0;
                    }
                }
            }
            return 0;
        }
 public void Init()
 {
     Requester.ReqPatternNames(Requester.MainGate);
     ResetTables();
     InitTbl = new CSVTableParser();
     Charge5Classes.Descriptions.SetDescriptionPI(ref InitTbl);
     Tables = new List<CSVTableParser>();
     for (int i = 0; i < CountTables; i++) {
         var t = new CSVTableParser();
         Charge5Classes.Descriptions.SetDescriptionTBL(ref t);
         Tables.Add(t);
     }
 }
Ejemplo n.º 5
0
        public static void SaveTables(string name, CSVTableParser inittbl, List<CSVTableParser> tables)
        {
            var currentPathName = StorePath + "\\" + name;
            Directory.CreateDirectory(currentPathName);

            foreach (var row in inittbl.Rows) {
                tables[(int) row.Cell["Index"]].FileName = String.Format("{0}\\{1}.csv", currentPathName,
                                                                         (row.Cell["TableName"]));
                tables[(int) row.Cell["Index"]].Separator = Separator;
                tables[(int) row.Cell["Index"]].Save();
            }
            inittbl.FileName = currentPathName + "\\" + PIName;
            inittbl.Separator = Separator;
            inittbl.Save();
        }
 public static void SetDescriptionTBL(ref CSVTableParser table)
 {
     table.Description.Add(new ColumnPath() {ColumnName = "MinSiHotIron", ColumnType = typeof (double)});
     table.Description.Add(new ColumnPath() {ColumnName = "MaxSiHotIron", ColumnType = typeof (double)});
     table.Description.Add(new ColumnPath() {ColumnName = "MinTHotIron", ColumnType = typeof (double)});
     table.Description.Add(new ColumnPath() {ColumnName = "MaxTHotIron", ColumnType = typeof (double)});
     table.Description.Add(new ColumnPath() {ColumnName = "MassHotIron", ColumnType = typeof (double)});
     table.Description.Add(new ColumnPath() {ColumnName = "MassScrap", ColumnType = typeof (double)});
     table.Description.Add(new ColumnPath() {ColumnName = "MassLime", ColumnType = typeof (double)});
     table.Description.Add(new ColumnPath() {ColumnName = "MassDolom", ColumnType = typeof (double)});
     table.Description.Add(new ColumnPath() {ColumnName = "UVSMassDolom", ColumnType = typeof (double)});
     table.Description.Add(new ColumnPath() {ColumnName = "MassFOM", ColumnType = typeof (double)});
     table.Description.Add(new ColumnPath() {ColumnName = "UVSMassFOM", ColumnType = typeof (double)});
     table.Description.Add(new ColumnPath() {ColumnName = "MassDolomS", ColumnType = typeof (double)});
 }
 public void LoadFromCSV(string file)
 {
     m_table = new Dictionary<string, Dictionary<string, double>>();
     var loader = new CSVTableParser();
     loader.Description = GetDescription();
     loader.FileName = file;
     loader.Separator = ';';
     loader.Load();
     foreach (var row in loader.Rows) {
         var himDic = new Dictionary<string, double>();
         foreach (var o in row.Cell) {
             if (o.Key != "MaterialName")
                 himDic.Add((string) o.Key, (double) o.Value);
         }
         m_table.Add((string) row.Cell["MaterialName"], himDic);
     }
 }
Ejemplo n.º 8
0
        private static void Init()
        {
            MainConf = System.Configuration.ConfigurationManager.OpenExeConfiguration("");
            var o = new HeatChangeEvent();
            MainGate = new Client(new Listener());
            MainGate.Subscribe();

            Separator = MainConf.AppSettings.Settings["separator"].Value.ToArray()[0];
            StorePath = MainConf.AppSettings.Settings["StorePath"].Value;
            ConverterNumber = Int32.Parse(MainConf.AppSettings.Settings["converterNumber"].Value);

            DefaultPattern = MainConf.AppSettings.Settings["DefPattrn"].Value;

            InitTbl = new CSVTableParser();

            TablePaths = ScanStore(StorePath);
            try {
                Tables = LoadTables(DefaultPattern, ref InitTbl);
                InstantLogger.msg("default pattern \"{0}\" loaded", DefaultPattern);
            }
            catch (Exception) {
                InstantLogger.err("can't load pattern \"{0}\",\nTry load pattern \"default\"", DefaultPattern);
                Tables = LoadTables("default", ref InitTbl);
            }

            if (Tables == null) InstantLogger.err("default pattern not loaded");

            CalcModeIsAutomatic = false;

            Saver = new DataSaver();

            IterateTimer.Elapsed += new ElapsedEventHandler(IterateTimeOut);
            IterateTimer.Enabled = true;

            Reset();

            //SaveTables("new", InitTbl, Tables);

            //////////////////////////////////
            //CSVTP_FlexEventConverter.AppName = "Charge5";
            //var tableFlex = CSVTP_FlexEventConverter.PackToFlex("newToFlex", InitTbl, Tables);
            //var name = "";
            //CSVTP_FlexEventConverter.UnpackFromFlex(tableFlex, ref InitTbl, ref Tables, ref name);
            //Console.WriteLine("Pare: {0}", name);
            //SaveTables("newFromFlex", InitTbl, Tables);
        }
Ejemplo n.º 9
0
        public static List<CSVTableParser> LoadTables(string name, ref CSVTableParser initbl)
        {
            var tables = new List<CSVTableParser>();
            //var initbl = new CSVTableParser();

            for (int i = 0; i < MaxTables; i++)
                tables.Add(new CSVTableParser());
            var isFound = false;
            foreach (var tablePath in TablePaths) {
                var tpsplt = tablePath.Split('\\');
                foreach (var s in tpsplt) {
                    if (s == name) {
                        var pathInit = String.Format("{0}\\{1}", tablePath, PIName);
                        if (File.Exists(pathInit)) {
                            isFound = true;
                            initbl.FileName = pathInit;
                            initbl.Separator = Separator;
                            Charge5Classes.Descriptions.SetDescriptionPI(ref initbl);
                            initbl.Load();
                        }
                    }
                }
                if (isFound) {
                    foreach (var row in initbl.Rows) {
                        var tb = new CSVTableParser {
                                                        FileName =
                                                            String.Format("{0}\\{1}.csv", tablePath,
                                                                          row.Cell["TableName"]),
                                                        Separator = Separator
                                                    };
                        Charge5Classes.Descriptions.SetDescriptionTBL(ref tb);
                        tb.Load();
                        tables[(int) row.Cell["Index"]] = tb;
                    }
                }
            }
            if (isFound)
                return tables;
            else
                return null;
        }
 public static void SetDescriptionPI(ref CSVTableParser table)
 {
     table.Description.Add(new ColumnPath() {ColumnName = "Index", ColumnType = typeof (int)});
     table.Description.Add(new ColumnPath() {ColumnName = "TableName", ColumnType = typeof (string)});
 }
 private CSVTableParser UpdateCsvtpFromTd(TableData tableData, CSVTableParser tableParser)
 {
     tableParser.Rows.RemoveRange(0, tableParser.Rows.Count);
     for (int index = 0; index < tableData.Rows.Count; index++) {
         var row = tableData.Rows[index];
         tableParser.Rows.Add(new Row());
         tableParser.Rows[index].Cell["MassDolom"] = row.MassDolom;
         tableParser.Rows[index].Cell["MassDolomS"] = row.MassDolomS;
         tableParser.Rows[index].Cell["MassFOM"] = row.MassFOM;
         tableParser.Rows[index].Cell["MassHotIron"] = row.MassHotIron;
         tableParser.Rows[index].Cell["MassLime"] = row.MassLime;
         tableParser.Rows[index].Cell["MassScrap"] = row.MassScrap;
         tableParser.Rows[index].Cell["MaxSiHotIron"] = row.MaxSiHotIron;
         tableParser.Rows[index].Cell["MaxTHotIron"] = row.MaxTHotIron;
         tableParser.Rows[index].Cell["MinSiHotIron"] = row.MinSiHotIron;
         tableParser.Rows[index].Cell["MinTHotIron"] = row.MinTHotIron;
         tableParser.Rows[index].Cell["UVSMassDolom"] = row.UVSMassDolom;
         tableParser.Rows[index].Cell["UVSMassFOM"] = row.UVSMassFOM;
     }
     return tableParser;
 }
 private TableData CsvtpToTD(CSVTableParser table)
 {
     var tableOut = new TableData();
     foreach (var row in table.Rows) {
         tableOut.Rows.Add(new TableRow() {
                                              MassDolom = (double) row.Cell["MassDolom"],
                                              MassDolomS = (double) row.Cell["MassDolomS"],
                                              MassFOM = (double) row.Cell["MassFOM"],
                                              MassHotIron = (double) row.Cell["MassHotIron"],
                                              MassLime = (double) row.Cell["MassLime"],
                                              MassScrap = (double) row.Cell["MassScrap"],
                                              MaxSiHotIron = (double) row.Cell["MaxSiHotIron"],
                                              MaxTHotIron = (double) row.Cell["MaxTHotIron"],
                                              MinSiHotIron = (double) row.Cell["MinSiHotIron"],
                                              MinTHotIron = (double) row.Cell["MinTHotIron"],
                                              UVSMassDolom = (double) row.Cell["UVSMassDolom"],
                                              UVSMassFOM = (double) row.Cell["UVSMassFOM"]
                                          });
     }
     return tableOut;
 }
Ejemplo n.º 13
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;
                }
            }
        }
Ejemplo n.º 14
0
        public static double CalcNewCarbon(CSVTableParser matrixC, Estimates data, int OxyAfterMetering)
        {
            using (var l = new Logger("CalcC")) {
                if (data.CurrentC == 0) return 0;

                foreach (var row in matrixC.Rows) {
                    if ((double) (row.Cell["CMin"]) <= data.CurrentC && data.CurrentC < (double) (row.Cell["CMax"])) {
                        l.msg("C item found --- CMin {0}; CMax {1}", row.Cell["CMin"], row.Cell["CMax"]);

                        var oxygenOnCarbon = (int) (row.Cell["OxygenOnCarbon"]);
                        return data.CurrentC - ((OxyAfterMetering/oxygenOnCarbon)*0.01);
                    }
                }
            }
            return 0;
        }
Ejemplo n.º 15
0
        public static int CalcT(CSVTableParser matrixT, Estimates data)
        {
            if (matrixT.Rows == null) {
                InstantLogger.err("matrixT.Rows == null");
                return 0;
            }
            using (var l = new Logger("CalcT")) {
                if ((data.CurrentT == 0)
                    || (data.TargetT == 0)
                    || (data.TargetTuMin == 0)
                    || (data.TargetTuMax == 0)
                    || (data.CurrentC == 0)
                    )
                    return 0;
                foreach (var row in matrixT.Rows) {
                    if ((double) (row.Cell["CMin"]) <= data.CurrentC && data.CurrentC < (double) (row.Cell["CMax"])) {
                        l.msg("T item found --- CMin {0}; CMax {1}", row.Cell["CMin"], row.Cell["CMax"]);

                        //var differenceT = data.TargetT - data.CurrentT;
                        double differenceT = (double)(((data.TargetT + (data.TargetT - data.TargetTuMin)) * 0.5) - data.CurrentT); // до середины между целевым и минимальным целевым
                        if (differenceT > 0)
                        {
                            var oxygenOnHeating = (int)(row.Cell["OxygenOnHeating"]);
                            var heating = (int)(row.Cell["Heating"]);
                            double correctionOxy = (double)((((double)oxygenOnHeating) / ((double)heating)) * differenceT);
                            l.msg("Correction Oxygen T = {0}", correctionOxy);
                            return (int)Math.Round(correctionOxy);
                        }
                        else {
                            l.msg("recomend end blow? code:-3");
                            return -3; // рекомендуется закончить продувку

                        }
                    }
                }
            }
            return 0;
        }
Ejemplo n.º 16
0
        private static void Init()
        {
            MatrixT = new CSVTableParser();
            MatrixC = new CSVTableParser();
            MainConf = System.Configuration.ConfigurationManager.OpenExeConfiguration("");

            CurrentScheme = Int32.Parse(MainConf.AppSettings.Settings["Scheme"].Value);

            Separator = MainConf.AppSettings.Settings["separator"].Value.ToArray()[0];
            MatrixT.FileName = MainConf.AppSettings.Settings["matrixT"].Value;
            MatrixT.Separator = Separator;

            var o = new FlexEvent();
            MainGate = new ConnectionProvider.Client(new Listener());
            MainGate.Subscribe();

            MatrixTDescription = new List<ColumnPath>();
            MatrixTDescription.Add(new ColumnPath() { ColumnName = "CMin", ColumnType = typeof(double) });
            MatrixTDescription.Add(new ColumnPath() { ColumnName = "CMax", ColumnType = typeof(double) });
            MatrixTDescription.Add(new ColumnPath() { ColumnName = "OxygenOnHeating", ColumnType = typeof(int) });
            MatrixTDescription.Add(new ColumnPath() { ColumnName = "Heating", ColumnType = typeof(int) });
            #if IS_DBFLEX
            ReqScheme(CurrentScheme);
            #else
            MatrixT.Description = MatrixTDescription;
            MatrixT.Load();
            #endif

            MatrixC.FileName = MainConf.AppSettings.Settings["matrixC"].Value;
            MatrixC.Separator = Separator;

            MatrixC.Description.Add(new ColumnPath() {ColumnName = "CMin", ColumnType = typeof (double)});
            MatrixC.Description.Add(new ColumnPath() {ColumnName = "CMax", ColumnType = typeof (double)});
            MatrixC.Description.Add(new ColumnPath() {ColumnName = "OxygenOnCarbon", ColumnType = typeof (int)});

            MatrixC.Load();

            WaitSublanceData = new Timer();
            WaitSublanceData.Elapsed += new ElapsedEventHandler(SublanceDataLost);

            CarbonIterateTimer.Elapsed += new ElapsedEventHandler(CarbonIterator);
            CarbonIterateTimer.Enabled = true;

            Reset();
        }
Ejemplo n.º 17
0
        public static CSVTableParser LoadMatrixTFromFlex(List<ColumnPath> description, FlexHelper fex)
        {
            var matrixT = new CSVTableParser();
            matrixT.Description = description;

            var cminLst = (List<double>)fex.GetComplexArg("CMIN", typeof(List<double>));
            var cmaxLst = (List<double>)fex.GetComplexArg("CMAX", typeof(List<double>));
            var oxygenLst = (List<double>)fex.GetComplexArg("OXYGEN", typeof(List<double>));
            var heatinLst = (List<double>)fex.GetComplexArg("HEATING", typeof(List<double>));

            for (int i = 0; i < fex.GetInt(Implements.DBFlex.ArgCountName); i++) {
                var row = matrixT.ColumnCreator();
                row.Cell["CMin"] = cminLst[i];
                row.Cell["CMax"] = cmaxLst[i];
                row.Cell["OxygenOnHeating"] = oxygenLst[i];
                row.Cell["Heating"] = heatinLst[i];
                matrixT.Rows.Add(row);
            }

            return matrixT;
        }