Beispiel #1
0
        private void Calc_DSm()
        {
            var dateAverage = new DateAverage(dateParser);

            var valuesColumnName = "DSm_Values";
            var resultColumnName = "DSm";


            tables.CalcsHydro.IterateRows(row =>
            {
                var intList = row["OI_METEO"].ToIntList();

                var datesQuery = from meteoRow in meteoRows
                                 where intList.Contains(meteoRow["OI_Meteo"].IntValue)
                                 select meteoRow["DSm"].StringValue;

                var datesArray = datesQuery
                                 .Where(item => item != "")
                                 .ToArray();

                var values = string.Join(";", datesArray);

                row.Set(valuesColumnName, values);

                Etc.NoThrow(() =>
                {
                    var dayMonthAverage = dateAverage.CalcFor(datesArray);
                    var dayMonthRounded = dateAverage.RoundDayMonth(dayMonthAverage, 5);
                    row.Set(resultColumnName, dayMonthRounded);
                });
            }, valuesColumnName, resultColumnName);
        }
Beispiel #2
0
        public static void CalcMeteoAvg(List <Row> meteoRows, string meteoColumnName,
                                        TableProcessing.Table calcsHydroTable, string hydroColumnName,
                                        ICellMapper cellMapper, params TableProcessing.Table[] resultTables)
        {
            var valuesColumnName = meteoColumnName + "_Values";


            calcsHydroTable.IterateRows(hydroRow =>
            {
                var intList = hydroRow["OI_METEO"].ToIntList();

                double number = 0;

                var realMeteoColumnName = meteoColumnName;

                if (meteoColumnName.StartsWith("&"))
                {
                    var hydroPtr        = meteoColumnName.Substring(1);
                    realMeteoColumnName = hydroRow[hydroPtr].StringValue;
                }

                Etc.NoThrow(() =>
                {
                    var doubleQuery = from meteoRow in meteoRows
                                      where intList.Contains(meteoRow["OI_Meteo"].IntValue) &&
                                      double.TryParse(
                        meteoRow[realMeteoColumnName].StringValue, out number)
                                      select number;

                    var enumerable = doubleQuery.ToList();

                    var strQuery = from dbl in enumerable
                                   select cellMapper.Map(new Cell(dbl)).StringValue;

                    var res = string.Join(";", strQuery.ToArray());

                    hydroRow.Set(valuesColumnName, res);

                    hydroRow.Set(hydroColumnName,
                                 enumerable.Average(), cellMapper);
                });
            }, valuesColumnName, hydroColumnName);

            foreach (var table in resultTables)
            {
                table.AddColumn(calcsHydroTable.Column(hydroColumnName));
            }
        }
        private void Calc_LR()
        {
            if (calcBranch.DSm)
            {
                tables.CalcsMeteo.AddColumn(
                    tables.OperInfoMeteo.Column("Lm"));

                tables.CalcsMeteo.IterateRows(row =>
                {
                    var dt       = GetDate(row["Lm"]);
                    var dayMonth = dateParser.ToDayMonth(dt, "_");

                    Etc.NoThrow(() =>
                    {
                        var columnName_L = DayAndMonthItemsRepr
                                           .DD_MM_to_LDD_MM(dayMonth);

                        row.Set("L_Column", columnName_L);
                    });
                }, "L_Column");

                var operRows = tables.OperInfoMeteo.GetRows();

                tables.CalcsMeteo.IterateRows(calcRow =>
                {
                    Etc.NoThrow(() =>
                    {
                        var colName = calcRow["L_Column"].StringValue;
                        var operRow = operRows[calcRow.Index];
                        calcRow.Set("LR", operRow[colName]);
                    });
                }, "LR");
            }
            else
            {
                var DD_MM = userInput[CalculationsForm.Arg_DayAndMonth];

                Etc.NoThrow(() =>
                {
                    var columnName_L = DayAndMonthItemsRepr.DD_MM_to_LDD_MM(DD_MM);

                    var column_oper_L = tables.OperInfoMeteo.Column(columnName_L);

                    tables.CalcsMeteo.Column("LR").SetDataFrom(column_oper_L);
                });
            }
        }
Beispiel #4
0
        private void HRm_Finder(string val_OI_Hydro, double val_QRm)
        {
            var dt = postGroups[val_OI_Hydro];

            var closestRowN  = 0;
            var closestColN  = 0;
            var closestValue = 0.0;
            var closestDiff  = double.PositiveInfinity;

            for (var colN = 0; colN < dt.Columns.Count; colN++)
            {
                if (!NumberColumns.Contains(dt.Columns[colN].ColumnName))
                {
                    continue;
                }

                for (var rowN = 0; rowN < dt.Rows.Count; rowN++)
                {
                    Etc.NoThrow(() =>
                    {
                        var value = new Cell(dt.Rows[rowN][colN]).DoubleValue;
                        var diff  = Math.Abs(value - val_QRm);

                        if (diff < closestDiff)
                        {
                            closestRowN  = rowN;
                            closestColN  = colN;
                            closestValue = value;
                            closestDiff  = diff;
                        }
                    });
                }
            }

            var colNumber = new Cell(dt.Rows[closestRowN]["H"]).IntValue;
            var rowNumber = new Cell(dt.Columns[closestColN].ColumnName).IntValue;

            calcMemory["HRm"]       = colNumber + rowNumber;
            calcMemory["QRm_Posts"] = closestValue;
        }
Beispiel #5
0
        private void Calc_PY()
        {
            var interpTable = new TableProcessing.Table("Інтерполяція PY");

            tables.AddCustomTable(interpTable);

            interpTable.AddColumn("PY");
            interpTable.AddRow("0,001");
            interpTable.AddRow("0,01");
            interpTable.AddRow("0,03");
            interpTable.AddRow("0,05");
            interpTable.AddRow("0,1");
            interpTable.AddRow("0,3");
            interpTable.AddRow("0,5");

            for (var i = 1; i <= 99; i++)
            {
                interpTable.AddRow(i);
            }

            tables.CalcsHydro.IterateRows(row =>
            {
                var kY             = row["kY"].DoubleValue;
                var CvY_columnName = row["CvY_Column"].StringValue;

                if (CvY_columnName.IndexOf("CvY_", StringComparison.Ordinal) != 0)
                {
                    return;
                }

                if (!tables.OrdinKtgr.DataTable.Columns.Contains(CvY_columnName))
                {
                    var value_CvY = CvYColumnConverter.ValueFromName(CvY_columnName);
                    InterpolateCvY(value_CvY);
                }

                var PY_cells  = tables.OrdinKtgr.Column("PY").GetCells();
                var CvY_cells = tables.OrdinKtgr.Column(CvY_columnName).GetCells();

                var x = new List <double>();
                var y = new List <double>();

                for (var i = 0; i < PY_cells.Count; i++)
                {
                    Etc.NoThrow(() =>
                    {
                        var xValue = PY_cells[i].DoubleValue;
                        var yValue = CvY_cells[i].DoubleValue;

                        x.Add(xValue);
                        y.Add(yValue);
                    });
                }

                Etc.NoThrow(() =>
                {
                    var spline = LinearSpline.Interpolate(x, y);

                    interpTable.IterateRows(row2 =>
                    {
                        row2.Set(CvY_columnName,
                                 spline.Interpolate(row2["PY"].DoubleValue));
                    }, CvY_columnName);
                });

                var PY = Find_PY(interpTable, kY, CvY_columnName);
                row.Set("PY", PY);
            }, "PY");

            tables.Result.AddColumn(tables.CalcsHydro.Column("PY"));
        }