Пример #1
0
        /// <summary>
        /// This method creates the shift table based on the 'lower'-'mid'-'upper' values specified in the owrd RDB file
        /// </summary>
        /// <param name="rdbFile"></param>
        private TimeSeriesDatabaseDataSet.RatingTableDataTable CreateShiftTable(TextFile rdbFile)
        {
            double gh1    = rdbFile.ReadSingle("SHIFT_LOWER_STAGE");
            var    shift1 = rdbFile.ReadSingle("SHIFT_LOWER_VALUE");
            double gh2    = rdbFile.ReadSingle("SHIFT_MID_STAGE");
            var    shift2 = rdbFile.ReadSingle("SHIFT_MID_VALUE");
            double gh3    = rdbFile.ReadSingle("SHIFT_UPPER_STAGE");
            var    shift3 = rdbFile.ReadSingle("SHIFT_UPPER_VALUE");

            if (gh1 == 0 && gh2 == 0 && gh3 == 0)
            {
                gh2 = 5.0;
                gh3 = 100;
            }

            // Build shift table
            var tbl = new TimeSeriesDatabaseDataSet.RatingTableDataTable();

            tbl.AddRatingTableRow(gh1, shift1);
            tbl.AddRatingTableRow(gh2, shift2);
            tbl.AddRatingTableRow(gh3, shift3);
            tbl.AddRatingTableRow(gh3 * 5, shift3); // extrapolate out

            if (gh1 > gh2 || gh2 > gh3)
            {
                var msg = "Error: Stages values in the shift table are not in increasing order.";
                msg += "\n" + this.ratingNumber;
                msg += "\n" + this.stationNumber;
                msg += "\n" + this.downloadURL;
                Console.WriteLine(msg);
                throw new ArgumentException(msg);
            }
            return(tbl);
        }
Пример #2
0
        public static TimeSeriesDatabaseDataSet.RatingTableDataTable GetRatingTable(string siteNumber)
        {
            //string url = "http://waterdata.usgs.gov/nwisweb/data/exsa_rat/13236500.rdb";
            string url = "http://waterdata.usgs.gov/nwisweb/get_ratings?site_no=13081500&file_type=exsa";

            url = url.Replace("13081500", siteNumber);
            string[] data = Web.GetPage(url);

            TextFile tf = new TextFile(data);

            UsgsRDBFile rdb = new UsgsRDBFile(data);

            TimeSeriesDatabaseDataSet.RatingTableDataTable t = new TimeSeriesDatabaseDataSet.RatingTableDataTable();

            t.XUnits = LookupUnits(tf, "# //RATING_INDEP");
            t.YUnits = LookupUnits(tf, "# //RATING_DEP");

            for (int i = 0; i < rdb.Rows.Count; i++)
            {
                double x = Convert.ToDouble(rdb.Rows[i]["indep"]);
                double y = Convert.ToDouble(rdb.Rows[i]["dep"]);
                var    r = t.FindByx(x);
                if (r == null)
                {
                    t.AddRatingTableRow(x, y);
                }
                else
                {
                    Console.WriteLine("Warning: duplicate x " + x);
                }
            }
            t.Name = "Usgs " + siteNumber;
            return(t);
        }
Пример #3
0
        public static TimeSeriesDatabaseDataSet.RatingTableDataTable GetRatingTable(string siteNumber)
        {
            //string url = "http://waterdata.usgs.gov/nwisweb/data/exsa_rat/13236500.rdb";
              string url = "http://waterdata.usgs.gov/nwisweb/get_ratings?site_no=13081500&file_type=exsa";
              url = url.Replace("13081500", siteNumber);
              string[] data = Web.GetPage(url);

              TextFile tf = new TextFile(data);

              UsgsRDBFile rdb = new UsgsRDBFile(data);

              TimeSeriesDatabaseDataSet.RatingTableDataTable t = new TimeSeriesDatabaseDataSet.RatingTableDataTable();

              t.XUnits = LookupUnits(tf,"# //RATING_INDEP");
              t.YUnits = LookupUnits(tf,"# //RATING_DEP");

              for (int i = 0; i < rdb.Rows.Count; i++)
              {
              double x = Convert.ToDouble(rdb.Rows[i]["indep"]);
              double y = Convert.ToDouble(rdb.Rows[i]["dep"]);
              t.AddRatingTableRow(x, y);
              }
              t.Name = "Usgs " + siteNumber;
              return t;
        }
