private double Compare(int startYear, int endYear, UnitType source, int id, string var) { string col_sqlite = var.Trim(); string col_text = ExtractSWAT_SQLite.ColumnSQLite2Text(source, var).Trim(); DataTable dtSQLite = _extractSQLite.Extract(startYear, endYear, source, id, col_sqlite); DataTable dtText = _extractText.Extract(startYear, endYear, source, id, col_text); if (dtSQLite == null || dtText == null) { return(-99.0); } if (dtSQLite.Rows.Count == 0 || dtText.Rows.Count == 0) { return(-99.0); } //Console.WriteLine(string.Format("Extract time for {0}-{1}-{2}-{3}-{4}: SQLite = {5:F4} ms, Text = {6:F4} ms", // startYear, endYear, source, id, var, _extractSQLite.ExtractTime,_extractText.ExtractTime)); //the join table structure DataTable dt = new DataTable(); dt.Columns.Add("TIME", typeof(DateTime)); dt.Columns.Add("SQLite", typeof(double)); dt.Columns.Add("Text", typeof(double)); //join these two tables using Linq var results = from table1 in dtSQLite.AsEnumerable() join table2 in dtText.AsEnumerable() on table1["TIME"] equals table2["TIME"] select dt.LoadDataRow(new object[] { table1["TIME"], table1[col_sqlite], table2[col_text] }, false); results.CopyToDataTable(); return(CalculateR2(dt, "SQLite", "Text", "")); }
/// <summary> /// Extract data from regular text file as datatable /// </summary> static void TestExtractFromText_SWATPlot(string txtinoutPath) { Console.WriteLine("******************** Text SWATPlot ********************"); ExtractSWAT_Text_SWATPlot extract = new ExtractSWAT_Text_SWATPlot(txtinoutPath); Console.WriteLine("******************** First Try ********************"); extract.Extract(UnitType.RCH, 1, "FLOW_OUTcms");//case sensitive extract.Extract(1993, UnitType.RCH, 1, "FLOW_OUTcms"); extract.Extract(2000, UnitType.RCH, 1, "FLOW_OUTcms"); extract.Extract(2007, UnitType.RCH, 1, "FLOW_OUTcms"); extract.Extract(UnitType.HRU, 1, "ETmm"); extract.Extract(1993, UnitType.HRU, 1, "ETmm"); extract.Extract(2000, UnitType.HRU, 1, "ETmm"); extract.Extract(2007, UnitType.HRU, 1, "ETmm"); Console.WriteLine("******************** Second Try ********************"); extract.Extract(UnitType.RCH, 1, "FLOW_OUTcms");//case sensitive extract.Extract(1993, UnitType.RCH, 1, "FLOW_OUTcms"); extract.Extract(2000, UnitType.RCH, 1, "FLOW_OUTcms"); extract.Extract(2007, UnitType.RCH, 1, "FLOW_OUTcms"); extract.Extract(UnitType.HRU, 1, "ETmm"); extract.Extract(1993, UnitType.HRU, 1, "ETmm"); extract.Extract(2000, UnitType.HRU, 1, "ETmm"); extract.Extract(2007, UnitType.HRU, 1, "ETmm"); }