public static void CreatePiscesTree(string filename, PiscesFolder CurrentFolder, TimeSeries.TimeSeriesDatabase db) { var sqlite = new SQLiteServer(filename); /*insert into seriescatalog (id,parentid,name,isfolder) values (1,1,"database name",1); * insert into seriescatalog (id,parentid,name,units,tablename) * */ Logger.WriteLine("reading " + filename, "ui"); var variables = sqlite.Table("variables", "select a.var_name,b.value AS units from variables a " + "left join attributes b on a.var_name = b.var_name and b.attribute_name = 'units' order by a.var_name DESC"); Logger.WriteLine("variable count = " + variables.Rows.Count, "ui"); var sc = db.GetSeriesCatalog(); string rootFolderName = Path.GetFileNameWithoutExtension(filename); var rootID = sc.AddFolder(rootFolderName); var prev_FolderName = rootFolderName; int folderID = rootID; int id = sc.NextID(); var cs = ConnectionStringUtility.MakeFileNameRelative("FileName=" + filename + ";", db.DataSource); foreach (DataRow row in variables.Rows) { var var_name = row["var_name"].ToString(); if (var_name.IndexOf("_") > 0) { var tokens = var_name.Split('_'); if (tokens[0] != prev_FolderName) { folderID = sc.AddFolder(tokens[0], rootID); id++; prev_FolderName = tokens[0]; } } var newRow = sc.NewSeriesCatalogRow(); newRow.id = id++; newRow.ParentID = folderID; newRow.Provider = "SQLiteSeries"; newRow.ConnectionString = cs; newRow.IsFolder = false; newRow.TableName = var_name; newRow.Units = row["units"].ToString(); newRow.Name = var_name; newRow.Parameter = row["var_name"].ToString(); sc.AddSeriesCatalogRow(newRow); } db.Server.SaveTable(sc); }
public static Watershed Read(string watershedName, DateTime startTime, DateTime endTime, string fileName) { SQLiteServer server = GetServer(fileName); var rval = new Watershed(watershedName); var sql = "select * from " + TableName + " WHERE issue_date >= '" + startTime.ToString(DateTimeFormat) + "' " + " AND issue_date <= '" + endTime.ToString(DateTimeFormat) + "' " + " AND watershed = '" + watershedName + "' "; sql += " order by watershed,issue_date,location_name"; var table = server.Table(TableName, sql); if (table.Rows.Count == 0) { throw new Exception("no data"); } DateTime prevIssueDate = Convert.ToDateTime(table.Rows[0]["issue_date"]); DateTime currentDate = Convert.ToDateTime(table.Rows[0]["issue_date"]); float[,] values = null; foreach (DataRow row in table.Rows) { currentDate = Convert.ToDateTime(row["issue_date"]); var times = GetTimes(row); GetValues(row, ref values); rval.AddForecast(row["location_name"].ToString(), currentDate, values, times); } return(rval); }