Example #1
0
        public void WhenSumIsCalledItCalculatesTheSameAsTheIndividualResolutionTest()
        {
            // arrange
            const string serialNumber = "Interval";
            const int    counter      = 2421;
            var          start        = DateTime.Today.AddDays(-14);

            using (var target = new kWhStorage(serialNumber, BaseDir, counter, Precision.Wh))
            {
                var totalMinutes = (ulong)(DateTime.Now - start).TotalMinutes;
                for (ulong i = 0; i < totalMinutes; i++)
                {
                    target.SetValue(start.AddMinutes(i), (5 + (i * 2)), 1000, 10m);
                }

                // act
                target.GetValue(start);

                // assert
                var thisWeek       = PeriodBuilder.LastWeek();
                var thisWeekSeries = SeriesValueListBuilder.BuildSeries(thisWeek.From, thisWeek.To, SeriesResolution.Hour);
                target.GetRecords(thisWeek.From, thisWeek.To, Unit.M3, thisWeekSeries, false);
                var thisWeekSeriesSum = thisWeekSeries.Sum(s => s.Value);

                var thisWeekSum = target.Sum(thisWeek.From, thisWeek.To, Unit.M3);
                Assert.AreEqual(thisWeekSum, thisWeekSeriesSum);
            }
        }
Example #2
0
        public void WhenLastDayOfStorageContainsPartialDataShouldGiveCorrectSum()
        {
            var time = new DateTime(2012, 8, 17, 13, 20, 0);

            using (var storageProvider = new kWhStorage("12-13-001-076", BaseDir, 1, Precision.Wh))
            {
                for (int i = 0; i < 10; i++)
                {
                    storageProvider.SetValue(time.AddMinutes(i), (ulong)(50 * i), 1000m, 21m);
                }

                Assert.IsTrue(storageProvider.Sum(storageProvider.StartOfFile, storageProvider.EndOfFile, Unit.kWh) > 0);
            }
        }
Example #3
0
        public void GetSumTest()
        {
            // arrange
            const string serialNumber = "Serial";
            const int    counter      = 1;

            using (var target = new kWhStorage(serialNumber, BaseDir, counter, Precision.Wh))
            {
                target.SetValue(DateTime.Now.AddDays(-8), 50, 1000, 1);
                target.SetValue(DateTime.Now.AddDays(-7), 100, 1000, 1);
                var begin = DateTime.Today.AddDays((DateTime.Today.Day - 1) * -1);
                var end   = new DateTime(DateTime.Now.Year, DateTime.Now.Month,
                                         DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month));

                // act
                var result = target.Sum(begin, end, Unit.kWh);

                // assert
                Assert.IsNotNull(result);
            }
        }
Example #4
0
        public void SumTest()
        {
            const string serialNumber = "Serial";
            const int    counter      = 1;
            decimal      expected;
            decimal      actual;

            using (var target = new kWhStorage(serialNumber, BaseDir, counter, Precision.Wh))
            {
                target.SetValue(DateTime.Today.AddDays(-1), 50, 5, 2);
                target.SetValue(DateTime.Today.AddDays(-1).AddMinutes(120), 100, 5, 2);

                var period = PeriodBuilder.Yesterday();
                var begin  = period.From;
                var end    = period.To;

                expected = 10000; // ((100 / 5) * 1000) - ((50 / 5) * 1000)
                actual   = target.Sum(begin, end, Unit.kWh);
            }
            Assert.AreEqual(expected, actual);
        }