Exemplo n.º 1
0
        /// <summary>
        /// Finds forecast series.  Check if a mid-month forecast exists
        /// and use that if available.  Handle special case for hungry horse (hgh)
        /// </summary>
        /// <param name="cbtt"></param>
        /// <param name="waterYear"></param>
        /// <returns></returns>
        public static Series GetLatestForecast(string cbtt, Int32 waterYear)
        {
            var pc = "fc";

            if (cbtt.ToLower() == "hgh")
            {
                pc = "fms"; // forecast (f) may (m) to september (s) == fms
            }
            Series fc  = new HydrometMonthlySeries(cbtt, pc);
            Series fcm = new HydrometMonthlySeries(cbtt, "fcm"); // mid month
            var    t1  = new DateTime(waterYear, 1, 1);
            var    t2  = new DateTime(waterYear, 7, 1);

            fc.Read(t1, t2);
            fcm.Read(t1, t2);

            int i_fc  = MonthOfLastForecast(fc);
            int i_fcm = MonthOfLastForecast(fcm);

            if (i_fcm > 0 && i_fcm >= i_fc)
            {
                return(fcm);
            }

            return(fc);
        }
Exemplo n.º 2
0
        private Series ReadMpollData(string pcode, string cbtt)
        {
            if (!checkBoxMpoll.Checked)
            {
                return(new Series());
            }

            Series   m  = new HydrometMonthlySeries(cbtt, pcode);
            DateTime t1 = new DateTime(6189, 10, 1);
            DateTime t2 = new DateTime(6190, 9, 1);


            m.Read(t1, t2);
            //m = Math.Subset(m, monthRangePicker1.MonthDayRange);
            //if (range.Month1 < 9)
            //{
            //    m = Math.ShiftToYear(m, 2001);
            //}
            //  else
            //{
            //    m = Math.ShiftToYear(m, 2000);
            //}

            m.Appearance.Style       = Styles.Point;
            m.Appearance.LegendText += " 30 yr average";

            return(m);
        }
Exemplo n.º 3
0
        public void MonthlyMissingRecords()
        {
            HydrometMonthlySeries s = new HydrometMonthlySeries("jkpi", "se");
            DateTime t1             = new DateTime(3000, 10, 1);
            DateTime t2             = new DateTime(3001, 9, 1);

            s.Read(t1, t2);
            s.WriteToConsole();
            Assert.AreEqual(12, s.Count);
            Assert.AreEqual(12, s.CountMissing());
        }
Exemplo n.º 4
0
        public void MonthlyMissingRecords()
        {
            HydrometMonthlySeries s = new HydrometMonthlySeries("jkpi", "se");
            DateTime t1 = new DateTime(3000, 10, 1);
            DateTime t2 = new DateTime(3001, 9, 1);

            s.Read(t1, t2);
            s.WriteToConsole();
            Assert.AreEqual(12, s.Count);
            Assert.AreEqual(12, s.CountMissing());
        }
Exemplo n.º 5
0
        void ReadMonthlyForecast(DateTime t1, DateTime t2)
        {
            fc             = new HydrometMonthlySeries(controlPoint.StationQU, "FC");// hgh "fms"
            fc.TimePostion = TimePostion.FirstOfMonth;

            fcm             = new HydrometMonthlySeries(controlPoint.StationQU, "FCM");
            fcm.TimePostion = TimePostion.MidMonth;

            fc.Read(t1, t2);
            fcm.Read(t1, t2);
        }
Exemplo n.º 6
0
        public static Series GetLatestForecast(string cbtt, Int32 waterYear)
        {
            var pc = "fc";

            if (cbtt.ToLower() == "hgh")
            {
                pc = "fms";
            }
            Series forecast = new HydrometMonthlySeries(cbtt, pc);
            var    t1       = new DateTime(waterYear, 1, 1);
            var    t2       = new DateTime(waterYear, 7, 1);

            forecast.Read(t1, t2);
            return(forecast);
        }
