private void InterpolateCvY(double value) { var interpColumnName = CvYColumnConverter.NameFromValue(value); var interpTable = new TableProcessing.Table("Interpolate " + interpColumnName); interpTable.AddColumn(tables.OrdinKtgr.Column("PY")); var floorValue = double.NegativeInfinity; var ceilValue = double.PositiveInfinity; for (var i = 0; i < tables.OrdinKtgr.DataTable.Columns.Count; i++) { var column = tables.OrdinKtgr.DataTable.Columns[i]; if (column.ColumnName.IndexOf("CvY_", StringComparison.Ordinal) != 0) { continue; } var CV_value = CvYColumnConverter.ValueFromName(column.ColumnName); if (CV_value < value) { floorValue = CV_value; } else if (CV_value > value) { ceilValue = CV_value; break; } } var floorStr = CvYColumnConverter.NameFromValue(floorValue); var ceilStr = CvYColumnConverter.NameFromValue(ceilValue); interpTable.AddColumn(tables.OrdinKtgr.Column(floorStr)); var column_res = interpTable.Column(interpColumnName); interpTable.AddColumn(tables.OrdinKtgr.Column(ceilStr)); interpTable.IterateRows(row => { double[] x = { floorValue, ceilValue }; double[] y = { row[floorStr].DoubleValue, row[ceilStr].DoubleValue }; var res = LinearSpline.Interpolate(x, y).Interpolate(value); row.Set(column_res.Name, res); }, column_res.Name); tables.OrdinKtgr.AddColumn(interpTable.Column(interpColumnName)); }
private void AddCalcColumnsOrdinal(TableProcessing.Table table, int firstOrdinal, params string[] columns) { var ordinal = firstOrdinal; foreach (var columnName in columns) { table.AddColumn(tables.CalcsHydro.Column(columnName)); table.DataTable.Columns[columnName].SetOrdinal(ordinal); ordinal++; } }
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")); }