示例#1
0
        /// <summary>
        /// using the daily_calculation table preload hydrmet data referenced in the equations
        /// </summary>
        /// <param name="groupNames"></param>
        public void PreloadDailyHydrometData(string[] groupNames, DateTime t1, DateTime t2)
        {
            string sql = "select * from daily_calculation where group_name in ( '"
                         + System.String.Join("','", groupNames) + "' )";

            daily_calculationDataTable tbl = new daily_calculationDataTable();

            GetServer().FillTable(tbl, sql);

            var cbttPcodeList = new List <string>();

            // check for calculations (where cbtt_pcode) format is used.
            // example  JCK_AF
            foreach (var row in tbl)
            {
                string pattern = "(?<cbttPcode>[A-Z]{2,8}_[A-Z]{2,8})";
                var    mc      = Regex.Matches(row.equation, pattern);
                if (mc.Count > 0)
                {
                    foreach (Match item in mc)
                    {
                        cbttPcodeList.Add(item.Groups["cbttPcode"].Value.Replace("_", " "));
                    }
                }
            }

            cbttPcodeList = cbttPcodeList.Distinct().ToList();

            var cache = new HydrometDataCache();

            cache.Add(cbttPcodeList.ToArray(), t1, t2, HydrometHost.PN, TimeInterval.Daily);

            HydrometDailySeries.Cache = cache;
        }
示例#2
0
        private static void SetupCacheForShef(CsvFile csv, DateTime t1, DateTime t2)
        {
            Cache = new HydrometDataCache();

            // get list of pcodes and cbtts
            var query = from row in csv.AsEnumerable()
                        select row.Field <string>("cbtt")
                        + " " + row.Field <string>("pcode");

            Cache.Add(query.ToArray(), t1, t2, HydrometHost.PNLinux, TimeInterval.Daily);
        }
示例#3
0
        ///// <summary>
        ///// Saves Series data to Archives. This will overwrite existing data
        ///// uses:
        /////    Series.SiteName as cbtt
        /////    Series.Parameter as pcode
        ///// </summary>
        ///// <param name="list"></param>
        ///// <param name="?"></param>
        //public static void SaveToArchives(SeriesList list, string username, string password)
        //{
        //    string hydrometScript = WriteToArcImportFile(list);

        //    string remoteFile = HydrometDataUtility.CreateRemoteFileName(username, HydrometDataBase.Archives);

        //    if (LinuxUtility.IsLinux())
        //    {
        //        // copy file to server using scp --


        //    }
        //    else
        //    {
        //        var rval = HydrometEdits.RunArcImport(username, password, hydrometScript, remoteFile, true, false, false);
        //        Logger.WriteLine(rval);
        //    }
        //}


        /// <summary>
        /// .A ARKI1 20121104 M DH2400/QRDRG 0.435
        /// .A LUCI1 20121026 M DH2400/QADRZ 0.802
        /// </summary>
        /// <param name="controlFileName"></param>
        /// <param name="t1"></param>
        /// <param name="t2"></param>
        /// <returns></returns>
        public static string[] CreateSHEFA(string controlFileName, DateTime t1, DateTime t2)
        {
            var rval = new List <string>();
            var tmp  = Cache;

            CsvFile csv = new CsvFile(controlFileName,
                                      new string[] { "String", "String", "String", "String", "String", "Double" });

            SetupCacheForShef(csv, t1, t2);

            foreach (DataRow row in csv.Rows)
            {
                // read hydromet
                var s = new HydrometDailySeries(row["cbtt"].ToString(),
                                                row["pcode"].ToString());
                s.Read(t1, t2);
                s.RemoveMissing();

                foreach (var pt in s)
                {
                    if (pt.IsMissing)
                    {
                        continue;
                    }

                    double d = pt.Value * Convert.ToDouble(row["scale"]);

                    string A = ".A " + row["shef_locid"].ToString()
                               + " " + pt.DateTime.ToString("yyyyMMdd")
                               + " " + row["time_zone"].ToString()
                               + " DH2400/" + row["shef_tag"].ToString()
                               + " " + d.ToString("F3");


                    rval.Add(A);
                }
            }


            Cache = tmp;
            return(rval.ToArray());
        }
示例#4
0
        public static void PreloadInstantHydrometData(AlarmDataSet.alarm_definitionDataTable alarmdef)
        {
            // find all instant data, and largest hours_back, to make a single cache of data
            var cbttPcodes = (from row in alarmdef.AsEnumerable()
                         where row.database.ToLower() == "i"  // instant hydromet data
                         select row.cbtt.ToLower() + " " + row.pcode.ToLower()).Distinct().ToArray();

            if (cbttPcodes.Length == 0)
                return;

            // TO DO.  throw error if mixing quality and 'regular' data.
            //if (MixedQualityData(cbttPcodes))
            //{
            //    throw new ArgumentException("Error: quality and Mixing qual");
            //}

            var hours_back = (from row in alarmdef.AsEnumerable()
                              where row.database.ToLower() == "i"
                              select row.hours_back).Max();

            DateTime t1 = DateTime.Now.AddHours(-hours_back);
            DateTime t2 = DateTime.Now;
               // HydrometInstantSeries.KeepFlaggedData = true;

            var cache = new HydrometDataCache();
            cache.Add(String.Join(",", cbttPcodes).Split(','), t1, t2,
                HydrometHost.PN, Reclamation.TimeSeries.TimeInterval.Irregular, hours_back);

            HydrometInstantSeries.Cache = cache;
            Console.WriteLine(cbttPcodes);
        }