Exemplo n.º 7
0
        public WodiRuleCurve(string cbtt, int waterYear, FillType fType)
            : base("wodi.space", fType)
        {
            this.waterYear = waterYear;
            qu             = new HydrometDailySeries("wodi", "qu");
            var t1 = new DateTime(waterYear - 1, 10, 1);
            var t2 = new DateTime(waterYear, 9, 30);

            qu.Read(t1, t2);
            tblQu          = FcPlotDataSet.GetTable("wodi.inflow");
            tblfc          = FcPlotDataSet.GetTable("wodi.forecast");
            fc             = new HydrometMonthlySeries("wodi", "fc");
            fc.TimePostion = TimePostion.EndOfMonth;
            fc.Read(t1, t2);

            ReadQUAverage();
        }
Exemplo n.º 8
0
        void ReadMonthlyForecast(DateTime t1, DateTime t2)
        {
            var pc = "fc";

            if (controlPoint.StationFC.ToLower() == "hgh")
            {
                pc = "fms";
            }
            fc             = new HydrometMonthlySeries(controlPoint.StationFC, pc);// hgh "fms"
            fc.TimePostion = TimePostion.FirstOfMonth;

            fcm             = new HydrometMonthlySeries(controlPoint.StationFC, "FCM");
            fcm.TimePostion = TimePostion.MidMonth;

            fc.Read(t1, t2);
            fcm.Read(t1, t2);
        }
