Beispiel #1
0
        public void TestMergeMassBalance()
        {
            SQLiteServer       pDB = new SQLiteServer(path);
            TimeSeriesDatabase DB  = new TimeSeriesDatabase(pDB);

            // Reads input data required by the calculation
            Series daily   = DB.GetSeriesFromName("CHEI_QD");
            Series monthly = DB.GetSeriesFromName("CHEI_QM");

            daily.Read();
            monthly.Read();

            // disaggregate and merge
            Series infilled = Math.RMSEInterp(daily, monthly);

            Math.MergeCheckMassBalance(daily, infilled);

            // generate series of monthly volumes only for months with a computed value,
            // these will be compared to the observed monthly
            Series partialMonthlyEstimated = new Series();

            for (int i = 0; i < infilled.Count; i++)
            {
                Point p = infilled[i];

                // Gets the data for the month
                int      numDays = DateTime.DaysInMonth(p.DateTime.Year, p.DateTime.Month);
                DateTime t1      = new DateTime(p.DateTime.Year, p.DateTime.Month, 1);
                DateTime t2      = new DateTime(p.DateTime.Year, p.DateTime.Month, numDays);

                if (p.Flag == PointFlag.Computed && partialMonthlyEstimated.IndexOf(t1) < 0)
                {
                    partialMonthlyEstimated.Add(t1, Math.Sum(infilled.Subset(t1, t2)) * 1.98347);
                }
            }

            // check observed against infilled for months where data was infilled
            double diff = 0.0;

            for (int i = 0; i < partialMonthlyEstimated.Count; i++)
            {
                DateTime estDate = partialMonthlyEstimated[i].DateTime;
                if (monthly.IndexOf(estDate) > 0)
                {
                    diff += (monthly[estDate].Value - partialMonthlyEstimated[estDate].Value);
                }
            }

            Assert.IsTrue(diff < 0.01, "UofI merge mass balance failed by: " + diff);
        }