static void Main(string[] args) { Logger.EnableLogger(true); try { string fileName = GetFileName(args); HydrometInfoUtility.SetDefaultHydrometServer(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.ThreadExit += new EventHandler(Application_ThreadExit); Application.ApplicationExit += new EventHandler(Application_ApplicationExit); piscesForm1 = new PiscesForm(fileName); piscesForm1.FormClosed += new FormClosedEventHandler(explorerForm1_FormClosed); Application.Run(piscesForm1); PostgreSQL.ClearAllPools(); FileUtility.CleanTempPath(); } catch (Exception exc) { MessageBox.Show(exc.ToString()); } }
private void ReadSettings() { var svr = HydrometInfoUtility.HydrometServerFromPreferences(); // retiring PN if (svr == HydrometHost.PNLinux || svr == HydrometHost.PN) { this.radioButtonBoiseLinux.Checked = true; } else if (svr == HydrometHost.Yakima) { this.radioButtonYakHydromet.Checked = true; } else if (svr == HydrometHost.GreatPlains) { this.radioButtonGP.Checked = true; } else if (svr == HydrometHost.LocalSource) { radioButtonLocal.Checked = true; } this.textBoxDbName.Text = UserPreference.Lookup("TimeSeriesDatabaseName", "timeseries"); }
private static void LoadDailyUsbrCatalog(TimeSeriesDatabaseDataSet.SeriesCatalogDataTable sc, TimeSeriesDatabaseDataSet.SeriesCatalogDataTable sc_vm, string program) { for (int i = 0; i < sc.Rows.Count; i++) { if (i == 55) { return; } var row = sc[i]; string[] path = { "water.usbr.gov", "pn", program, row.siteid, "daily" }; var folderID = sc_vm.GetOrCreateFolder(path); TimeSeriesName tn = new TimeSeriesName(row.TableName); var newRow = sc_vm.NewSeriesCatalogRow(); newRow.ItemArray = row.ItemArray; newRow.id = sc_vm.NextID(); newRow.iconname = ""; newRow.Provider = "HydrometDailySeries"; newRow.ConnectionString = "server=PN;cbtt=" + tn.siteid + ";pcode=" + tn.pcode + ";"; newRow.TableName = "pnhydromet_" + row.TableName; newRow.Units = HydrometInfoUtility.LookupDailyUnits(tn.pcode); newRow.Parameter = HydrometInfoUtility.LookupDailyParameterName(tn.pcode); newRow.ParentID = folderID; sc_vm.Rows.Add(newRow); } }
public RatingTableSelector() { InitializeComponent(); DataTable tbl = new DataTable(); var svr = HydrometInfoUtility.HydrometServerFromPreferences(); if (svr == HydrometHost.GreatPlains) { string fn = Path.Combine("gp", "ratingtables.csv"); fn = FileUtility.GetFileReference(fn); tbl = new CsvFile(fn); var c = tbl.Columns.Add("name"); c.DefaultValue = ""; } else { tbl = WebTable(); } dataGridView1.DataSource = tbl; dataGridView1.ReadOnly = true; dataGridView1.AllowUserToAddRows = false; buttonOk.Enabled = false; }
private void SelectTable() { hydrometRatingTable = new TimeSeriesDatabaseDataSet.RatingTableDataTable(); var f = new RatingTableSelector(); if (f.ShowDialog() == DialogResult.OK) { cbtt = f.cbtt; yparm = f.pcode; this.labelSiteName.Text = "Description: " + HydrometInfoUtility.LookupSiteDescription(cbtt); this.labelcbtt.Text = "cbtt: " + cbtt; string altid = HydrometInfoUtility.LookupAltID(cbtt).Trim(); if (altid.Length > 0) { labelcbtt.Text += " altid: " + altid; } this.labelyparm.Text = "y parameter: " + yparm; ReadTableFromInternet(cbtt, yparm, f.RatingName, altid); hydrometRatingTable.Name = f.RatingName + " -- " + HydrometInfoUtility.LookupSiteDescription(cbtt); hydrometRatingTable.EditDate = f.DateModified; this.labelDate.Text = "Modified " + f.DateModified; } }
public FormMain() { var host = HydrometInfoUtility.HydrometServerFromPreferences(); if (host == HydrometHost.PN) { UserPreference.SetDefault("HydrometServer", HydrometHost.PNLinux.ToString(), false); } HydrometInfoUtility.SetDefaultHydrometServer(); UserPreference.SetDefault("HideStatusDialog", "False", false); UserPreference.SetDefault("AutoFlagDayFiles", "True", false); InitializeComponent(); this.Text += " " + Application.ProductVersion; // FileUtility.CleanTempPath(); Application.EnableVisualStyles(); TabPageManager tabManager = new TabPageManager(tabControl1); Logger.OnLogEvent += new StatusEventHandler(Logger_OnLogEvent); UpdateTabs(); //MakeMinimalVersion(); this.Text = "Hydromet/Agrimet Tools V" + Application.ProductVersion; }
public void Reset() { if (DesignMode) { return; } var t = DateTime.Now; int wy = t.Year; if (t.Month >= 10) { wy++; } this.textBoxWaterYear.Text = wy.ToString(); var t2 = t.AddMonths(1); this.monthRangePicker1.MonthDayRange = new MonthDayRange(10, 1, 9, 30); // load QU locations this.comboBoxSite.Items.Clear(); HydrometServer = HydrometInfoUtility.HydrometServerFromPreferences(); if (HydrometInfoUtility.HydrometServerFromPreferences() == HydrometHost.GreatPlains) { this.comboBoxSite.Items.AddRange(FcPlotDataSet.GetNames("GP")); } else { this.comboBoxSite.Items.AddRange(FcPlotDataSet.GetNames("PN")); } checkBoxDashed.Visible = false; }
private string GetHeaderTitle(out string subTitle) { subTitle = ""; var query = HydrometInfoUtility.ExpandQuery(this.comboBoxInputs.Text, TimeInterval.Daily); // single cbtt? var tokens = query.Split(','); var cbttList = new List <string>(); foreach (var item in tokens) { string s = item.Trim().Split(' ')[0]; if (!cbttList.Contains(s)) { cbttList.Add(s); } } if (cbttList.Count == 1) { subTitle = HydrometInfoUtility.LookupGroupDescription(cbttList[0]); return(HydrometInfoUtility.LookupSiteDescription(cbttList[0])); } return(""); }
void Reset() { var t = DateTime.Now; int wy = t.Year; if (t.Month >= 10) { wy++; } this.yearSelector1.SelectedYears = new Int32[] { wy--, wy }; var t2 = t.AddMonths(1); if (t.Month == 9) { this.monthRangePicker1.MonthDayRange = new MonthDayRange(10, 1, 9, 30); } else { this.monthRangePicker1.MonthDayRange = new MonthDayRange(10, 1, t2.Month, DateTime.DaysInMonth(t2.Year, t2.Month)); } //this.comboBoxPcode.SelectedIndex = 0; this.checkBoxGP.Visible = HydrometInfoUtility.HydrometServerFromPreferences() == HydrometHost.GreatPlains; this.checkBoxMpoll.Visible = HydrometInfoUtility.HydrometServerFromPreferences() != HydrometHost.GreatPlains; if (this.checkBoxMpoll.Visible) { this.checkBoxGP.Checked = false; } if (this.checkBoxGP.Visible) { this.checkBoxMpoll.Checked = false; } }
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 void linkLabelRead_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { HydrometHost svr = HydrometInfoUtility.HydrometServerFromPreferences(); int yr; if (!int.TryParse(textBoxWaterYear.Text, out yr)) { MessageBox.Show("Error parsing water year '" + textBoxWaterYear.Text + "'"); return; } if (comboBoxSiteList.SelectedIndex < 0) { return; } DateTime t1 = new DateTime(yr - 1, 10, 1); DateTime t2 = new DateTime(yr, 9, 30); int idx = this.comboBoxSiteList.SelectedIndex; string siteId = comboBoxSiteList.SelectedValue.ToString(); string query = siteId + " " + siteListTable.Rows[idx]["parameters"].ToString(); hydrometDataTable = HydrometDataUtility.ArchiveTable(svr, query, t1, t2); hydrometDataTable.AcceptChanges(); bool ctrl = (Control.ModifierKeys & Keys.Control) != 0; timeSeriesSpreadsheet1.Clear(); timeSeriesSpreadsheet1.SetDataTable(hydrometDataTable, Reclamation.TimeSeries.TimeInterval.Daily, ctrl); ReadSeries(); hydrometDataTable.RowChanged += hydrometDataTable_RowChanged; }
void AddHydrometClick(object sender, System.EventArgs e) { ImportHydromet dlg = new ImportHydromet(); if (dlg.ShowDialog() == DialogResult.OK) { UserPreference.SetDefault("HydrometServer", dlg.HydrometServer.ToString(), true); string msg = ""; try { ShowAsBusy("connecting to hydromet"); Series s = HydrometInfoUtility.Read(dlg.Cbtt, dlg.ParameterCode, dlg.T1, dlg.T2, dlg.TimeInterval, dlg.HydrometServer); if (s.Count == 0) { msg = "Error: Could not find any Hydromet Data"; } else { msg = "read " + s.Count + " records"; if (dlg.UseSimpleName) { s.Name = dlg.Cbtt + " " + dlg.ParameterCode; } DB.AddSeries(s, CurrentFolder); } } finally { ShowAsReady(msg); } } }
void Reset() { var t = DateTime.Now; int wy = t.Year; if (t.Month >= 10) { wy++; } this.yearSelector1.SelectedYears = new Int32[] { wy--, wy }; var t2 = t.AddMonths(1); //if (t.Month == 9) //{ // this.monthRangePicker1.MonthDayRange = new MonthDayRange(10, 1, 9, 30); //} //else //{ // this.monthRangePicker1.MonthDayRange = new MonthDayRange(10, 1, t2.Month, DateTime.DaysInMonth(t2.Year, t2.Month)); //} this.monthRangePicker1.MonthDayRange = new MonthDayRange(10, 1, 9, 30); this.textBoxWY1.Text = HydrometDataUtility.T1Thirty.Year.ToString(); this.textBoxWY2.Text = HydrometDataUtility.T2Thirty.Year.ToString(); //this.comboBoxPcode.SelectedIndex = 0; this.checkBoxGP.Visible = HydrometInfoUtility.HydrometServerFromPreferences() == HydrometHost.GreatPlains; }
public void SiteDescription() { Logger.EnableLogger(); string d = HydrometInfoUtility.LookupSiteDescription("AFTY"); Console.WriteLine(d); Assert.AreEqual("Afton Wyoming Weather Station", d); }
public static HydrometHost GetHydrometServer() { string s = ConfigurationManager.AppSettings["HydrometServer"]; var rval = HydrometInfoUtility.HydrometServerFromString(s); return(rval); }
public void SiteDescription() { Logger.EnableLogger(); string d = HydrometInfoUtility.LookupSiteDescription("ACAO"); Console.WriteLine(d); Assert.AreEqual("Ashland Creek Mouth, near Ashland", d); }
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; } }
private void buttonDownloadQuality_Click(object sender, EventArgs e) { string cbtt = this.textBoxCbttQuality.Text.Trim(); /// TO get nessdi var nessid = HydrometInfoUtility.LookupNessid(cbtt); //var nessid = "34748654"; var tbl = GoesMessageDataSet.GetEDDNMessages(nessid, textBoxHoursBack.Text); dataGridViewQuality.DataSource = tbl; }
public void HydrometRatingTable() { //var rt = new TimeSeriesDatabaseDataSet.RatingTableDataTable(); // rt.ReadFromFile(Path.Combine(TestData.DataPath,"rating"); var rt = HydrometInfoUtility.GetRatingTable("gcl", "af"); //TimeSeriesDatabaseDataSet.RatingTableDataTable. var x = rt.Lookup(1281.95); Assert.AreEqual(4543763, x, .01); //var s = new HydrometInstantSeries("gcl", "fb"); //TestRatingTable }
private void Init() { SaveToVMS = UserPreference.Lookup("SaveToVMS") == "True"; ComputeDependencies = UserPreference.Lookup("ComputeDependencies") == "True"; if (m_interval == TimeInterval.Monthly) { checkBoxDependencies.Enabled = false; checkBoxDependencies.Checked = false; } HydrometHost svr = HydrometInfoUtility.HydrometServerFromPreferences(); this.checkBoxSaveVMS.Enabled = !(svr == HydrometHost.PNLinux || svr == HydrometHost.YakimaLinux); }
private void comboBoxSite_DropDown(object sender, EventArgs e) { HydrometServer = HydrometInfoUtility.HydrometServerFromPreferences(); this.comboBoxSite.Items.Clear(); // load QU locations if (HydrometInfoUtility.HydrometServerFromPreferences() == HydrometHost.GreatPlains) { this.comboBoxSite.Items.AddRange(FcPlotDataSet.GetNames("GP")); } else { this.comboBoxSite.Items.AddRange(FcPlotDataSet.GetNames("PN")); } }
public void DayFileWebQuery() { DateTime t1 = new DateTime(2004, 1, 1); DateTime t2 = new DateTime(2004, 1, 2); Series s = HydrometInfoUtility.Read("jck", "af", t1, t2, TimeInterval.Irregular, HydrometHost.PNLinux); s.WriteToConsole(); Assert.AreEqual(192, s.Count, "number of records read"); // 143482.03 DateTime t = DateTime.Parse("01/01/2004 15:15"); Assert.AreEqual(143482.03, s.Lookup(t), 0.01, "value on jan 1, 2005 15:15"); }
private DataTable WebTable() { DataTable rval = new DataTable(); rval.Columns.Add("Site"); rval.Columns.Add("Yparm"); rval.Columns.Add("name"); rval.Columns.Add("date_modified"); string rt = HydrometInfoUtility.GetRatingTableURL(); if (rt == "") { return(rval); } var data = Web.GetPage(rt); /* <a href="acao.csv">acao.csv</a> */ // "<tr><td valign=\"top\"><img src=\"/icons/text.gif\" alt=\"[TXT]\"></td><td><a href=\"acao_shift.csv\">acao_shift.csv</a> </td><td align=\"right\">2016-01-15 07:02 </td><td align=\"right\">1.9K</td><td> </td></tr>" Regex re = new Regex( "<a href=\\\".*\\\">(?<name>.*\\.(csv|txt))</a>\\s*</td><td a" + "lign=\\\"right\\\">(?<date_modified>[\\-0-9\\s\\:]*)", RegexOptions.Multiline | RegexOptions.CultureInvariant | RegexOptions.Compiled ); for (int i = 0; i < data.Length; i++) { if (re.IsMatch(data[i])) { var m = re.Match(data[i]); string n = m.Groups["name"].Value; var tokens = n.Split('_'); var cbtt = tokens[0]; //var pcode = "q"; //if (tokens.Length == 2) // pcode = tokens[1]; //if (pcode == "shift") // continue; var date_modified = m.Groups["date_modified"].Value; rval.Rows.Add(cbtt, "", n, date_modified); } } return(rval); }
private void buttonSave_Click(object sender, EventArgs e) { if (externalSeries == null || hmet == null) { MessageBox.Show("can not save. please try loading data"); return; } string cbtt = textBoxcbtt.Text.Trim().ToUpper(); string pcode = textBoxPcode.Text.Trim().ToUpper(); string fileName = FileUtility.GetTempFileName(".txt"); //"update" + DateTime.Now.ToString("yyyyMMMdd") + ".txt"; int counter = WriteArchivesImportFile(cbtt, pcode, fileName, GetSourceType()); labelStatus.Text = "Saved " + counter + " records to file " + fileName; Application.DoEvents(); if (counter == 0) { return; } Login login = new Login(); bool admin = Login.AdminPasswordIsValid(); if (!admin) { MessageBox.Show("You must enter the administrator password in the setup tab for this feature to work"); } HydrometHost svr = HydrometInfoUtility.HydrometServerFromPreferences(); if (svr == HydrometHost.GreatPlains && admin && login.ShowDialog() == DialogResult.OK) { SaveToVMS(fileName, login); } else if (admin) { SaveToLinux(fileName); } }
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); }
private void SetupUsgsLink() { this.linkLabelUsgs.Visible = false; usgsUrl = ""; if (dataTable != null && dataTable.Columns.Count > 1 && dataTable.Rows.Count > 0) { string cbtt = this.comboBoxInputs.Text.Trim().Split(' ')[0]; // check for USGS id.. string altId = HydrometInfoUtility.LookupAltID(cbtt); if (altId.Trim().Length > 0 && Regex.IsMatch(altId, "[0-9]{7,10}")) { linkLabelUsgs.Text = "usgs " + altId; usgsUrl = "http://waterdata.usgs.gov/nwis/uv?format=html&period=7&site_no=" + altId; linkLabelUsgs.Visible = true; } } }
private void buttonGo_Click(object sender, EventArgs e) { Cursor = Cursors.WaitCursor; Application.DoEvents(); try { HydrometHost svr = HydrometInfoUtility.HydrometServerFromPreferences(); int yr = 2000; if (multi.cbtt.Trim() != "") { var s = HydrometDailySeries.GetMultiYearAverage(multi.cbtt, multi.pcode, svr, multi.T1, multi.T2); var list = new SeriesList(); list.Add(s); view.SeriesList = list; view.Draw(); Application.DoEvents(); // comparison period if (compare.cbtt.Trim() != "") { var s2 = HydrometDailySeries.GetMultiYearAverage(compare.cbtt, compare.pcode, svr, compare.T1, compare.T2); list.Add(s2); } if (textBoxCompareSingleYear.Text.Trim() != "" && textBoxSingleYearCbtt.Text.Trim() != "" && int.TryParse(this.textBoxCompareSingleYear.Text, out yr)) { yr = Convert.ToInt32(textBoxCompareSingleYear.Text); DateTime t1 = new DateTime(yr - 1, 10, 1); DateTime t2 = new DateTime(yr, 9, 30); Series s3 = HydrometDailySeries.Read(textBoxSingleYearCbtt.Text, textBoxSingleYearPcode.Text, t1, t2, svr); s3 = Reclamation.TimeSeries.Math.ShiftToYear(s3, 2000); s3.Appearance.LegendText = yr.ToString(); list.Add(s3); } view.SeriesList = list; view.Draw(); } } finally { Cursor = Cursors.Default; } }
private string LookupUnits(string pcode) { if (m_db == TimeInterval.Daily) { return(HydrometInfoUtility.LookupDailyUnits(pcode)); } if (m_db == TimeInterval.Irregular) { return(HydrometInfoUtility.LookupDayfileUnits(pcode)); } if (m_db == TimeInterval.Monthly) { return(HydrometMonthlySeries.LookupUnits(pcode)); } return(""); }
private static void LoadUpperSnakeHydromet(TimeSeriesDatabaseDataSet.SeriesCatalogDataTable sc_vm) { // load hydromet/upper snake var lines = upperSnakeDaily.Split('\n'); foreach (var item in lines) { var tokens = item.Trim().Split(' ', '\t'); var cbtt = tokens[0].Trim().ToLower(); var pcode = tokens[1].Trim().ToLower(); string[] path = { "water.usbr.gov", "pn", "hydromet", cbtt, "daily" }; var folderID = sc_vm.GetOrCreateFolder(path); HydrometDailySeries s = new HydrometDailySeries(cbtt, pcode); s.SiteID = cbtt; s.Parameter = HydrometInfoUtility.LookupDailyParameterName(pcode); sc_vm.AddSeriesCatalogRow(s, sc_vm.NextID(), folderID, "pnhydromet_" + s.Table.TableName); } }
private void SaveToLinux(string filename) { HydrometHost svr = HydrometInfoUtility.HydrometServerFromPreferences(); if (svr == HydrometHost.PNLinux) { // saving to Postgresql/Linux if (Database.IsPasswordBlank()) { updateStatus("Warning: the database password is blank.", true); return; } SaveOptions o = new SaveOptions(TimeInterval.Daily); if (o.ShowDialog() == DialogResult.OK) { Logger.WriteLine("Pisces import: " + filename, "ui"); Database.ImportVMSTextFile(filename, o.ComputeDependencies); } } }