Ejemplo n.º 1
0
        /// <summary>
        /// Find all CalculationSeries (Equations) that reference this Series.  Use the tablename
        /// of this series as the variable to look for in each equation.
        /// </summary>
        /// <param name="cs"></param>
        /// <returns></returns>
        private List <CalculationSeries> BuildDependencies(CalculationSeries cs)
        {
            var rval = new List <CalculationSeries>();

            var    vars = cs.GetDependentVariables();
            string msg  = cs.Table.TableName + " depends on :";

            TimeSeriesName cName = new TimeSeriesName(cs.Table.TableName);

            foreach (var vn in vars)
            {
                TimeSeriesName tn = new TimeSeriesName(vn, cName.interval);

                if (tn.GetTableName() == cs.Table.TableName)
                {
                    Logger.WriteLine(cs.Expression);
                    Logger.WriteLine("Warning: prevented recursive dependency " + tn.GetTableName());
                    continue;
                }
                var dependents = list.FindAll(x => x.Table.TableName == tn.GetTableName());

                foreach (var d in dependents)
                {
                    msg += d.Table.TableName + ",";
                }

                rval.AddRange(dependents);
            }

            Logger.WriteLine(msg);

            return(rval);
        }
Ejemplo n.º 2
0
        public void ReservoirContentsWithDatabase()
        {
            Logger.EnableLogger();
            var fn = FileUtility.GetTempFileName(".pdb");
            System.IO.File.Delete(fn);

            SQLiteServer svr = new SQLiteServer(fn);
            var db = new TimeSeriesDatabase(svr, Reclamation.TimeSeries.Parser.LookupOption.TableName,false);

            var c = new CalculationSeries("instant_karl_af");
            var path = Path.Combine(Globals.TestDataPath, "rating_tables");
            path = Path.Combine(path, "karl_af.txt");

            c.Expression = "FileRatingTable(instant_karl_fb,\""+path+"\")";
            c.TimeInterval = TimeInterval.Irregular;
            db.AddSeries(c);

            var fb = new Series("instant_karl_fb");
            fb.TimeInterval = TimeInterval.Irregular;
            db.AddSeries(fb);
            fb.Add("1-1-2013", 1);
            fb.Add("1-2-2013", 2);
            fb.Add("1-3-2013", 3);
            fb.Add("1-4-2013", 4);
            TimeSeriesImporter ti = new TimeSeriesImporter(db);
            ti.Import(fb,computeDependencies:true);// this should force a calculation...

            var af = db.GetSeriesFromTableName("instant_karl_af");
            Assert.NotNull(af, "Series not created");

            af.Read();

            Assert.AreEqual(4, af.Count);
            Assert.AreEqual(300, af[2].Value);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///  read computed value from hydromet and compare..
        ///
        /// </summary>
        /// <param name="s"></param>
        private void CompareToHydromet(CalculationSeries s)
        {
            if (s.Count == 0)
            {
                return;
            }
            // TO DO.. also check instant calcs.
            TimeSeriesName n = new TimeSeriesName(s.Table.TableName);

            if (s.TimeInterval == TimeInterval.Daily)
            {
                var tmp = HydrometDailySeries.Cache;
                HydrometDailySeries.Cache = null; // don't use cache..
                HydrometDailySeries h = new HydrometDailySeries(n.siteid, n.pcode);
                HydrometDailySeries.Cache = tmp;

                h.Read(s.MinDateTime, s.MaxDateTime);

                Series diff = Reclamation.TimeSeries.Math.Abs(h - s);

                var    pt        = Reclamation.TimeSeries.Math.MaxPoint(diff);
                double tolerance = 0.1;
                if (Array.IndexOf(new string[] { "sr", "wr" }, n.pcode) >= 0)
                {
                    tolerance = 1.0;
                }

                double delta    = h[0].Value - s[0].Value;
                double pctError = 0;
                if (System.Math.Abs(delta) > 0)
                {
                    pctError = System.Math.Abs(delta / h[0].Value);
                }

                if (pctError > tolerance)
                {
                    if (debugFileName == "")
                    {
                        debugFileName = "calc_errors.csv";
                        if (File.Exists(debugFileName))
                        {
                            File.Delete(debugFileName);
                        }
                        File.AppendAllText(debugFileName, "site,pcode,interval,openvms,linux,delta,percentError" + "\n");
                    }
                    if (h[0].Value != Point.MissingValueFlag)
                    {
                        string msg = n.siteid + "," + n.pcode + "," + n.interval + "," + h[0].Value + ", " + s[0].Value + ", " + delta + ", " + pctError;
                        Console.WriteLine(msg);
                        File.AppendAllText(debugFileName, msg + "\n");
                    }
                }
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Ejemplo n.º 4
0
        static bool s_appendToFile = false; // for output file.

        private static void WriteToHydrometDailyFile(string dailyFileName, CalculationSeries s)
        {
            TimeSeriesName n = new TimeSeriesName(s.Table.TableName);

            HydrometDailySeries.WriteToArcImportFile(s, n.siteid, n.pcode,
                                                     dailyFileName, s_appendToFile);

            if (!s_appendToFile)
            {
                s_appendToFile = true; // append after the first time.
            }
        }
Ejemplo n.º 5
0
        public void ImportDecodesAndProcessWithFlagLimits()
        {
            Logger.EnableLogger();
            FileUtility.CleanTempPath();
            var fn1 = FileUtility.GetTempFileName(".pdb");
            Console.WriteLine(fn1);
            var svr = new SQLiteServer(fn1);
            var db = new TimeSeriesDatabase(svr, Reclamation.TimeSeries.Parser.LookupOption.TableName,false);

            var tmpDir = CopyTestDecodesFileToTempDirectory("decodes_lapo.txt");

               var rtlapo = CreateTempRatingTable("lapo.csv", new double[] {3.50,3.54,3.55,5.54 },
                                             new double[] {1,2,3,10 });
            // set limits  gh: low=3.53, high 3.6,  rate of change/hour 1
               Quality q = new Quality(db);
               q.SaveLimits("instant_lapo_gh", 3.6, 3.53, 1.0);
               q.SaveLimits("instant_lapo_q", 5, 1.1, 0);

               var site = db.GetSiteCatalog();
               site.AddsitecatalogRow("lapo", "", "OR");
               db.Server.SaveTable(site);
            var c = new CalculationSeries("instant_lapo_q");
            c.SiteID = "lapo";
            c.Expression = "FileRatingTable(%site%_gh,\""+rtlapo+"\")";
            db.AddSeries(c);

            //SeriesExpressionParser.Debug = true;
            FileImporter import = new FileImporter(db);
            import.Import(tmpDir,RouteOptions.None,computeDependencies:true,searchPattern:"*.txt");
            db.Inventory();

            var s = db.GetSeriesFromTableName("instant_lapo_gh");
            var expectedFlags = new string[] { "", "", "", "+", "", "", "", "-" };
            for (int i = 0; i < s.Count; i++)
            {
                  Assert.AreEqual(expectedFlags[i], s[i].Flag, " flag not expected ");
            }

            s = db.GetSeriesFromTableName("instant_lapo_q");
            s.Read();
            Assert.IsTrue(s.Count > 0, "No flow data computed lapo");
            s.WriteToConsole(true);
             // computed flows should be: 2 2 2 10 2 2 1
            expectedFlags = new string[]{"","","","+","","","","-"}; //q>=1 and q<= 5
            for (int i = 0; i < s.Count; i++)
            {
                 Assert.AreEqual(expectedFlags[i], s[i].Flag.Trim()," Flag check on Flow (Q) ");
            }

            SeriesExpressionParser.Debug = false;
        }
Ejemplo n.º 6
0
        public void JacksonQU()
        {
            // daily data based on other daily data
            //DailyCalculator.
            Reclamation.TimeSeries.Parser.SeriesExpressionParser.Debug = true;
            var s = new CalculationSeries();
            s.Expression = "(jck_af-jck_af[t-1])/1.98347+jck_qd";
            s.TimeInterval = TimeInterval.Daily;
            s.Parser.VariableResolver = new HydrometVariableResolver();

            s.Calculate(new DateTime(2012,11,1),new DateTime(2012,11,15));

            Assert.AreEqual(298, s["2012-11-15"].Value, 0.01);
        }
Ejemplo n.º 7
0
        private static void CacheAllParametersForSite(CalculationSeries s, DateTime t1, DateTime t2)
        {
            // if we need instant data for this site
            // get all instant parameters in memory for future use.

            string tag = s.TimeInterval.ToString() + s.SiteID;

            if (visitedSites.Contains(tag))
            {
                return;
            }
            if (s.TimeInterval != TimeInterval.Daily)
            {
                return;
            }

            var t2a = t2.AddDays(1); // extra data when midnight next day is needed.


            if (s.Expression.IndexOf("instant") >= 0)
            { // Instant to Daily Calculation
                var tbl = s.TimeSeriesDatabase.GetSeriesCatalog("siteid = '" + s.SiteID + "' and timeinterval = 'Irrregular'");

                var pcodes = DataTableUtility.Strings(tbl, "", "Parameter");

                var query = s.SiteID + " " + String.Join("," + s.SiteID + " ", pcodes);
                var pairs = query.Split(',');
                //
                HydrometInstantSeries.Cache.Add(pairs, t1, t2a, HydrometHost.PNLinux, TimeInterval.Irregular);

                visitedSites.Add(tag);
                Console.WriteLine(s.SiteID + " added to the cache");
            }
            else if (s.Expression.IndexOf("instant") < 0)
            { // Daily to Daily type calculation..
                var tbl = s.TimeSeriesDatabase.GetSeriesCatalog("siteid = '" + s.SiteID + "' and timeinterval = 'Daily'");

                var pcodes = DataTableUtility.Strings(tbl, "", "Parameter");
                var query  = s.SiteID + " " + String.Join("," + s.SiteID + " ", pcodes);
                var pairs  = query.Split(',');

                //HydrometDailySeries.Cache = new HydrometDataCache(); // clear out and make new cache.
                HydrometDailySeries.Cache.Add(pairs, t1, t2a, HydrometHost.PNLinux, TimeInterval.Daily);

                visitedSites.Add(tag);
                Console.WriteLine(s.SiteID + " added to the cache");
            }
        }
Ejemplo n.º 8
0
        public void ValeQU()
        {
            // daily data based on other daily data
            //DailyCalculator.
            Reclamation.TimeSeries.Parser.SeriesExpressionParser.Debug = true;
            var s = new CalculationSeries();
            s.Expression = "(WAR_AF[t-2]-WAR_AF[t-3]+BEU_AF[t-2]-BEU_AF[t-3]+BUL_AF-BUL_AF[t-1])/1.98347+VALO_QD";
            s.TimeInterval = TimeInterval.Daily;
            s.Parser.VariableResolver = new HydrometVariableResolver();

            DateTime t = new DateTime(2012, 12, 6);
            s.Calculate(t,t);

            Assert.AreEqual(1, s.Count);
            Assert.AreEqual(573.75, s[t].Value, 0.01);
        }
Ejemplo n.º 9
0
 private static void LogStatusOfCalculation(string errorFileName, CalculationSeries s)
 {
     if (s.Count == 0 || s.CountMissing() > 0)
     {
         File.AppendAllText(errorFileName, "Error: " + s.Table.TableName + " = " + s.Expression + "\n");
         string msg = "\nDetails: " + s.Table.TableName + " = " + s.Expression + "\n";
         foreach (var x in s.Messages)
         {
             msg += "\n" + x;
         }
         Console.WriteLine(msg);
     }
     else
     {
         Console.WriteLine(" OK. ");
     }
 }
Ejemplo n.º 10
0
        public void MathMax()
        {
            //DailyCalculator.
            DateTime t = new DateTime(2012, 12, 6);
            ConstantSeries s1 = new ConstantSeries("s1", "aa", -1, TimeInterval.Daily);
            s1.TimeInterval = TimeInterval.Daily;
            Reclamation.TimeSeries.Parser.SeriesExpressionParser.Debug = true;
            var s = new CalculationSeries();
            s.Expression = "Max(s1,0)";
            s.TimeInterval = TimeInterval.Daily;
            s.Parser.VariableResolver = new VariableResolver();
            s.Parser.VariableResolver.Add("s1", s1);

            s.Calculate(t, t.AddDays(2));
            s.WriteToConsole();
            Assert.AreEqual(3, s.Count);
        }
Ejemplo n.º 11
0
        private void AddToDictionary(string key, CalculationSeries cs)
        {
            if (inputDictionary.ContainsKey(key))
            {
                var items = inputDictionary[key];

                if (!items.Contains(cs))
                {
                    items.Add(cs);
                }
            }
            else
            {
                var items = new List <CalculationSeries>();
                items.Add(cs);
                inputDictionary.Add(key, items);
            }
        }
Ejemplo n.º 12
0
        public void AddBug()
        {
            DateTime t1 = new DateTime(2013,1,1);
            var t2 = t1.AddDays(365);
            var fn = FileUtility.GetTempFileNameInDirectory(@"c:\temp\",".pdb");
            SQLiteServer svr = new SQLiteServer(fn);
            TimeSeriesDatabase db = new Reclamation.TimeSeries.TimeSeriesDatabase(svr,false);
            var s = new HydrometDailySeries("pal","af");
            s.Name = "pal_af";
            s.Read(t1,t2);
            db.AddSeries(s);

            var cs = new CalculationSeries("add_test");
            cs.Expression = "pal_af + pal_af";
            db.AddSeries(cs);

            cs = db.GetSeriesFromName("add_test") as CalculationSeries;
            cs.Calculate(t1, t2);

            cs = db.GetSeriesFromName("add_test") as CalculationSeries;
            cs.Read();

            Assert.IsTrue(cs.Count > 0);
        }
Ejemplo n.º 13
0
        public void Interpolate2DWithDatabase()
        {
            Logger.EnableLogger();
            var fn = FileUtility.GetTempFileName(".pdb");
            File.Delete(fn);

            SQLiteServer svr = new SQLiteServer(fn);
            var db = new TimeSeriesDatabase(svr,false );

            var c = new CalculationSeries("rir_q");
            var path = Path.Combine(TestData.DataPath, "rating_tables");
            path = Path.Combine(path, "rir_q.txt");

            c.Expression = "FileLookupInterpolate2D(rir_fb, rir_ra, \"" + path + "\")" +
                " + FileLookupInterpolate2D(rir_fb, rir_rb, \"" + path + "\")";
            c.TimeInterval = TimeInterval.Irregular;
            db.AddSeries(c);

            var fb = new Series("rir_fb");
            fb.TimeInterval = TimeInterval.Irregular;
            db.AddSeries(fb);
            fb.Add("6-1-2011", 5110.99);
            fb.Add("6-2-2011", 5111.31);
            fb.Add("6-3-2011", 5111.71);
            fb.Add("6-4-2011", 5112.09);

            var ra = new Series("rir_ra");
            ra.TimeInterval = TimeInterval.Irregular;
            ra.Add("6-1-2011", 2.1);
            ra.Add("6-2-2011", 1.29);
            ra.Add("6-3-2011", 1.29);
            ra.Add("6-4-2011", 1.29);
            db.AddSeries(ra);

            var rb = new Series("rir_rb");
            rb.TimeInterval = TimeInterval.Irregular;
            rb.Add("6-1-2011", 2.1);
            rb.Add("6-2-2011", 1.28);
            rb.Add("6-3-2011", 1.28);
            rb.Add("6-4-2011", 1.28);
            db.AddSeries(rb);

            TimeSeriesImporter ti = new TimeSeriesImporter(db);
            ti.Import(fb, computeDependencies: true);// this should force a calculation...

            var q = db.GetSeriesFromTableName("rir_q");
            Assert.NotNull(q, "Series not created");

            q.Read();

            /*
             * Flows from Hydromet
             * 6-1-2011, 1009.87
             * 6-2-2011, 602.24
             * 6-3-2011, 603.32
             * 6-4-2011, 604.34
             */

            Assert.AreEqual(4, q.Count);
            Assert.AreEqual(1009.87, System.Math.Round(q[0].Value, 2));
            Assert.AreEqual(603.32, System.Math.Round(q[2].Value, 2));
        }
Ejemplo n.º 14
0
        public Series GetSeries(TimeSeriesDatabaseDataSet.SeriesCatalogRow sr)
        {
            Series s   = null;// = new Series(sr, db);
            int    sdi = sr.id;

            try
            {
                if (sr.Provider.Trim() == "")
                {
                    sr.Provider = "Series";
                }

                // most common cases -- avoid reflection
                if (sr.Provider == "Series")
                {
                    s = new Series(db, sr);
                    //s.Table.TableName =
                    s.Icon = AssignIcon(sr.iconname);
                    s.TimeSeriesDatabase = this.db;
                    return(s);
                }
                // most common cases -- avoid reflection
                if (sr.Provider == "CalculationSeries")
                {
                    s      = new CalculationSeries(db, sr);
                    s.Icon = AssignIcon(sr.iconname);
                    s.TimeSeriesDatabase = this.db;
                    return(s);
                }


                if (seriesTypeList == null)
                {
                    seriesTypeList = new List <Type>();
                    var asmList = AppDomain.CurrentDomain.GetAssemblies();

                    foreach (Assembly item in asmList)
                    {
                        if (item.FullName.IndexOf("Reclamation.") < 0 &&
                            item.FullName.IndexOf("Pisces") < 0 &&
                            item.FullName.IndexOf("HDB") < 0)
                        {
                            continue;
                        }

                        var types = item.GetTypes().Where(x => x.BaseType == typeof(Series));
                        seriesTypeList.AddRange(types);
                    }
                }

                for (int i = 0; i < seriesTypeList.Count; i++)
                {
                    Type t = seriesTypeList[i];
                    if (t.Name == sr.Provider)
                    {
                        Type[] parmFaster  = new Type[] { typeof(TimeSeriesDatabase), typeof(SeriesCatalogRow) };
                        var    cInfoFaster = t.GetConstructor(parmFaster);

                        if (cInfoFaster != null)
                        {
                            object o = cInfoFaster.Invoke(new object[] { db, sr });
                            if (o is Series)
                            {
                                s = o as Series;
                            }
                            else
                            {
                                throw new InvalidOperationException("Provider '" + sr.Provider + "' is not a Series");
                            }
                        }

                        else
                        {
                            throw new InvalidOperationException("Can't find constructor for '" + sr.Provider + "'");
                        }

                        break;
                    }
                }
            }
            catch (Exception excep)
            {
                if (excep.InnerException != null)
                {
                    throw excep.InnerException;
                }
                throw new Exception(excep.Message + "\n" + sr.Provider);
            }

            if (s == null)
            {
//                Logger.WriteLine("No Class found for '"+sr.Provider +"'  ID= "+sr.id+" Name = "+sr.Name);
                s = new Series(db, sr);
            }
            s.Icon = AssignIcon(sr.iconname);
            s.TimeSeriesDatabase = this.db;
            return(s);
        }
Ejemplo n.º 15
0
        public void wrdo()
        {
            Logger.EnableLogger();
            var dir = FileUtility.GetTempPath();
            var testDir = Path.Combine(Globals.TestDataPath, "wrdo");
            FileUtility.CopyFiles(testDir, dir,"*.dat",true,true);

            var c = new Series("daily_wrdo_mm"); //needed to
            //c.Expression = "DailyAverage(instant_wrdo_obm,92)";
            c.TimeInterval = TimeInterval.Daily;
            c.Add("10-1-2014",43.27);
            c.Add("10-2-2014",48.53);
            c.Add("10-3-2014",52.33);
            c.Add("10-4-2014",54.63);
            c.Add("10-5-2014",53.97);
            c.Add("10-6-2014",55.22);
            c.Add("10-7-2014", 55.12);

            db.AddSeries(c);

            c = new CalculationSeries("daily_wrdo_mn");
            c.Expression = "DailyMin(instant_wrdo_obn)";
            c.TimeInterval = TimeInterval.Daily;
            db.AddSeries(c);

            c = new CalculationSeries("daily_wrdo_pc");
            c.Expression = "DailyMidnight(instant_wrdo_pc)";
            c.TimeInterval = TimeInterval.Daily;
            c.Add("10-5-2014", 8);
            db.AddSeries(c);

            c = new CalculationSeries("daily_wrdo_pp");
            c.Expression = "daily_wrdo_pc-daily_wrdo_pc[t-1]";
            c.TimeInterval = TimeInterval.Daily;
            c.Add("10-5-2014", 0);
            db.AddSeries(c);

            c = new CalculationSeries("daily_wrdo_pu");
            c.TimeSeriesDatabase = db;
            c.Expression = "DailyWaterYearRunningTotal(daily_wrdo_pp,daily_wrdo_pu)";
            c.TimeInterval = TimeInterval.Daily;

            c.Add("10-1-2014", 0);
            c.Add("10-2-2014", 0);
            c.Add("10-3-2014", 0);
            c.Add("10-4-2014", 0);
            c.Add("10-5-2014", 0);
            c.Add("10-6-2014", 0);
            db.AddSeries(c);
            c = db.GetSeriesFromTableName("daily_wrdo_pu");

            c.Properties.Set("DaysBack", "4");
            c.Properties.Save();
            c = new CalculationSeries("daily_wrdo_mx");
            c.Expression = "DailyMax(instant_wrdo_obx)";
            c.TimeInterval = TimeInterval.Daily;
            db.AddSeries(c);

            c = new CalculationSeries("daily_wrdo_ym");
            c.Expression = "DailyAverage(instant_wrdo_tp,92)";
            c.TimeInterval = TimeInterval.Daily;
            db.AddSeries(c);

            c = new CalculationSeries("daily_wrdo_wr");
            c.Expression = "DailySum(instant_wrdo_ws,92)/4.0";
            c.TimeInterval = TimeInterval.Daily;
            db.AddSeries(c);

            c = new CalculationSeries("daily_wrdo_sr");
            c.Expression = "DailySum(instant_wrdo_si,92)/4.0";
            c.TimeInterval = TimeInterval.Daily;
            db.AddSeries(c);

            c = new CalculationSeries("daily_wrdo_et");
            c.SiteID = "wrdo"; // needed for expression pre-processor with  %site%
            c.Expression = "DailyEtKimberlyPenman(daily_%site%_mm,daily_%site%_mn,daily_%site%_mx,daily_%site%_ym,daily_%site%_wr,daily_%site%_sr,42.0125,1243.58)";
            c.TimeInterval = TimeInterval.Daily;
            db.AddSeries(c);

            FileImporter fi = new FileImporter(db);
            fi.Import(dir,RouteOptions.None,true,true,"*.dat");

            var s = db.GetSeriesFromTableName("daily_wrdo_ym");
            s.Read();
            Assert.IsTrue(s.Count > 0, " DailyAverage(instant_wrdo_tp,92) failed!");

            s = db.GetSeriesFromTableName("daily_wrdo_et");
            s.Read();
            Assert.AreEqual(0.16,s["10-7-2014"].Value,0.01,"Error with ET");

            s = db.GetSeriesFromTableName("daily_wrdo_pu");
            s.Read();
            Assert.AreEqual(0,s["10-7-2014"].Value, 0.02, "Error with pu");
        }
Ejemplo n.º 16
0
 public void Test()
 {
     CalculationSeries      s  = new CalculationSeries();
     SeriesExpressionParser p  = s.Parser;
     VariableResolver       vr = p.VariableResolver;
 }
Ejemplo n.º 17
0
        private static DateTime AdjustStartingDateFromProperties(DateTime t1, DateTime t2, CalculationSeries s)
        {
            var t1a = t1;

            // for example daily QU calculations default back 7 days (when running previous day)
            if (s.Properties != null && s.Properties.Contains("DaysBack")) // && t2.Date == DateTime.Now.AddDays(-1).Date)
            {
                var daysBack = Convert.ToInt32(s.Properties.Get("DaysBack", "0"));
                t1a = t1a.AddDays(-daysBack);
            }

            if (s.Properties != null && s.Properties.Contains("WholeWaterYear"))
            {
                var whole = s.Properties.Get("WholeWaterYear", "False");
                if (whole != "False")
                {
                    // begin calculations october 1
                    Console.WriteLine("Using WholeWaterYear");
                    int yr = t2.Year;
                    if (t2.Month <= 9)
                    {
                        yr = t2.Year - 1;
                    }
                    t1a = new DateTime(yr, 10, 1);
                }
            }
            return(t1a);
        }
Ejemplo n.º 18
0
        public void ImportDecodesWithMissingGageHeight()
        {
            FileUtility.CleanTempPath();
            var fn1 = FileUtility.GetTempFileName(".pdb");
            Console.WriteLine(fn1);
            var svr = new SQLiteServer(fn1);
            var db = new TimeSeriesDatabase(svr, Reclamation.TimeSeries.Parser.LookupOption.TableName,false);
            Logger.EnableLogger();

            var tmpDir = CopyTestDecodesFileToTempDirectory("decodes_mabo_missing_gh.txt");
            var ratingTableFileName =CreateTempRatingTable("mabo.csv", 2.37, 2.8, x => (x*10));
            var c = new CalculationSeries("instant_mabo_q");
            c.Expression = "FileRatingTable(mabo_gh,\""+ratingTableFileName+"\")";
            db.AddSeries(c);

            FileImporter import = new FileImporter(db);
            import.Import(tmpDir, RouteOptions.Outgoing, computeDependencies: true,searchPattern:"*.txt");
            db.Inventory();

            var s = db.GetSeriesFromTableName("instant_mabo_q");

            s.Read();
            Assert.IsTrue(s.CountMissing() == 0);
            Assert.IsTrue(s.Count > 0, "No flow data computed");
        }
Ejemplo n.º 19
0
        public Series GetSeries(TimeSeriesDatabaseDataSet.SeriesCatalogRow sr)
        {
            if (db.Settings.ReadBoolean("VerboseLogging", false))
                Logger.EnableLogger();

            Series s = null;// = new Series(sr, db);
            int sdi = sr.id;
            try
            {

                if (sr.Provider.Trim() == "")
                    sr.Provider = "Series";

                // most common cases -- avoid reflection
                if (sr.Provider == "Series")
                {
                    s = new Series(db, sr);
                    //s.Table.TableName =
                    s.Icon = AssignIcon(sr.iconname);
                    s.TimeSeriesDatabase = this.db;
                    return s;
                }
                // most common cases -- avoid reflection
                if (sr.Provider == "CalculationSeries")
                {
                    s = new CalculationSeries(db, sr);
                    s.Icon = AssignIcon(sr.iconname);
                    s.TimeSeriesDatabase = this.db;
                    return s;
                }

                if (seriesTypeList == null)
                {
                    seriesTypeList = new List<Type>();
                    var asmList = AppDomain.CurrentDomain.GetAssemblies();

                    foreach (Assembly item in asmList)
                    {
                        if (item.FullName.IndexOf("Reclamation.") <0
                            && item.FullName.IndexOf("Pisces") <0
                            && item.FullName.IndexOf("HDB") <0 )
                            continue;

                        var types = item.GetTypes().Where(x => x.BaseType == typeof(Series));
                        seriesTypeList.AddRange(types);
                    }
                }

                for (int i = 0; i < seriesTypeList.Count; i++)
                {
                    Type t = seriesTypeList[i];
                    if (t.Name == sr.Provider)
                    {
                        Type[] parmFaster = new Type[] {  typeof(TimeSeriesDatabase), typeof(SeriesCatalogRow) };
                        var cInfoFaster = t.GetConstructor(parmFaster);

                        if (cInfoFaster != null)
                        {
                            object o = cInfoFaster.Invoke(new object[] {  db, sr });
                            if (o is Series)
                                s = o as Series;
                            else
                                throw new InvalidOperationException("Provider '" + sr.Provider + "' is not a Series");
                        }

                            else
                            {
                                throw new InvalidOperationException("Can't find constructor for '" + sr.Provider + "'");
                            }

                        break;
                    }

                }
            }
            catch(Exception excep)
            {
                if (excep.InnerException != null)
                {
                    Logger.WriteLine(excep.InnerException.Message);
                    throw excep.InnerException;
                }
                var msg = excep.Message + "\n" + sr.Provider;
                Logger.WriteLine(msg);
                throw new Exception(msg);
            }

            if (s == null)
            {
            //                Logger.WriteLine("No Class found for '"+sr.Provider +"'  ID= "+sr.id+" Name = "+sr.Name);
                s = new Series( db, sr);
            }
            s.Icon = AssignIcon(sr.iconname);
            s.TimeSeriesDatabase = this.db;
            return s;
        }
Ejemplo n.º 20
0
 public void Test()
 {
     CalculationSeries s = new CalculationSeries();
     SeriesExpressionParser p = s.Parser;
     VariableResolver vr = p.VariableResolver;
 }
        private static void AddSeries(string period, string scenario,
                                  TimeSeriesDatabase db, VariableResolver vr,
                                  string name, string equation, ModsimType mType)
        {
            if (name.Trim().ToLower() == "nan")
            {
            return;
            }

            if (name.Trim() == "")
            {
            Console.WriteLine("--- WARNING modsim Node Name is missing. Type = " +
                              mType.ToString());
            return;
            }

            CalculationSeries cs = new CalculationSeries(name);
            cs.TimeInterval = TimeInterval.Monthly;

            if (mType == ModsimType.Gain)
            {
            cs.Expression = string.Format("Max({0}, 0)", equation);
            }
            if (mType == ModsimType.Negative)
            {
            cs.Expression = string.Format("Abs(Min({0}, 0))", equation);
            }
            cs.TimeSeriesDatabase = db;
            cs.Parser.VariableResolver = vr;
            cs.Units = "cfs";
            db.AddSeries(cs);    // add series before calcualte to get an id assigned.
            cs.Calculate(); // Calculate also saves the data.

            SetSeriesDatesToBeginningOfMonth(cs);
            ConsolePrintSeriesNameAndCount(cs);
        }