Пример #4
0
        /// <summary>
        /// This method creates the shift table based on the 'lower'-'mid'-'upper' values specified in the owrd RDB file
        /// </summary>
        /// <param name="rdbFile"></param>
        private TimeSeriesDatabaseDataSet.RatingTableDataTable CreateShiftTable(TextFile rdbFile)
        {
            double gh1    = rdbFile.ReadSingle("SHIFT_LOWER_STAGE");
            var    shift1 = rdbFile.ReadSingle("SHIFT_LOWER_VALUE");
            double gh2    = rdbFile.ReadSingle("SHIFT_MID_STAGE");
            var    shift2 = rdbFile.ReadSingle("SHIFT_MID_VALUE");
            double gh3    = rdbFile.ReadSingle("SHIFT_UPPER_STAGE");
            var    shift3 = rdbFile.ReadSingle("SHIFT_UPPER_VALUE");

            if (gh1 == 0 && gh2 == 0 && gh3 == 0)
            {
                gh2 = 5.0;
                gh3 = 100;
            }

            // Build shift table
            var tbl = new TimeSeriesDatabaseDataSet.RatingTableDataTable();

            tbl.AddRatingTableRow(gh1, shift1);
            tbl.AddRatingTableRow(gh2, shift2);
            tbl.AddRatingTableRow(gh3, shift3);
            tbl.AddRatingTableRow(gh3 * 5, shift3); // extrapolate out
            return(tbl);
        }
Пример #5
0
        public static TimeSeriesDatabaseDataSet.RatingTableDataTable ParseRatingTableData(TextFile tf,
                                                                                          string cbtt, string pcode)
        {
            /*
             * <table border="1" summary="Expanded Rating Table">	<tr align="center">
             * <th width="80px"><b>ft</b></th>
             * <th width="80px"><b>cfs</b></th>
             * </tr>
             *
             * Table Edit Date: 18-SEP-2014 02:22
             * <tr align="right"><td>2440.01</td><td>-704.00</td></tr>
             * <tr align="right"><td>2440.02</td><td>-704.00</td></tr>
             * <tr align="right"><td>2440.03</td><td>-704.00</td></tr>
             * <tr align="right"><td>2440.04</td><td>-704.00</td></tr>
             */


            TimeSeriesDatabaseDataSet.RatingTableDataTable t = new TimeSeriesDatabaseDataSet.RatingTableDataTable();
            int idx = tf.IndexOfBothRegex("<th.*</th>", "<th.*</th>");

            if (idx >= 0)
            {
                t.XUnits = Regex.Match(tf[idx], @"<th.*<b>(?<x>\w*)</b>").Groups[1].Value;
                t.YUnits = Regex.Match(tf[idx + 1], @"<th.*<b>(?<x>\w*)</b>").Groups[1].Value;
            }
            //<br>Table Edit Date: 18-SEP-2014 02:22<br>Today's Date: 23-SEP-2014 06:54
            var idxDate = tf.IndexOfRegex("Table Edit Date:.*<br>");

            if (idxDate >= 0)
            {
                t.EditDate = Regex.Match(tf[idxDate], "Table Edit Date:(?<date>.*)<br>").Groups[1].Value;
            }


            Regex re = new Regex(@"<tr.*?>(?<x>[\d\.\-\+]{1,12})</td><td>(?<y>[\d\.\-\+]{1,12})</td>");

            for (int i = idx + 2; i < tf.Length; i++)
            {
                var m = re.Match(tf[i]);
                if (m.Success)
                {
                    double x, y;
                    if (double.TryParse(m.Groups["x"].Value, out x)
                        )
                    {
                        if (double.TryParse(m.Groups["y"].Value, out y) &&
                            System.Math.Abs(998877 - y) > 0.01
                            )
                        {
                            t.AddRatingTableRow(x, y);
                        }
                    }
                }
            }
            t.Name = "Hydromet " + cbtt + " " + pcode;
            idx    = tf.IndexOfRegex("<b>Station .+<br />");
            if (idx >= 0)
            {
                t.Name = Regex.Match(tf[idx], "<b>Station (.+)<br />").Groups[1].Value;
            }

            return(t);
        }
