예제 #1
0
파일: Program.cs 프로젝트: ruo2012/Pisces
        // 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);
        }
예제 #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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        /// <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);
        }
예제 #5
0
파일: Alarm.cs 프로젝트: woohn/Pisces
        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);
        }
예제 #6
0
파일: Program.cs 프로젝트: woohn/Pisces
        /// <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);
        }
예제 #7
0
파일: Program.cs 프로젝트: woohn/Pisces
        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)
            }
        }
예제 #8
0
파일: Program.cs 프로젝트: usbr/Pisces
 // 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;
 }
예제 #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;
        }
예제 #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);
        }