Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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();
        }
Ejemplo n.º 6
0
        /// <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);
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
        /// <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();
            }
        }
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 11
0
        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);
        }
Ejemplo n.º 12
0
        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);
        }
Ejemplo n.º 13
0
        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);
        }
Ejemplo n.º 14
0
        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;
            }
        }
Ejemplo n.º 15
0
        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);
        }
Ejemplo n.º 16
0
        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);
        }
Ejemplo n.º 17
0
        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]);
        }
Ejemplo n.º 18
0
        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);
        }
Ejemplo n.º 19
0
        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");
        }
Ejemplo n.º 20
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"));
                    }
                }
            }
        }
Ejemplo n.º 21
0
//        [Test, Category("DatabaseServer")]
//        public void TestSqlServer()
//        {
//            /*
//             * C:\>sqlcmd -S .\SQLEXPRESS
//> create login [bor\ktarbet] from windows
//             *  select loginname from master..syslogins
//> go
//             sp_addsrvrolemember @loginame='bor\ktarbet' , @rolename='sysadmin'
//> ;
//             */
//            string cStr ="integrated security=SSPI;data source=localhost\\SQLEXPRESS;Database=master";
//            var svr = new SqlServer(cStr);
//            var tmp = svr.Table("exists", " SELECT name FROM master..sysdatabases where name = 'test_pisces'");
//            if (tmp.Rows.Count == 1)
//            {
//                svr.CloseAllConnections();
//                svr.DeleteDataBase("test_pisces");
//            }

//            Console.WriteLine("about to create database");
//            svr.CreateDataBase("test_pisces");
//            svr = new SqlServer(cStr.Replace("master","test_pisces"));

//            TimeSeriesDatabase db = new TimeSeriesDatabase(svr,false);
//            BasicDatabaseTest(db);
//        }


        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");
        }
Ejemplo n.º 22
0
        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);
        }
Ejemplo n.º 23
0
        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);
        }
Ejemplo n.º 24
0
        /// <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);
        }
Ejemplo n.º 25
0
        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);
        }
Ejemplo n.º 26
0
        public void TestHydrometRuleCurve()
        {
            var residual = new HydrometDailySeries("prv", "fcresid");

            DateTime t1 = new DateTime(2013, 10, 1);
            DateTime t2 = new DateTime(2014, 3, 4);

            residual.Read(t1, t2);
            DateTime feb1 = new DateTime(2014, 2, 1);

            var space = Reclamation.TimeSeries.Math.HydrometRuleCurve("prvo", residual);

            //Assert.AreEqual(0, space[t1].Value);

            Assert.AreEqual(60000, space[feb1].Value, 1);
            space.WriteToConsole();
        }
Ejemplo n.º 27
0
        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;
            }
        }
Ejemplo n.º 28
0
        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]);
        }
Ejemplo n.º 29
0
        public override void PrintDataTable(SeriesList list, DataTable table)
        {
            // add a column for 30 year average to the table.
            Series   s  = new HydrometDailySeries(dailySiteID, dailyPcode, HydrometHost.PNLinux);
            DateTime t1 = HydrometDataUtility.T1Thirty;

            s.Read(t1, t1.AddYears(30));
            Series s30 = Reclamation.TimeSeries.Math.MultiYearDailyAverage(s, 10);

            s30.RemoveMissing();

            if (table.Columns.Contains("flag"))
            {
                table.Columns.Remove("flag");
            }
            Print(table, s30);
        }
Ejemplo n.º 30
0
        private void PrintHtmlReport(TimeRange r, string siteID, string parameter)
        {
            Console.Write("Content-type: text/html\n\n");
            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);
            }
        }
Ejemplo n.º 31
0
        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);
            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);
            }
        }
Ejemplo n.º 32
0
        private void buttonGo_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            Application.DoEvents();
            try
            {
                MonthDayRange range = monthDayRangePicker1.MonthDayRange;



                string cbtt  = multiWaterYearSelector1.cbtt;
                string pcode = multiWaterYearSelector1.pcode;

                //var s = Reclamation.TimeSeries.Math.HydrometDaily(cbtt, pcode);

                var          t1  = multiWaterYearSelector1.T1;
                var          t2  = multiWaterYearSelector1.T2;
                HydrometHost svr = HydrometInfoUtility.HydrometServerFromPreferences();

                var s = HydrometDailySeries.Read(cbtt, pcode, t1, t2, svr);

                var rvalMax = Reclamation.TimeSeries.Math.AnnualMax(s, range, range.Month1);
                var rvalMin = Reclamation.TimeSeries.Math.AnnualMin(s, range, range.Month1);

                rvalMax.Appearance.LegendText = cbtt.ToUpper() + " " + pcode.ToUpper() + " Maximum in Range";
                rvalMin.Appearance.LegendText = cbtt.ToUpper() + " " + pcode.ToUpper() + " Minimum in Range";

                var list = new SeriesList();

                list.Add(rvalMax);
                list.Add(rvalMin);

                view.SeriesList = list;
                view.Draw();
            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }
Ejemplo n.º 33
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);
        }
Ejemplo n.º 34
0
        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);
                }
        }
Ejemplo n.º 35
0
        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);
        }
Ejemplo n.º 36
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);
        }
Ejemplo n.º 37
0
        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]);
        }
Ejemplo n.º 38
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;
        }