private static void InsertMontanaSitesFromJsonToPisces(FeatureCollection collection, TimeSeriesDatabaseDataSet.sitecatalogDataTable sc) { // insert montana sites into pisces for (int i = 0; i < collection.Features.Count; i++) { Feature item = collection.Features[i]; if (item.Properties["title"].ToString().IndexOf(" MT ") < 0) { continue; } var rows = sc.Select("siteid = '" + item.Id.ToLower() + "'"); if (rows.Length == 0) // not in Pisces { Console.WriteLine(item.Id + " not found in Pisces"); // put it Pisces. var desc = item.Properties["title"].ToString(); var pt = item.Geometry as GeoJSON.Net.Geometry.Point; var pos = pt.Coordinates as GeoJSON.Net.Geometry.GeographicPosition; var lat = pos.Latitude.ToString(); var lo = pos.Longitude.ToString(); //sc.AddsitecatalogRow(item.Id.ToLower(), desc, "MT", lat, lo, "", "US/Mountain", "", "", "", 0, "usbr_map.json", "", "", "agrimet", "great_plains"); } } }
internal static bool IsAgrimetSite(string cbtt) { if (s_sites == null) { s_sites = s_db.GetSiteCatalog("type = 'agrimet'"); } return(s_sites.Select("siteid = '" + cbtt + "'").Length > 0); }
private static bool KeepThisSeries(TimeSeriesDatabaseDataSet.sitecatalogDataTable sitecatalog, string siteid, string pcode, string years) { HydrometMonthlySeries m = new HydrometMonthlySeries(siteid, pcode, HydrometHost.PN); var goodYears = Regex.IsMatch(years, "20[0-9]{2}"); var rows = sitecatalog.Select("siteid='" + siteid + "'"); if (rows.Length == 0 && m.Name != "") { //Console.WriteLine("siteid could be added to catalog:'"+siteid+"' "+m.Name); } return(rows.Length == 1 && goodYears); }
/// <summary> /// For each instant Series in the database create an appropriate /// Dailycalculation. /// </summary> public void AddDailyCalculations(DataTable pcodeLookup, bool dryRun, string[] sites) { var codes = new List <string>(); for (int i = 0; i < pcodeLookup.Rows.Count; i++) { var pc = pcodeLookup.Rows[i]["instantpcode"].ToString(); codes.Add(pc.ToLower()); } var filter = "select * from seriescatalog a join sitecatalog b on a.siteid=b.siteid " + "where timeinterval= 'Irregular' and b.type <> 'agrimet' "; filter += "and parameter in ( '" + String.Join("','", codes.ToArray()) + "')"; var q = new TimeSeriesDatabaseDataSet.SeriesCatalogDataTable(); m_db.Server.FillTable(q, filter); newCalcCount = 0; changeEqCount = 0; //foreach (var r in q) for (int j = 0; j < q.Rows.Count; j++) { var r = q[j]; try { if (sites.Length > 0 && Array.IndexOf(sites, r.siteid) == -1) { continue; } if (!HasCurrentData(r.TableName)) // don't add equations for 'old' data { Console.WriteLine("no current data. skipping .." + r.TableName); } else { var calcs = pcodeLookup.Select("InstantPcode ='" + r.Parameter + "'"); for (int i = 0; i < calcs.Length; i++) { var dailyPcode = calcs[i]["DailyPcode"].ToString().ToLower(); var siteFilter = calcs[i]["siteFilter"].ToString(); var expression = calcs[i]["Equation"].ToString(); expression = expression.Replace("%site%", r.siteid); var name = r.siteid + "_" + dailyPcode; TimeSeriesName tn = new TimeSeriesName(name, "daily"); if (m_sites.Select("siteid='" + r.siteid + "'").Length == 0) { Console.WriteLine("Warning: skipping site not cataloged: " + r.siteid); continue; } // remove property--> program:hydromet (prevents data flow from pnhyd0) if (!dryRun) { RemoveProgramProperty(tn); } if (!FilterAllows(r.siteid, siteFilter)) // config spreasheet limits i.e. responsibility='IDWR' { continue; } if (m_db.TableNameInUse(tn.GetTableName())) { // already defined in some manner. ConvertToDailyEquation(tn, expression, dryRun); } else { CalculationSeries s = CreateCalcSeries(r, name, tn, expression); newCalcCount++; if (!dryRun) { AddCalcSeries(s); } } // check if this equation matches Hydromet Legacy. if (!dryRun) { CompareWithVMS(tn); } } } } catch (Exception exc) { sw.WriteLine("Error:" + exc.Message); } if (j % 100 == 0) { Console.WriteLine(j + " of " + q.Count); } } sw.WriteLine("New equations: " + newCalcCount); sw.WriteLine("modified to Equations :" + this.changeEqCount); sw.Close(); }