Пример #6
0
        public static TimeSeriesDatabaseDataSet.RatingTableDataTable ParseRatingTableData(TextFile tf, 
            string cbtt, string pcode)
        {
            /*
             <table border="1" summary="Expanded Rating Table">	<tr align="center">
            <th width="80px"><b>ft</b></th>
            <th width="80px"><b>cfs</b></th>
            </tr>
             *
             * Table Edit Date: 18-SEP-2014 02:22
            <tr align="right"><td>2440.01</td><td>-704.00</td></tr>
            <tr align="right"><td>2440.02</td><td>-704.00</td></tr>
            <tr align="right"><td>2440.03</td><td>-704.00</td></tr>
            <tr align="right"><td>2440.04</td><td>-704.00</td></tr>
             */

            TimeSeriesDatabaseDataSet.RatingTableDataTable t = new TimeSeriesDatabaseDataSet.RatingTableDataTable();
            int idx = tf.IndexOfBothRegex("<th.*</th>", "<th.*</th>");
            if (idx >= 0)
            {
                t.XUnits = Regex.Match(tf[idx], @"<th.*<b>(?<x>\w*)</b>").Groups[1].Value;
                t.YUnits = Regex.Match(tf[idx + 1], @"<th.*<b>(?<x>\w*)</b>").Groups[1].Value;
            }
            //<br>Table Edit Date: 18-SEP-2014 02:22<br>Today's Date: 23-SEP-2014 06:54
            var idxDate = tf.IndexOfRegex("Table Edit Date:.*<br>");
            if (idxDate >= 0)
            {
                t.EditDate = Regex.Match(tf[idxDate], "Table Edit Date:(?<date>.*)<br>").Groups[1].Value;
            }

            Regex re = new Regex(@"<tr.*?>(?<x>[\d\.\-\+]{1,12})</td><td>(?<y>[\d\.\-\+]{1,12})</td>");
            for (int i = idx + 2; i < tf.Length; i++)
            {
                var m = re.Match(tf[i]);
                if (m.Success)
                {
                    double x, y;
                    if (double.TryParse(m.Groups["x"].Value, out x)
                        )
                    {
                        if (double.TryParse(m.Groups["y"].Value, out y)
                            && System.Math.Abs(998877 - y) > 0.01
                            )
                        {
                            t.AddRatingTableRow(x, y);
                        }
                    }
                }
            }
            t.Name = "Hydromet " + cbtt + " " + pcode;
            idx = tf.IndexOfRegex("<b>Station .+<br />");
            if (idx >= 0)
                t.Name = Regex.Match(tf[idx], "<b>Station (.+)<br />").Groups[1].Value;

            return t;
        }
Пример #7
0
        public static TimeSeriesDatabaseDataSet.RatingTableDataTable GetRatingTable(string cbtt, string pcode)
        {
            // yakima ?
            //http://www.usbr.gov/pn-bin/yak/expandrtf.pl?site=kee&pcode=af&form=col

            string url = "http://www.usbr.gov/pn-bin/expandrtf.pl?site=pali&pcode=q&form=col";

            if (HydrometInfoUtility.HydrometServerFromPreferences() == HydrometHost.GreatPlains)
            {
                //url = "http://www.usbr.gov/gp-bin/expandrtf.pl?site=adatunco&pcode=q&form=col";
                url = "http://www.usbr.gov/gp-bin/expandrtf.pl?site=pali&pcode=q&form=col";
            }


            url = url.Replace("site=pali", "site=" + cbtt.Trim());
            url = url.Replace("pcode=q", "pcode=" + pcode.Trim());

            string[] data = Web.GetPage(url);
            TextFile tf   = new TextFile(data);

            /*
             * <table border="1" summary="Expanded Rating Table">	<tr align="center">
             * <th width="80px"><b>ft</b></th>
             * <th width="80px"><b>cfs</b></th>
             * </tr>
             *
             * Table Edit Date: 18-SEP-2014 02:22
             * <tr align="right"><td>2440.01</td><td>-704.00</td></tr>
             * <tr align="right"><td>2440.02</td><td>-704.00</td></tr>
             * <tr align="right"><td>2440.03</td><td>-704.00</td></tr>
             * <tr align="right"><td>2440.04</td><td>-704.00</td></tr>
             */


            TimeSeriesDatabaseDataSet.RatingTableDataTable t = new TimeSeriesDatabaseDataSet.RatingTableDataTable();
            int idx = tf.IndexOfBothRegex("<th.*</th>", "<th.*</th>");

            if (idx >= 0)
            {
                t.XUnits = Regex.Match(tf[idx], @"<th.*<b>(?<x>\w*)</b>").Groups[1].Value;
                t.YUnits = Regex.Match(tf[idx + 1], @"<th.*<b>(?<x>\w*)</b>").Groups[1].Value;
            }
            //<br>Table Edit Date: 18-SEP-2014 02:22<br>Today's Date: 23-SEP-2014 06:54
            var idxDate = tf.IndexOfRegex("Table Edit Date:.*<br>");

            if (idxDate >= 0)
            {
                t.EditDate = Regex.Match(tf[idxDate], "Table Edit Date:(?<date>.*)<br>").Groups[1].Value;
            }


            Regex re = new Regex(@"<tr.*?>(?<x>[\d\.\-\+]{1,12})</td><td>(?<y>[\d\.\-\+]{1,12})</td>");

            for (int i = idx + 2; i < tf.Length; i++)
            {
                var m = re.Match(tf[i]);
                if (m.Success)
                {
                    double x, y;
                    if (double.TryParse(m.Groups["x"].Value, out x)
                        )
                    {
                        if (double.TryParse(m.Groups["y"].Value, out y) &&
                            System.Math.Abs(998877 - y) > 0.01
                            )
                        {
                            t.AddRatingTableRow(x, y);
                        }
                    }
                }
            }
            t.Name = "Hydromet " + cbtt + " " + pcode;
            idx    = tf.IndexOfRegex("<b>Station .+<br />");
            if (idx >= 0)
            {
                t.Name = Regex.Match(tf[idx], "<b>Station (.+)<br />").Groups[1].Value;
            }

            return(t);
        }