Exemplo n.º 9
0
        public void Monthly30yrAverage()
        {
            HydrometMonthlySeries s = new HydrometMonthlySeries("jkpi", "sem");
            DateTime t1 = new DateTime(6189, 10, 1);
            DateTime t2 = new DateTime(6190, 9, 1);

            double[] sem = { 0, 3.5, 9.6, 16.6, 23.0, 28.8, 33.3, 23.0, 0, 0, 0, 0 };
            s.Read(t1, t2);
            Assert.AreEqual(12, s.Count);
            DateTime t = t1;
            for (int i = 0; i < sem.Length; i++)
            {
                Assert.AreEqual(sem[i], s[i].Value);
                Assert.AreEqual(t.Month, s[i].DateTime.Month);
                Assert.AreEqual(t.Year, s[i].DateTime.Year);
                Assert.AreEqual("S", s[i].Flag);
                t = t.AddMonths(1);
            }
            //m.CreateSeries(row);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Hydromet mpoll stores the average for water years 1960-1989
        /// in the year 6189
        /// </summary>
        //[Test]
        public void Monthly30yrAverage()
        {
            HydrometMonthlySeries s = new HydrometMonthlySeries("jkpi", "sem");
            DateTime t1             = new DateTime(6189, 10, 1);
            DateTime t2             = new DateTime(6190, 9, 1);

            double[] sem = { 0, 3.5, 9.6, 16.6, 23.0, 28.8, 33.3, 23.0, 0, 0, 0, 0 };
            s.Read(t1, t2);
            Assert.AreEqual(12, s.Count);
            DateTime t = t1;

            for (int i = 0; i < sem.Length; i++)
            {
                Assert.AreEqual(sem[i], s[i].Value);
                Assert.AreEqual(t.Month, s[i].DateTime.Month);
                Assert.AreEqual(t.Year, s[i].DateTime.Year);
                Assert.AreEqual("S", s[i].Flag);
                t = t.AddMonths(1);
            }
            //m.CreateSeries(row);
        }
Exemplo n.º 11
0
        public void TestHydrometResidualForecast()
        {
            DateTime t1 = new DateTime(2014, 2, 1);
            DateTime t2 = new DateTime(2014, 2, 28);

            var qu       = new HydrometDailySeries("prvo", "qu");
            var fc       = new HydrometMonthlySeries("prvo", "fc");
            var fcm      = new HydrometMonthlySeries("prvo", "fcm");
            var residual = new HydrometDailySeries("prv", "fcresid");

            Assert.AreEqual(TimeInterval.Daily, residual.TimeInterval);

            qu.Read(t1, t2);
            fc.Read(t1, t2);
            fcm.Read(t1, t2);
            var forecast = Math.HydrometForecastMonthlyToDaily(fc, fcm);

            residual.Read(t1, t2);

            var fcresid = Reclamation.TimeSeries.Math.HydrometResidualForecast(forecast, qu, residual);

            fcresid.WriteToConsole();
        }
Exemplo n.º 12
0
        public static Series Read(string cbtt, string pcode, DateTime t1, DateTime t2,
            TimeInterval interval, HydrometHost hydrometServer)
        {
            Series s = new Series();

            if (interval == TimeInterval.Daily)
            {
                s = HydrometDailySeries.Read(cbtt, pcode, t1, t2, hydrometServer);
            }
            else if (interval == TimeInterval.Irregular)
            {
                s = HydrometInstantSeries.Read(cbtt, pcode, t1, t2, hydrometServer);
            }
            else if (interval == TimeInterval.Monthly)
            {
                s = new HydrometMonthlySeries(cbtt, pcode,hydrometServer);
                s.Read(t1, t2);
            }
            else
            {
                throw new ArgumentException("Undefined TimeInterval", interval.ToString());
            }

            return s;
        }
Exemplo n.º 13
0
        static void Main(string[] args)
        {
            if (args.Length != 3 && args.Length != 4)
            {
                Console.WriteLine("Usage: ImportMonthlyValues server user pass [siteid]");
                Console.WriteLine(" server = hostname ");
                Console.WriteLine(" user = username");
                Console.WriteLine(" pass = passwordfile");
                return;
            }

            var    host = args[0];
            string user = args[1];
            string pass = File.ReadAllLines(args[2])[0];
            string cbtt = "";

            if (args.Length == 4)
            {
                cbtt = args[3];
            }

            var svr = PostgreSQL.GetPostgresServer("timeseries", host, user, pass);
            //UpdateVMS_daily_por(svr);
            TimeSeriesDatabase db = new TimeSeriesDatabase(svr);

            Console.WriteLine(db.Server.ConnectionString);

            var sitecatalog = db.GetSiteCatalog();
            // cbtt, pcode, years, descr, units
            DataTable mpoll = new DataTable("mpoll");

            if (File.Exists(@"c:\temp\mpoll.xml"))
            {
                mpoll.ReadXml(@"c:\temp\mpoll.xml");
            }
            else
            {
                mpoll = HydrometInfoUtility.MonthlyInventory;
                mpoll.WriteXml(@"C:\temp\mpoll.xml", System.Data.XmlWriteMode.WriteSchema);
            }

            for (int i = 0; i < mpoll.Rows.Count; i++)
            {
                var r      = mpoll.Rows[i];
                var siteid = r["cbtt"].ToString().ToLower();
                var pcode  = r["pcode"].ToString().ToLower();
                var years  = r["years"].ToString();

                if (cbtt != "" && cbtt.ToLower() != siteid.ToLower())
                {
                    continue;
                }

                HydrometMonthlySeries m = new HydrometMonthlySeries(siteid, pcode, HydrometHost.PN);
                HydrometMonthlySeries.ConvertToAcreFeet = false;
                // does site id exist in sitecatalog?
                if (KeepThisSeries(sitecatalog, siteid, pcode, years))
                {
                    m.Read();
                    m.RemoveMissing();
                    Console.WriteLine(siteid + "_" + pcode + " [" + m.Count + "]");
                    if (m.Count == 0)
                    {
                        continue;
                    }

                    var folder = db.GetOrCreateFolder("hydromet", siteid, "monthly");
                    var tn     = "monthly_" + siteid + "_" + pcode;
                    var s      = db.GetSeriesFromTableName(tn);
                    if (s == null)
                    { // need to create series.
                        s                 = new Series("", TimeInterval.Monthly);
                        s.Name            = siteid + "_" + pcode;
                        s.Table.TableName = tn;
                        s.Parameter       = pcode;
                        s.SiteID          = siteid;
                        s.TimeInterval    = TimeInterval.Monthly;
                        db.AddSeries(s, folder);
                    }


                    s.Table = m.Table;
                    db.SaveTimeSeriesTable(s.ID, s, DatabaseSaveOptions.DeleteAllExisting);
                }
            }
        }