Exemple #1
0
        // Populates Pisces DB with instant 15-minute data
        private static Series GetInstantSeries(string CBTT, string PCODE, DateTime t1, DateTime t2, TimeSeriesDatabase pDB,
                                               PiscesFolder rFldr)
        {
            Console.Write(CBTT + "_" + PCODE + ", ");
            Series rval = new HydrometInstantSeries(CBTT, PCODE);

            rval.Read(t1, t2);
            rval.Name = CBTT + "_" + PCODE + "15min";
            pDB.AddSeries(rval, rFldr);
            return(rval);
        }
Exemple #2
0
        public Series FetchInstantFromAPI(string site, string pcode, DateTime start, DateTime end)
        {
            // TODO: Add caching
            Series s = new Series("", TimeInterval.Irregular);

            s.Table           = HydrometInstantSeries.Read(site, pcode, start, end, HydrometHost.PNLinux).Table;
            s.Table.TableName = "instant_" + site + "_" + pcode;
            s.Name            = s.Table.TableName;

            return(s);
        }
        public double GetValue(string cbtt, string pcode, DateTime t)
        {
            var s = new HydrometInstantSeries(cbtt, pcode);

            //DateTime th = new DateTime(t.Year, t.Month, t.Day, hour, 0, 0);
            s.Read(t, t);

            if (s.Count > 0 && !s[0].IsMissing)
            {
                return(s[0].Value);
            }
            return(Point.MissingValueFlag);
        }
        /// <summary>
        /// Imports all required Series data to satisfy required equation inputs.
        /// </summary>
        private void ReadAllData(DateTime t1, DateTime t2, out Series dewTempDataAll, out Series windDataAll,
                                 out Series avgTempDataAll, out Series R_s1All)
        {
            string cbtt = this.cbtt;

            dewTempDataAll = new HydrometInstantSeries(cbtt, "TP"); //Dew Point Temp (DegF)
            dewTempDataAll.Read(t1, t2);
            windDataAll = new HydrometInstantSeries(cbtt, "WS");    //Wind Speed (mph)
            windDataAll.Read(t1, t2);
            avgTempDataAll = new HydrometInstantSeries(cbtt, "OB"); //Average Temp (DegF)
            avgTempDataAll.Read(t1, t2);
            R_s1All = new HydrometInstantSeries(cbtt, "SI");        //Solar Radiation (MJ/m2/hr)
            R_s1All.Read(t1, t2);
        }
Exemple #5
0
        static Series GetInstantSeries(string cbtt, string pcode, DateTime t, int hours_back)
        {
            Series s  = new HydrometInstantSeries(cbtt, pcode, Utility.GetHydrometServer());
            var    t1 = t.AddHours(-hours_back);

            s.Read(t1, t);
            // Hydromet web query doesn't have hour resolution.  we must clean that ourselves.
            var s2 = Reclamation.TimeSeries.Math.Subset(s, t1, t);

            // keep data in HydrometInstantSeries (becuse it understands it's flags)
            s.Clear();
            s.Add(s2);
            return(s);
        }
Exemple #6
0
        /// <summary>
        /// .A LWOI1 080313 M DH0530/QRIRG 72.07
        /// .A LWOI1 080313 M DH0545/QRIRG 69.50
        /// .A LWOI1 080313 M DH0600/QRIRG 70.78
        /// .A LWOI1 080313 M DH0615/QRIRG 69.50
        /// </summary>
        private static void WriteHourly(DateTime t1, DateTime t2, StreamWriter sw, string cbtt, string pcode, string shefName, string shefPcode, string timeZone)
        {
            //HydrometInstantSeries.UseCaching = false;
            Series s = HydrometInstantSeries.Read(cbtt, pcode, t1, t2, HydrometHost.PNLinux);

            s.RemoveMissing();

            for (int j = 0; j < s.Count; j++)
            {
                DateTime t = s[j].DateTime;
                sw.WriteLine(".A " + shefName + " "
                             + t.ToString("yyMMdd") + " "
                             + timeZone + " "
                             + "DH" + t.ToString("HHmm") + "/" + shefPcode + " " + s[j].Value.ToString("F2"));
            }
            System.Threading.Thread.Sleep(100);
        }
Exemple #7
0
        static void Main(string[] args)
        {
            string dbFileName = "test.pdb";

            if (File.Exists(dbFileName))
            {
                File.Delete(dbFileName);
            }

            SQLiteServer       sqlite = new SQLiteServer(dbFileName);
            TimeSeriesDatabase db     = new TimeSeriesDatabase(sqlite);

            // read seriescatalog.csv -- from the production database. This is a template without the data

            DataTable csv = new CsvFile("seriescatalog.csv");

            //get a list of site that have instant (irregular) data

            string[] sites = GetSitesWithPrecip(csv);

            // for each site with precipitation
            // -------------
            for (int i = 0; i < sites.Length; i++)
            {
                // add instant precip (pc -- raw in the bucket values)

                var    folder = db.GetOrCreateFolder(sites[i]);
                Series s      = new Series("", TimeInterval.Irregular);

                s.Table           = HydrometInstantSeries.Read(sites[i], "pc", DateTime.Parse("2010-10-1"), DateTime.Now.Date, HydrometHost.PNLinux).Table;
                s.Table.TableName = "instant_" + sites[i] + "_pc";
                s.Name            = s.Table.TableName;
                db.AddSeries(s, folder);

                if (i > 3) // make testing faster
                {
                    break;
                }

                // add daily  precip (pc -- midnight value of the bucket)
                // add daily incremental  ( pp -- daily sum of precipitation)
                // add daily cumulative (pu -- water year cummulative)
            }
        }
