private ForecastTerm CreateTerm(TextFile tf, int idx) { var s = tf[idx].Split(',')[1].Trim(); ForecastTerm rval = null; if (s == "Antecedent Runoff") { rval = new AntecedentRunoffForecastTerm(); } else if (s == "Precipitation") { rval = new PrecipitationForecastTerm(); } else if (s == "Snow") { rval = new SnowForecastTerm(); } else if (s == "Runoff") { rval = new RunoffForecastTerm(); } else { throw new NotImplementedException(); } rval.Number = Convert.ToInt32(tf[idx].Split(',')[0].Substring(1, 1));// X1, Y1, X2... return(rval); }
public DataTable ComputeHistoricalCoefficients(int year1, int year2) { DataTable tbl = new DataTable(Name); //Logger.EnableLogger(); tbl.Columns.Add("Year"); int previousTerm = -1; for (int i = 0; i < XTerms.Count; i++) { if (XTerms[i].Number != previousTerm) // grouped terms { tbl.Columns.Add("X" + XTerms[i].Number, typeof(double)); previousTerm = XTerms[i].Number; } } tbl.Columns.Add("Y1"); int month = ForecastTerm.GetMonthFromString(YTerm.MonthNames[YTerm.MonthNames.Count - 1]); int year = 0; try { for (year = year1; year <= year2; year++) { var row = tbl.NewRow(); row["Year"] = year; DateTime t = new DateTime(year, month, 1); previousTerm = -1; double sum = 0; for (int x = 0; x < XTerms.Count; x++) { var term = XTerms[x]; var d = term.Evaluate(t, true, 1.0); if (previousTerm == term.Number) { sum += d; } else { sum = d; } row["X" + term.Number] = sum; previousTerm = term.Number; } row["Y1"] = YTerm.SeasonalRunoff(t); //.Evaluate(t,true,1.0); tbl.Rows.Add(row); } //CsvFile.WriteToCSV(tbl, @"C:\temp\andcoeff.csv"); } catch (Exception ex1) { throw new Exception("Issue on year " + year + " \n" + ex1.Message); } return(tbl); }