private void buttonRecomputeCoeficients_Click(object sender, EventArgs e) { // Performance perf = new Performance(); string fn = FileUtility.GetTempFileName(".csv"); xls.SaveSheetToCsv(xls.ActiveSheetName, fn); xls.Save(); // must save to get back to *.xls from *.csv eq = new ForecastEquation(fn); var cache = new HydrometDataCache(); cache.Add(eq.GetCbttPcodeList().ToArray(), new DateTime(eq.StartYear - 1, 10, 1), new DateTime(eq.EndYear, 9, 30)); HydrometMonthlySeries.Cache = cache; var dir = Path.GetDirectoryName(this.textBoxExcelFileName.Text); try { Cursor = Cursors.WaitCursor; Application.DoEvents(); R = new CoefficientCalculator(); var newCoefficients = R.ComputeCoefficients(eq, Path.GetDirectoryName(Application.ExecutablePath)); var dlg = new RegressionResults(); dlg.CompareToHistoryClicked += new EventHandler <EventArgs>(dlg_CompareToHistoryClicked); dlg.Output = R.Output; dlg.DataFile = R.dataFile; dlg.CoeficientsExisting = CoefficientCalculator.FormatCoefficients(eq.coefficients); dlg.CoefficientsComputed = CoefficientCalculator.FormatCoefficients(newCoefficients); if (dlg.ShowDialog() == DialogResult.OK) // save { // save back to excel. xls.UpdateCoeficients(xls.ActiveSheetName, newCoefficients); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Cursor = Cursors.Default; } }
static void Main(string[] args) { if (args.Length != 5 && args.Length != 2) { Console.WriteLine("HydrometForecast.exe basin.csv date level look-ahead output"); Console.WriteLine("Where: "); Console.WriteLine(" basin.csv -- name of csv input file"); Console.WriteLine(" date -- date to run forecaset 2017-01-01"); Console.WriteLine(" level -- subsequent conditions 1.0 normal 0.8 for 80%, etc... "); Console.WriteLine(" look-ahead -- perfect forecast 0 or 1"); Console.WriteLine(" output -- filename for output"); Console.WriteLine("Example: HydrometForecast heise.csv 2016-1-1 1.0 0 output.txt"); Console.WriteLine("HydrometForecast.exe basin.csv output.csv"); return; } var filename = args[0]; ForecastEquation eq = new ForecastEquation(filename); if (args.Length == 2) { var cache = new HydrometDataCache(); cache.Add(eq.GetCbttPcodeList().ToArray(), new DateTime(eq.StartYear - 1, 10, 1), new DateTime(eq.EndYear, 9, 30)); HydrometMonthlySeries.Cache = cache; var tbl = eq.ComputeHistoricalCoefficients(eq.StartYear, eq.EndYear); CsvFile.WriteToCSV(tbl, args[1], false); } else { DateTime t = DateTime.Parse(args[1]); double level = double.Parse(args[2]); int lookAhead = int.Parse(args[3]); string outputFileName = args[4]; ForecastResult result = eq.Evaluate(t, lookAhead == 1, level); File.WriteAllLines(outputFileName, result.Details.ToArray()); } }