示例#5
0
        /// <summary>
        /// using the daily_calculation table preload hydrmet data referenced in the equations
        /// </summary>
        /// <param name="groupNames"></param>
        public void PreloadDailyHydrometData(string[] groupNames,DateTime t1,DateTime t2)
        {
            string sql = "select * from daily_calculation where group_name in ( '"
                          + System.String.Join("','",groupNames)+"' )";

            daily_calculationDataTable tbl = new daily_calculationDataTable();

            GetServer().FillTable(tbl, sql);

            var cbttPcodeList = new List<string>();

            // check for calculations (where cbtt_pcode) format is used.
            // example  JCK_AF
            foreach (var row in tbl)
            {
                string pattern = "(?<cbttPcode>[A-Z]{2,8}_[A-Z]{2,8})";
                var mc = Regex.Matches(row.equation, pattern);
                if (mc.Count > 0)
                {
                    foreach (Match item in mc)
                    {
                        cbttPcodeList.Add(item.Groups["cbttPcode"].Value.Replace("_", " "));
                    }
                }
            }

            cbttPcodeList = cbttPcodeList.Distinct().ToList();

            var cache = new HydrometDataCache();

            cache.Add(cbttPcodeList.ToArray(),t1,t2, HydrometHost.PN, TimeInterval.Daily);

            HydrometDailySeries.Cache = cache;
        }
示例#6
0
        // default 8am.
        /// <summary>
        /// Creates and returns the report.
        /// </summary>
        /// <returns></returns>
        public string Create(DateTime t, int year1=0, int year2=0)
        {
            string rval = GetTemplate();
            //13-OCT-2016  09:12:35
            var fmt = "dd-MMM-yyyy  HH:mm:ss";
            rval = rval.Replace(fmt, t.ToString(fmt));
            rval = rval.Replace("HH:mm", t.ToString("HH:mm"));

            res_af = Array.ConvertAll(res_af,x => x=double.MinValue);
            res_af2 = Array.ConvertAll(res_af, x => x = double.MinValue);
            res_q = Array.ConvertAll(res_af, x => x = double.MinValue);

            DateTime t1 =t.AddDays(-1);
            DateTime t2 = t;
            HydrometDataCache c = new HydrometDataCache();

            HydrometInstantSeries.Cache.Add(this.yakima_data, t1, t2, HydrometHost.Yakima, TimeInterval.Irregular);

            foreach (var cbtt in resList)
            {
              rval = ProcessParameter(rval ,t, cbtt, "fb");
              rval = ProcessParameter(rval, t, cbtt, "af");
              rval = ProcessParameter(rval, t, cbtt, "q");
            }

            rval = ReplaceSymbol(rval, "%total_af", total_af);
            double total_pct = total_af / totalCapacity * 100.0;
            rval = ReplaceSymbol(rval, "%total_pct", total_pct);
            rval = ReplaceSymbol(rval, "%total_q", reservoir_total_release);

            // compute inflows.
            for (int i = 0; i < resList.Length; i++)
            {
                if (resList[i] == "clr")
                    continue; // no contents
                var qu = (res_af[i]-res_af2[i]) / 1.9835 + res_q[i];
                rval = ReplaceSymbol(rval, "%" + resList[i] + "_in", qu);
                total_in += qu;
            }
            rval = ReplaceSymbol(rval, "%total_in", total_in);
            foreach (var canal in DataSubset("qc"))
            {
                var cbtt = canal.Substring(0, canal.IndexOf(" "));
                rval = ProcessParameter(rval, t, cbtt, "qc");
            }

            double others = ComputeOthersAboveParker(t1);
            rval = ReplaceSymbol(rval, "%major_qc", major_qc_total);
            rval = ReplaceSymbol(rval, "%other_qc", others);
            above_parker_qc += others + major_qc_total;
            rval = ReplaceSymbol(rval, "%parker_qc", above_parker_qc);

            foreach (var river in DataSubset("q"))
            {
                var cbtt = river.Substring(0, river.IndexOf(" "));
                if( !resList.Contains(cbtt)) // reservoir allready processed
                  rval = ProcessParameter(rval, t, cbtt, "q");
            }

            // unregulated tributary and return flows above parker.
            var above_parker = trib_qc_total + others + parw_q - reservoir_total_release;

             rval = ReplaceSymbol(rval, "%trib_parw", above_parker);

             rval = rval + "\r\nOPERATIONAL COMMENTS:  ";
             if (year1 > 0 && year2 > 0)
             {
                 var t1a = new DateTime(year1 - 1, 10, 1);
                 var t2a = new DateTime(year2, 9, 30);

                 double avgPct = MultiYearAvg(t1,t1a, t2a);

                 rval = rval + " Storage is " + avgPct.ToString("F1") + "% of average (" + year1
                      + ", " + year2 + ")."
                      + "\r\n---------------------";
             }

            return rval;
        }