public void AddBug() { DateTime t1 = new DateTime(2013, 1, 1); var t2 = t1.AddDays(365); var fn = FileUtility.GetTempFileNameInDirectory(@"c:\temp\", ".pdb"); SQLiteServer svr = new SQLiteServer(fn); TimeSeriesDatabase db = new Reclamation.TimeSeries.TimeSeriesDatabase(svr, false); var s = new HydrometDailySeries("pal", "af"); s.Name = "pal_af"; s.Read(t1, t2); db.AddSeries(s); var cs = new CalculationSeries("add_test"); cs.Expression = "pal_af + pal_af"; db.AddSeries(cs); cs = db.GetSeriesFromName("add_test") as CalculationSeries; cs.Calculate(t1, t2); cs = db.GetSeriesFromName("add_test") as CalculationSeries; cs.Read(); Assert.IsTrue(cs.Count > 0); }
/// <summary> /// Lookup hydromet Series. /// name is interval_cbtt_pcode /// </summary> /// <param name="name"></param> /// <returns></returns> public override ParserResult Lookup(string name, TimeInterval defaultInterval) { var interval = defaultInterval; TimeSeriesName tn = new TimeSeriesName(name); if( tn.HasInterval) { interval = tn.GetTimeInterval(); } if (tn.Valid) { Logger.WriteLine("Hydromet Lookup " + tn.siteid + "," + tn.pcode); var s = new Series(); if (interval == TimeInterval.Monthly) { s = new HydrometMonthlySeries(tn.siteid, tn.pcode,svr); } else if (interval == TimeInterval.Irregular) { s = new HydrometInstantSeries(tn.siteid, tn.pcode,svr); } else if (interval == TimeInterval.Daily) { s = new HydrometDailySeries(tn.siteid, tn.pcode,svr); } return new ParserResult(s); } else { return base.Lookup(name,interval); } }
private static void SaveToFile(System.Data.DataRow row, Series s, string dir) { var cbtt = row["cbtt"].ToString(); var pcode = row["pcode"].ToString(); var d = DateTime.Now.ToString("yyyyMMddHHmm"); var interval = row["interval"].ToString(); if (interval.ToLower() == "instant") { s.TimeInterval = TimeInterval.Irregular; var fn = Path.Combine(dir, "instant_ipco_" + cbtt + "_" + pcode + d + ".txt"); Console.WriteLine(fn); HydrometInstantSeries.WriteToHydrometFile(s, cbtt, pcode, "idahopower", fn); } else if (interval.ToLower() == "daily") { s.TimeInterval = TimeInterval.Daily; var fn = Path.Combine(dir, "daily_ipco_" + cbtt + "_" + pcode + d + ".txt"); Console.WriteLine(fn); HydrometDailySeries.WriteToArcImportFile(s, cbtt, pcode, fn); } }
private static double MultiYearAvg(DateTime t, DateTime t1, DateTime t2) { var s = HydrometDailySeries.GetMultiYearAverage("sys", "af", HydrometHost.Yakima, t1, t2); int y = 2001; if (t.Month >= 10) { y = 2000; } DateTime t2000 = new DateTime(y, t.Month, t.Day); int idx = s.IndexOf(t2000.Date); if (idx >= 0 && !s[idx].IsMissing) { var af = HydrometDailySeries.Read("sys", "af", t, t, HydrometHost.Yakima); af.RemoveMissing(); if (af.Count == 1) { var x = s[idx].Value; x = af[0].Value / x * 100.0; return(x); } } return(Reclamation.TimeSeries.Point.MissingValueFlag); }
/// <summary> /// Routes a list of Series as a group /// hydromet cbtt is copied from list[i].SiteName /// hydromet pcode is copied from list[i].Parameter /// </summary> /// <param name="list"></param> /// <param name="route"></param> /// <param name="name">identity used as part of filename </param> public static void RouteDaily(SeriesList list, string name, RouteOptions route = RouteOptions.Both) { if (list.Count == 0) { return; } string fileName = ""; if (route == RouteOptions.Both || route == RouteOptions.Outgoing) { fileName = GetOutgoingFileName("daily", name, "all"); Console.WriteLine("saving daily outgoing to:" + fileName); HydrometDailySeries.WriteToArcImportFile(list, fileName); } if (route == RouteOptions.Both || route == RouteOptions.Incoming) { foreach (var s in list) { fileName = GetIncommingFileName("daily", s.SiteID, s.Parameter); Console.WriteLine("saving daily incoming to:" + fileName); s.WriteCsv(fileName, true); } } }
private void AddStatistics(SeriesList wyList) { bool anyStats = checkBoxMax.Checked || checkBoxMin.Checked || checkBoxAvg.Checked; if (!anyStats) { return; } int y1 = 1990; int y2 = 2011; int.TryParse(this.textBoxWY1.Text, out y1); int.TryParse(this.textBoxWY2.Text, out y2); DateTime t1 = new DateTime(y1 - 1, 10, 1); DateTime t2 = new DateTime(y2, 9, 30); var server = HydrometInfoUtility.HydrometServerFromPreferences(); Series s = new HydrometDailySeries(comboBoxCbtt.Text.Trim(), DeterminePcode(), server); s.Read(t1, t2); s.RemoveMissing(); s.Appearance.LegendText = ""; YearRange yr = new YearRange(2000, 10); var list = Math.SummaryHydrograph(s, new int[] { }, yr.DateTime1, checkBoxMax.Checked, checkBoxMin.Checked, checkBoxAvg.Checked, false); //, false); wyList.Add(list); }
private static SeriesList ReadHydrometOptionalData(int wy, string query, DateRange range) { SeriesList rval = new SeriesList(); string[] tokens = query.Split(','); foreach (var pair in tokens) { var s = pair.TrimStart().TrimEnd(); string cbtt = s.Split(' ')[0]; string pcode = s.Split(' ')[1]; Series hm = new HydrometDailySeries(cbtt, pcode); hm.Name = Convert.ToString(wy) + " " + cbtt.ToUpper() + " " + pcode.ToUpper(); DateTime t1 = range.DateTime1; DateTime t2 = range.DateTime2; hm.Read(t1, t2); hm.RemoveMissing(); if (hm.Count > 0) { rval.Add(hm); } } return(rval); }
private void WriteListToFile(SeriesList list, string name, TimeInterval interval, string route) { var tmpFileName = FileUtility.GetTempFileName(".txt"); File.Delete(tmpFileName); Logger.WriteLine("writing " + list.Count + " series "); Logger.WriteLine("temp file:" + tmpFileName); if (interval == TimeInterval.Daily) { SeriesList exportList = new SeriesList(); foreach (var s in list) { exportList.Add(s); } HydrometDailySeries.WriteToArcImportFile(exportList, tmpFileName); } if (interval == TimeInterval.Irregular) { foreach (var s in list) { HydrometInstantSeries.WriteToHydrometFile(s, s.SiteID, s.Parameter, Environment.UserName, tmpFileName, true); } } if (File.Exists(tmpFileName)) { Logger.WriteLine("Moving: " + tmpFileName); string fn = interval == TimeInterval.Daily ? "daily" : "instant"; var fileName = GetOutgoingFileName(fn, name, "all", route); Logger.WriteLine("To: " + fileName); File.Move(tmpFileName, fileName); } }
/// <summary> /// prints csv table in this format. /// DateTime,current year, previous, average /// 10/1/2017, 123.34, 69.0, 77.7 /// 10/2/2017, 120.0, 67.0, 77.3 /// </summary> private void PrintAnalysis(TimeRange r, string siteID, string parameter) { Console.Write("Content-type: text/csv\n\n"); var years = new List <int>(); var current = DateTime.Now.Date.WaterYear(); var prev = current - 1; years.Add(current); years.Add(prev); DateTime startOf30YearAvearge = HydrometDataUtility.T1Thirty; var x = new SeriesList(); Series s = new HydrometDailySeries(siteID, parameter, HydrometHost.PNLinux); x.Add(s); var result = PiscesAnalysis.WaterYears(x, years.ToArray(), true, 10, true, startOf30YearAvearge); var tbl = result.ToDataTable(true); // Console.WriteLine("<pre/>"); Console.WriteLine("DateTime,Current Year,Previous Year,Average"); for (int i = 0; i < tbl.Rows.Count; i++) { var o = tbl.Rows[i]; var str = ((DateTime)o[0]).ToString("yyyy/MM/dd"); Console.WriteLine(str + "," + o[1].ToString() + "," + o[2].ToString() + "," + o[3].ToString()); } }
public void ManageSeriesCatalogDirectly() { Logger.EnableLogger(); var filename = @"c:\temp\test.pdb"; if (File.Exists(filename)) { File.Delete(filename); } Console.WriteLine(filename); var server = new SQLiteServer(filename); var db = new TimeSeriesDatabase(server, false); var seriesCatalog = db.GetSeriesCatalog(); var siteCatalog = db.GetSiteCatalog(); // create a folder for each month for (int i = 1; i <= 12; i++) { var t = new DateTime(2015, i, 1); seriesCatalog.GetOrCreateFolder("Months", t.ToString("MMMM")); } // Add USGS series (Boise River) to the January Folder Series s = new UsgsDailyValueSeries("13206000", UsgsDailyParameter.DailyMeanDischarge); s.SiteID = "usgs_13206000"; var januaryIndex = seriesCatalog.GetOrCreateFolder("Months", "January"); seriesCatalog.AddSeriesCatalogRow(s, seriesCatalog.NextID(), januaryIndex, "usgs_boiseriver_flow"); // Add Hydromet series to the February Folder s = new HydrometDailySeries("bhr", "af", HydrometHost.GreatPlains); s.Name = "gphyd_bhr_af"; s.SiteID = "gphyd_bhr"; var feb = seriesCatalog.GetOrCreateFolder("Months", "February"); seriesCatalog.AddSeriesCatalogRow(s, seriesCatalog.NextID(), feb, "usgs_boiseriver_flow"); // Add Site information siteCatalog.AddsitecatalogRow("usgs_13206000", "BOISE RIVER AT GLENWOOD BRIDGE NR BOISE ID", "ID"); siteCatalog.AddsitecatalogRow("gphyd_bhr", "Big Horn Reservoir", "MT"); server.SaveTable(seriesCatalog); s = db.GetSeriesFromName("gphyd_bhr_af"); s.Read(); Console.WriteLine(s.Count); // Add CSV file db.Inventory(); }
/// <summary> /// Creates Summary Crop Water Use Charts /// </summary> /// <param name="cbtt"></param> /// <param name="t"></param> /// <returns></returns> private static List <string> CreateSummaryReport(string cbtt, DateTime t, CropDatesDataSet.CropDatesRow[] cropRow) { var rval = new List <string>(); //var cropRow = CropDatesDataSet.GetCropFiles(t.Year, cbtt); var et = new HydrometDailySeries(cbtt, "ETRS"); //var et = new KimberlyPenmanEtSeries(cbtt); // Below is the calculation to determine how many days to read back. Set to calculate based on ETr Start Date. var etStartDate = cropRow[0].startdate.DayOfYear; var etTodayDate = t.DayOfYear; int numDaysRead = etTodayDate - etStartDate; et.Read(t.AddDays(-numDaysRead), t.AddDays(-1)); // Produces Summary Chart heading. rval.Add(" " + " " + cbtt + " - " + "ET SUMMARY" + " - " + t.ToString("yyyy") + " "); string s1 = " DATE "; string s2 = " "; string s5 = " ----"; for (int i = 0; i < cropRow.Length; i++) { var row = cropRow[i]; s1 = s1 + row.cropname.PadRight(5); //s2 = s2 + " " + row.UIDX.ToString("F0").PadLeft(3) + " "; s2 = s2 + " " + "".PadLeft(3) + " "; s5 = s5 + " " + "----"; } rval.Add(s2); rval.Add(s1); rval.Add(s5 + " "); // Populates Summary Chart by generating strings of ET values. string dateString = " "; for (int dateIndex = 1; dateIndex < numDaysRead; dateIndex++) { var t1 = et[dateIndex].DateTime; dateString = " " + t1.ToString("MM/dd").PadLeft(4); string valueString = ""; for (int cropIndex = 0; cropIndex < cropRow.Length; cropIndex++) { var row = cropRow[cropIndex]; var etValue = CropCurves.WaterUse(t1, et[dateIndex].Value, row); if (t1 < cropRow[cropIndex].startdate || t1 > cropRow[cropIndex].terminatedate) { valueString += " -- "; } else { valueString += etValue.ToString("F2").PadLeft(5); } } rval.Add(dateString + valueString); } return(rval); }
public void JacksonLakeDaily() { var s = new HydrometDailySeries("jck", "qd"); s.Read(new DateTime(2007, 10, 1), new DateTime(2007, 10, 5)); Assert.IsTrue(s.Count == 5); Assert.AreEqual(1910.0, s["2007-10-1"].Value); }
public void GPBuffaloBillReservoirDaily() { var s = new HydrometDailySeries("bbr", "af",HydrometHost.GreatPlains); s.Read(new DateTime(2007, 10, 1), new DateTime(2007, 10, 5)); Assert.IsTrue(s.Count == 5); Assert.AreEqual(415879, s["2007-10-1"].Value,.01); }
/// <summary> /// read computed value from hydromet and compare.. /// /// </summary> /// <param name="s"></param> private void CompareToHydromet(CalculationSeries s) { if (s.Count == 0) { return; } // TO DO.. also check instant calcs. TimeSeriesName n = new TimeSeriesName(s.Table.TableName); if (s.TimeInterval == TimeInterval.Daily) { var tmp = HydrometDailySeries.Cache; HydrometDailySeries.Cache = null; // don't use cache.. HydrometDailySeries h = new HydrometDailySeries(n.siteid, n.pcode); HydrometDailySeries.Cache = tmp; h.Read(s.MinDateTime, s.MaxDateTime); Series diff = Reclamation.TimeSeries.Math.Abs(h - s); var pt = Reclamation.TimeSeries.Math.MaxPoint(diff); double tolerance = 0.1; if (Array.IndexOf(new string[] { "sr", "wr" }, n.pcode) >= 0) { tolerance = 1.0; } double delta = h[0].Value - s[0].Value; double pctError = 0; if (System.Math.Abs(delta) > 0) { pctError = System.Math.Abs(delta / h[0].Value); } if (pctError > tolerance) { if (debugFileName == "") { debugFileName = "calc_errors.csv"; if (File.Exists(debugFileName)) { File.Delete(debugFileName); } File.AppendAllText(debugFileName, "site,pcode,interval,openvms,linux,delta,percentError" + "\n"); } if (h[0].Value != Point.MissingValueFlag) { string msg = n.siteid + "," + n.pcode + "," + n.interval + "," + h[0].Value + ", " + s[0].Value + ", " + delta + ", " + pctError; Console.WriteLine(msg); File.AppendAllText(debugFileName, msg + "\n"); } } } else { throw new NotImplementedException(); } }
public void JacksonLakeDaily() { var s = new HydrometDailySeries("jck", "qd"); s.Read(new DateTime(2007, 10, 1), new DateTime(2007, 10, 5)); Assert.IsTrue(s.Count == 5); Assert.AreEqual(1910.0, s["2007-10-1"].Value); }
public void GPBuffaloBillReservoirDaily() { var s = new HydrometDailySeries("bbr", "af", HydrometHost.GreatPlains); s.Read(new DateTime(2007, 10, 1), new DateTime(2007, 10, 5)); Assert.IsTrue(s.Count == 5); Assert.AreEqual(415879, s["2007-10-1"].Value, .01); }
static HydrometDailySeries GetDailySeries(string cbtt, string pcode, DateTime t, int hours_back) { var s = new HydrometDailySeries(cbtt, pcode, Utility.GetHydrometServer()); var t2 = t.Date; //.AddDays(-1); // hydromet daily data begins yesterday var t1 = t2.AddHours(-hours_back).Date; s.Read(t1, t2); return(s); }
public void JacksonLakeDaily() { var s = new HydrometDailySeries("jck", "qd"); s.Read(new DateTime(2007, 10, 1), new DateTime(2007, 10, 5)); Assert.IsTrue(s.Count == 5, " expected 5 points in jck_qu. number fount=" + s.Count); Assert.AreEqual(1910.0, s["2007-10-1"].Value); }
public void AddSeriesDirectly() { Logger.EnableLogger(); var filename = FileUtility.GetTempFileNameInDirectory(@"c:\temp\", ".pdb"); if (File.Exists(filename)) { File.Delete(filename); } Console.WriteLine(filename); var server = new SQLiteServer(filename); var db = new TimeSeriesDatabase(server); // create a folder for each month for (int i = 1; i <= 12; i++) { var t = new DateTime(2015, i, 1); db.AddFolder("Months", t.ToString("MMMM")); } // Add USGS series (Boise River) to the January Folder Series s = new UsgsDailyValueSeries("13206000", UsgsDailyParameter.DailyMeanDischarge); s.SiteID = "13206000"; var folder = db.GetOrCreateFolder("Months", "January"); s.Read(DateTime.Parse("2015-01-01"), DateTime.Parse("2015-01-10")); db.AddSeries(s, folder); // Add Hydromet series to the February Folder s = new HydrometDailySeries("bhr", "af", HydrometHost.GreatPlains); s.Name = "gphyd_bhr_af"; s.SiteID = "gphyd_bhr"; var feb = db.GetOrCreateFolder("Months", "February"); db.AddSeries(s, feb); // Add Csv file data to March Folder. s = new TextSeries(@"c:\temp\test_river.csv"); s.Read();// read data. Use Read(t1,t2) to limit by dates s.SiteID = "test"; s.Units = "cfs"; s.Table.TableName = "test_river"; // table name needs to be unique db.AddSeries(s, db.GetOrCreateFolder("Months", "March")); s = db.GetSeriesFromName("gphyd_bhr_af"); s.Read(); Console.WriteLine(s.Count); // Add CSV file db.Inventory(); }
private void buttonRefresh_Click(object sender, EventArgs e) { try { labelStatus.Text = "Reading"; Cursor = Cursors.WaitCursor; Sync(); Application.DoEvents(); DateTime t1 = this.timeSelectorBeginEnd1.T1; DateTime t2 = this.timeSelectorBeginEnd1.T2; ReadExternalData(t1, t2); labelStatus.Text = "found " + externalSeries.Count + " records in " + GetSourceType().ToString(); Application.DoEvents(); HydrometHost svr = HydrometInfoUtility.HydrometServerFromPreferences(); hmet = new HydrometDailySeries(textBoxcbtt.Text.Trim(), textBoxPcode.Text.Trim(), svr); hmet.Read(t1, t2); int hmetCount = hmet.Count - hmet.CountMissing(); labelStatus.Text += " and " + hmetCount + " records in hydromet"; Application.DoEvents(); SeriesList list = new SeriesList(); list.Add(externalSeries); list.Add(hmet); this.teeChartExplorerView1.SeriesList = list; //this.timeSeriesGraph1.Series = list; this.teeChartExplorerView1.Draw(); //this.timeSeriesGraph1.Draw(true); Series diff = hmet - externalSeries; SeriesList list2 = new SeriesList(); list2.Add(diff); timeSeriesGraph2.Series = list2; timeSeriesGraph2.Draw(true); } catch (Exception ex) { MessageBox.Show(ex.Message + " \n" + ex.StackTrace); } finally { Cursor = Cursors.Default; } }
public Series FetchDailyFromAPI(string site, string pcode, DateTime start, DateTime end) { // TODO: Add caching Series s = new Series("", TimeInterval.Daily); s.Table = HydrometDailySeries.Read(site, pcode, start, end, HydrometHost.PNLinux).Table; s.Table.TableName = "daily_" + site + "_" + pcode; s.Name = s.Table.TableName; return(s); }
static bool s_appendToFile = false; // for output file. private static void WriteToHydrometDailyFile(string dailyFileName, CalculationSeries s) { TimeSeriesName n = new TimeSeriesName(s.Table.TableName); HydrometDailySeries.WriteToArcImportFile(s, n.siteid, n.pcode, dailyFileName, s_appendToFile); if (!s_appendToFile) { s_appendToFile = true; // append after the first time. } }
internal static SystemState DetermineSystemState(DateTime t) { if (t.Date == DateTime.Now.Date) { t = t.Date.AddDays(-1); // we dont' have daily value yet for today (use yesterday) } t = t.Date; // state is daily but we could be running previous day at 9:55 am var dir = GetPathToMinimumFlowFiles(); // read avearge contents for three reservoirs var avg = new TextSeries(Path.Combine(dir, "talsys_afavg.csv")); avg.Read(); var talsys_avg = new PeriodicSeries(avg.Table); var t1 = t.Date.AddDays(-1); // current last two days system contents var hmet = new HydrometDailySeries("talsys", "af"); hmet.Read(t1, t); // determine state. Point talsys = hmet[t]; if (talsys.IsMissing) { talsys = hmet[t.AddDays(-1).Date]; // try back one day } if (talsys.IsMissing) { return(SystemState.Unknown); } if (t.Month == 2 && t.Day == 29)// don't lookup 29th in periodic table { t = t.AddDays(-1); } double avg_af = talsys_avg.Interpolate(t); if (talsys.Value >= avg_af + 15000) { return(SystemState.Wet); } if (talsys.Value <= avg_af - 15000) { return(SystemState.Dry); } return(SystemState.Median); }
static Series AverageSeries30Year() { var t1 = HydrometDataUtility.T1Thirty; var t2 = HydrometDataUtility.T2Thirty; Series qu = new HydrometDailySeries("wodi", "qu"); qu.Read(t1, t2); qu = Math.MonthlySum(qu) * 0.00198347; var qua = MonthlySummaryAnalysis.MonthlySeries(qu, StatisticalMethods.Mean, false); return(qua); }
private static Series Get30YearAverageSeries(string cbtt, string pcode, int forecastMonth) { var t1 = HydrometDataUtility.T1Thirty; var t2 = HydrometDataUtility.T2Thirty; var s2 = new HydrometDailySeries(cbtt, pcode, HydrometHost.PNLinux); s2.Read(t1, t2); DateTime t = new DateTime(2018, forecastMonth, 1); var list = Math.SummaryHydrograph(s2, new int[] { }, t, false, false, true, false); return(list[0]); }
static void Main(string[] args) { // compare daily data in linux server with vms var items = File.ReadAllLines("list.txt"); /* * daily_bsei_qj * daily_bppi_qj * daily_bouy_pp */ for (int i = 0; i < items.Length; i++) { var tokens = items[i].Split('_'); if (tokens.Length != 3) { Console.WriteLine("Error: " + items[i] + " not valid"); } string cbtt = tokens[1]; string p = tokens[2]; string tag = cbtt + " " + p; DateTime t1 = DateTime.Now.AddDays(-2).Date; DateTime t2 = t1; HydrometDailySeries hyd = new HydrometDailySeries(cbtt, p); hyd.Read(t1, t2); hyd.RemoveMissing(); HydrometDailySeries lrgs = new HydrometDailySeries(cbtt, p, HydrometHost.PNLinux); lrgs.Read(t1, t2); lrgs.RemoveMissing(); if (hyd.Count != lrgs.Count) { Console.WriteLine(tag + ": hyd.Count = " + hyd.Count + " linux.count =" + lrgs.Count); } else if (hyd.Count == 1 && lrgs.Count == 1) {// take difference var diff = hyd[0].Value - lrgs[0].Value; if (Math.Abs(diff) > 0.3) { Console.WriteLine(i + "," + tag + ", " + hyd[0].Value.ToString("F2") + ", " + lrgs[0].Value.ToString("F2") + ", " + diff.ToString("F2")); } } } }
public static void Import(Series s, string siteID, string parameter, string fileExtension = "txt") { if (s.TimeInterval == TimeInterval.Daily) { var fn = TimeSeriesTransfer.GetIncommingFileName("daily", siteID, parameter, fileExtension); HydrometDailySeries.WriteToArcImportFile(s, siteID, parameter, fn); } if (s.TimeInterval == TimeInterval.Irregular || s.TimeInterval == TimeInterval.Hourly) { var fn = TimeSeriesTransfer.GetIncommingFileName("instant", siteID, parameter, fileExtension); HydrometInstantSeries.WriteToHydrometFile(s, siteID, parameter, Environment.UserName, fn); } }
public void ReadAndShift() { // nov 14, 1999, 250 cfs // nov 15, 1999 249 cfs Series s = new HydrometDailySeries("bigi", "qd"); DateTime t = DateTime.Parse("1999-11-15"); int offset = -1; s = SeriesExpressionParser.ReadAndShiftData(-offset, s, t, t); Assert.AreEqual(1, s.Count); Assert.AreEqual(250, s[0].Value); Assert.AreEqual(15, s[0].DateTime.Day); }
private static void GPAverage(string cbtt, HydrometHost server, MonthDayRange range, SeriesList wyList) { var se_avg = new HydrometDailySeries(cbtt, "se_avg", server); var sl2 = new SeriesList(); sl2.Add(se_avg); var list1 = PiscesAnalysis.WaterYears(sl2, new int[] { 2002 }, false, range.Month1, true); if (list1.Count == 1) { var se = list1[0]; se.Appearance.LegendText = "SE_AVG"; wyList.Add(se); } }
private static double ReadHydrometValue(string cbtt, string pcode, DateTime date, HydrometHost server) { //Get hydromet data HydrometDailySeries s = new HydrometDailySeries(cbtt, pcode, server); s.Read(date, date); double value = 998877; if (s.Count > 0 && !s[0].IsMissing) { value = s[0].Value; } return(value); }
public void Shift() { // nov 14, 1999, 250 cfs // nov 15, 1999 249 cfs Series s = new HydrometDailySeries("bigi", "qd"); DateTime t = DateTime.Parse("1999-11-15"); s.Read(t, t); Assert.AreEqual(1, s.Count); s = Reclamation.TimeSeries.Math.Shift(s, 1); Assert.AreEqual(249, s[0].Value); Assert.AreEqual(16, s[0].DateTime.Day); }
/// <summary> /// .A WSRI1 20080326 M DH2400/QRDRG 2788.91 /// .A ARKI1 20080322 M DH2400/QRDRG 3063.14 /// .A ARKI1 20080323 M DH2400/QRDRG 3051.89 /// </summary> private static void WriteDaily(DateTime t1, DateTime t2, StreamWriter sw, string cbtt, string pcode, string shefName, string shefPcode, string timeZone) { //HydrometDailySeries.UseInternet = true; Series s = HydrometDailySeries.Read(cbtt, pcode, t1, t2, HydrometHost.PNLinux); s.RemoveMissing(); for (int j = 0; j < s.Count; j++) { sw.WriteLine(".A " + shefName + " " + s[j].DateTime.ToString("yyyyMMdd") + " " + timeZone + " " + "DH2400/" + shefPcode + " " + s[j].Value.ToString("F2")); } System.Threading.Thread.Sleep(2000); }
private void AddStatistics(SeriesList wyList) { bool anyStats = checkBoxMax.Checked || checkBoxMin.Checked || checkBoxAvg.Checked || checkBoxPctls.Checked; if (!anyStats) { return; } int y1 = 1990; int y2 = 2011; int[] pctls = new int[] { }; int.TryParse(this.textBoxWY1.Text, out y1); int.TryParse(this.textBoxWY2.Text, out y2); if (checkBoxPctls.Checked) { try { string values = textBoxPctls.Text; string[] tokens = values.Split(','); pctls = Array.ConvertAll <string, int>(tokens, int.Parse); } catch { pctls = new int[] { 10, 50, 90 }; } } DateTime t1 = new DateTime(y1 - 1, 10, 1); DateTime t2 = new DateTime(y2, 9, 30); var server = HydrometInfoUtility.HydrometServerFromPreferences(); Series s = new HydrometDailySeries(comboBoxCbtt.Text.Trim(), DeterminePcode(), server); s.Read(t1, t2); s.RemoveMissing(); s.Appearance.LegendText = ""; YearRange yr = new YearRange(2000, 10); var list = Math.SummaryHydrograph(s, pctls, yr.DateTime1, checkBoxMax.Checked, checkBoxMin.Checked, checkBoxAvg.Checked, false); //, false); wyList.Add(list); }
public static void BasicDatabaseTest(TimeSeriesDatabase db) { Assert.IsTrue(db.GetSeriesCatalog().Rows.Count ==1 , " initial catalog should have root"); Reclamation.TimeSeries.Hydromet.HydrometInfoUtility.AutoUpdate = true; DateTime t2 = DateTime.Now.Date.AddDays(-10); DateTime t1 = DateTime.Now.Date.AddDays(-30); Series s = new HydrometDailySeries("jck", "af"); int id = db.AddSeries(s); s = db.GetSeries(id); s.Read(t1, t2); s.WriteToConsole(); Assert.AreEqual(21, s.Count); s.Read(t1, DateTime.Now.Date.AddDays(-9)); //force auto update.(HydrometDaily supports this) // check if auto update worked. Assert.AreEqual(22, s.Count); Assert.AreEqual(2, db.GetSeriesCatalog().Rows.Count, "Catalog row count"); var por = s.GetPeriodOfRecord(); Assert.AreEqual(22, por.Count,"period of record"); }
internal void Run() { Console.Write("Content-type: text/html\n\n"); if (query == "") { query = HydrometWebUtility.GetQuery(); } var collection = HttpUtility.ParseQueryString(query); TimeRange r = GetDateRange(collection); var siteID = ""; if (collection.AllKeys.Contains("site")) { siteID = collection["site"]; } var parameter = ""; if (collection.AllKeys.Contains("parameter")) { parameter = collection["parameter"]; } var s = new HydrometDailySeries(siteID, parameter, HydrometHost.PNLinux); var startYear = r.StartDate.Year; var endYear = r.EndDate.Year; DateTime t1 = r.StartDate; for (int i = startYear; i < endYear; i++) { s.Read(t1, t1.AddMonths(12)); DataTable wyTable = Usgs.WaterYearTable(s); var header = GetHeader(i + 1, siteID,parameter); var html = DataTableOutput.ToHTML(wyTable, true, "",header); Console.WriteLine(html); t1 = t1.AddMonths(12); } }
public void AddBug() { DateTime t1 = new DateTime(2013,1,1); var t2 = t1.AddDays(365); var fn = FileUtility.GetTempFileNameInDirectory(@"c:\temp\",".pdb"); SQLiteServer svr = new SQLiteServer(fn); TimeSeriesDatabase db = new Reclamation.TimeSeries.TimeSeriesDatabase(svr,false); var s = new HydrometDailySeries("pal","af"); s.Name = "pal_af"; s.Read(t1,t2); db.AddSeries(s); var cs = new CalculationSeries("add_test"); cs.Expression = "pal_af + pal_af"; db.AddSeries(cs); cs = db.GetSeriesFromName("add_test") as CalculationSeries; cs.Calculate(t1, t2); cs = db.GetSeriesFromName("add_test") as CalculationSeries; cs.Read(); Assert.IsTrue(cs.Count > 0); }
private void ReadFromHydromet() { //DateTime t1 = startDate.AddDays(minOffset); // usually negative.. SeriesList list = new SeriesList(); for (int i = 0; i < cbtt.Length; i++) { HydrometDailySeries s = new HydrometDailySeries(cbtt[i], pcode[i], this.server); DateTime t1 = startDate.AddDays(daysOffset[i]); DateTime t2 = t1.AddDays(dayCount[i] - 1); if (!hasCount[i]) { t2 = endDate; } if (dayCount[i] < 1 && hasCount[i]) { Console.WriteLine("Warning: The number of days requested was " + dayCount[i] + "from hydromet"); } s.Read(t1, t2); if (s.Count < dayCount[i] && hasCount[0]) { Console.WriteLine("Warning: the requested hydromet data is missing."); } list.Add(s); } //Reclamation.PNHydromet.HydrometDaily.BulkRead(cbtt, pcode, t1, startDate, false,server); //FormPrevew p = new FormPrevew(list); //p.ShowDialog(); WriteToRiverwareFiles(list); }
public void ShefA() { var s = new HydrometDailySeries("LUC", "QU"); DateTime t1 = new DateTime(2012, 10, 27); DateTime t2 = new DateTime(2012, 10, 27); s.Read(t1, t2); var fn = FileUtility.GetTempFileName(".csv"); File.AppendAllText(fn,"cbtt,pcode,shef_locid,shef_tag,time_zone,scale\n" +"LUC,QU,LUCI1,QADRZ,M,0.001"); var txt = HydrometDailySeries.CreateSHEFA(fn, t1, t2); Assert.AreEqual(".A LUCI1 20121027 M DH2400/QADRZ 0.802", txt[0]); }
/// <summary> /// Compute/estimate smaller diversions above parker. /// This is done using factors that vary with time /// and Daily data for WESW QJ, and NSCW QJ. /// </summary> /// <param name="t1"></param> /// <returns></returns> private static double ComputeOthersAboveParker(DateTime t) { HydrometDailySeries wesw = new HydrometDailySeries("wesw", "qj", HydrometHost.Yakima); HydrometDailySeries nscw = new HydrometDailySeries("nscw", "qj", HydrometHost.Yakima); DateTime t1 = t.Date; wesw.Read(t1, t1); nscw.Read(t1, t1); wesw.RemoveMissing(); nscw.RemoveMissing(); if( wesw.Count ==0 || nscw.Count == 0) { Logger.WriteLine("Missing data. Check wesw, nscw"); return Point.MissingValueFlag; } var rval = GetValue(t1, wesw[0].Value, nscw[0].Value); return rval; }