Exemple #8
0
 // Populates Pisces DB with instant 15-minute data
 private static Series GetInstantSeries(string CBTT, string PCODE, DateTime t1, DateTime t2, TimeSeriesDatabase pDB,
     PiscesFolder rFldr)
 {
     Console.Write(CBTT + "_" + PCODE + ", ");
     Series rval = new HydrometInstantSeries(CBTT, PCODE);
     rval.Read(t1, t2);
     rval.Name = CBTT + "_" + PCODE + "15min";
     pDB.AddSeries(rval, rFldr);
     return rval;
 }
Exemple #9
0
        public double GetValue(string cbtt, string pcode, DateTime t)
        {
            var s = new HydrometInstantSeries(cbtt, pcode,HydrometHost.Yakima);
            //DateTime th = new DateTime(t.Year, t.Month, t.Day, hour, 0, 0);
            s.Read(t,t);

            if( s.Count >0 && !s[0].IsMissing)
            {
                return s[0].Value;
            }
            return Point.MissingValueFlag;
        }
Exemple #10
0
        //try to take the code from above and make it into here for the show cmd
        private static string Get(string s, DateTime t1, DateTime t2)
        {
            string[] cbtt  = { "" };
            string[] pcode = { "" };
            string   Id    = "";
            string   value = "";
            string   pc    = "";
            var      cfg   = new Config(s, t1, t2);

            if (s.Trim().ToLower()[0] == 'g')
            {
                cbtt = cfg.cbtt;
                for (int i = 0; i < cbtt.Length; i++)
                {
                    Id = LoopCBTT(cbtt[i]);

                    if (String.IsNullOrEmpty(Id) == true)
                    {
                        Console.WriteLine("%W-Dayfile, no data found for get request:" + cbtt[i]);
                    }

                    else
                    {
                        string[] ID = Id.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        //improving the speed of the program
                        var cache = new HydrometDataCache();
                        cache.Add(ID, t1, t2, HydrometHost.PNLinux, Reclamation.TimeSeries.TimeInterval.Irregular);
                        HydrometInstantSeries.Cache           = cache;
                        HydrometInstantSeries.KeepFlaggedData = true;

                        if (cfg.IsGetAll)
                        {
                            HydrometInstantSeries ts = new HydrometInstantSeries(ID[0].Split(' ')[0], ID[0].Split(' ')[1]);
                            ts.Read(t1, t2);
                            var count = (ts.MaxDateTime - ts.MinDateTime).TotalMinutes;
                            for (int t = 0; t <= count / 15; t++)
                            {
                                pc = cbtt[i].ToUpper() + " " + t1.AddMinutes(t * 15).ToString("yyMMMdd");
                                for (int j = 0; j < ID.Length; j++)
                                {
                                    var c = ID[j].Split(' ')[0];
                                    var p = ID[j].Split(' ')[1];
                                    HydrometInstantSeries.KeepFlaggedData = true;
                                    ts = new HydrometInstantSeries(c, p);
                                    ts.Read(t1, t2);
                                    pc = pc + " " + p.ToUpper();
                                    if (j == 0)
                                    {
                                        value = " " + ts.MinDateTime.AddMinutes(t * 15).TimeOfDay + " " + ts[ts.MinDateTime.AddMinutes(t * 15)].Value;
                                    }
                                    else
                                    {
                                        value = value + " " + ts[ts.MinDateTime.AddMinutes(t * 15)].Value;
                                    }
                                }
                                if (ts.MinDateTime.AddMinutes(t * 15).TimeOfDay.TotalHours == 0 || ts.MinDateTime.AddMinutes(t * 15).TimeOfDay.TotalHours == 12)
                                {
                                    WriteLines(pc);
                                }
                                WriteLines(value);
                            }
                        }

                        if (cfg.IsGet || (cfg.IsGetAll == false && cfg.IsGetPcode))
                        {
                            if (cfg.IsGetAll == false && cfg.IsGetPcode)
                            {
                                pcode = cfg.pcode;
                                Id    = "";
                                for (int j = 0; j < pcode.Length; j++)
                                {
                                    Id = Id + cbtt[i] + " " + pcode[j] + ",";
                                }
                                ID = Id.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                            }
                            var count = (t2 - t1).TotalDays;
                            for (int t = 0; t <= count; t++)
                            {
                                pc = cbtt[i].ToUpper() + " " + t1.AddDays(t).ToString("yyMMMdd");
                                for (int j = 0; j < ID.Length; j++)
                                {
                                    var c = ID[j].Split(' ')[0];
                                    var p = ID[j].Split(' ')[1];
                                    HydrometInstantSeries.KeepFlaggedData = true;
                                    HydrometInstantSeries ts = new HydrometInstantSeries(c, p);
                                    ts.Read(t1, t2);
                                    pc = pc + " " + p.ToUpper();
                                    if (j == 0)
                                    {
                                        value = " " + ts.MaxDateTime.AddDays(-count + t).TimeOfDay + " " + ts[ts.MaxDateTime.AddDays(-count + t)].Value;
                                    }
                                    else
                                    {
                                        value = value + " " + ts[ts.MaxDateTime.AddDays(-count + t)].Value;
                                    }
                                }
                                WriteLines(pc);
                                WriteLines(value);
                            }
                        }
                    }
                }
            }
            return(s);
        }