コード例 #1
0
ファイル: MyController.cs プロジェクト: Epstone/mypvlog
        protected override void Initialize(System.Web.Routing.RequestContext requestContext)
        {
            base.Initialize(requestContext);

              if (this.MembershipService == null) this.MembershipService = new AccountMembershipService();

              if (this._measureRepository == null) _measureRepository = new MeasureRepository();
              if (this._plantRepository == null) _plantRepository = new PlantRepository();
              if (this._kwhRepository == null) this._kwhRepository = new KwhRepository();
              if (this._dataProvider == null) this._dataProvider = new UiDataProvider();
        }
コード例 #2
0
        public void CalculateKwh_by_dayToDBTest()
        {
            var plantDb = new PlantRepository();
              int testPlantId = DatabaseHelpers.CreatePlantGetId();
              int privateInverterID = DatabaseHelpers.CreateInverter(testPlantId);
              int publicInverterId = plantDb.GetAllInvertersByPlant(testPlantId).First().PublicInverterId;

              var today = Utils.GetTodaysDate();
              var tomorow = today.AddDays(1);
              var dayAfterTomorow = tomorow.AddDays(1);

              //time frame for kwh calculation
              var timeFrameStart = Utils.CropHourMinuteSecond(today);
              var timeFrameEnd = timeFrameStart.AddDays(3);

              //time frame of test measures
              var todayStart = today.AddHours(8);
              var todayEnd = todayStart.AddHours(10);

              var tomorowStart = todayStart.AddDays(1);
              var tomorowEnd = tomorowStart.AddHours(8);

              var dayAfterTomorowStart = tomorowStart.AddDays(1);
              var dayAfterTomorowEnd = dayAfterTomorowStart.AddHours(8);

              //create test data and merge into one list
              var measureList = BigMama.GetMeasureList(todayStart, todayEnd, 1000, privateInverterID);
              var measureList_tomorow = BigMama.GetMeasureList(tomorowStart, tomorowEnd, 2000, privateInverterID);
              var measureList_dayAfterTomorow = BigMama.GetMeasureList(dayAfterTomorowStart, dayAfterTomorowEnd, 3000, privateInverterID);

              measureList.AddRange(measureList_tomorow);
              measureList.AddRange(measureList_dayAfterTomorow);

              var measureDb = new MeasureRepository();

              //Add test data to database

              measureDb.StartTransaction();
              measureList.ForEach(y=> _measureRepository.InsertMeasure(y));
              measureDb.CommitTransaction();

              //calculate kwh for each day and store in database
              var mgm = new MeasureManagement();
              mgm.ReCalculateKwh_by_dayToDB(timeFrameStart, timeFrameEnd, testPlantId);

              //read the calculated kwh days from the db
              var kwhDb = new KwhRepository();
              var actual = kwhDb.GetDayKwhByDateRange(timeFrameStart, timeFrameEnd, testPlantId);

              //Check the result from the db
              Assert.AreEqual(3, actual.Count);
              Assert.AreEqual(10.0, actual.GetKwh(today, publicInverterId).Value);
              Assert.AreEqual(16.0, actual.GetKwh(tomorow, publicInverterId).Value);
              Assert.AreEqual(24.0, actual.GetKwh(dayAfterTomorow, publicInverterId).Value);

              //check that removing all measures does not delete the day_kwh values
              //truncate measure table and refill with the DaT values
              _testDb.TruncateMinuteWiseMeasures();

              measureDb.StartTransaction();
              measureList_dayAfterTomorow.ForEach(y=>  measureDb.InsertMeasure(y));
              measureDb.CommitTransaction();

              //recalculate the kwh_days
              mgm.ReCalculateKwh_by_dayToDB(timeFrameStart, timeFrameEnd, testPlantId);
              var actual_2 = kwhDb.GetDayKwhByDateRange(timeFrameStart, timeFrameEnd, testPlantId);

              //results should be equal with those above
              Assert.AreEqual(3, actual.Count);
              Assert.AreEqual(10.0, actual.GetKwh(today, publicInverterId).Value);
              Assert.AreEqual(16.0, actual.GetKwh(tomorow, publicInverterId).Value);
              Assert.AreEqual(24.0, actual.GetKwh(dayAfterTomorow, publicInverterId).Value);
        }
コード例 #3
0
        public void IsPlantOnlineTest()
        {
            var offlinePlant = DatabaseHelpers.CreatePlantWithOneInverter();
              var onlinePlant = DatabaseHelpers.CreatePlantWithOneInverter();
              var plantWithoutInverter = DatabaseHelpers.CreatePlantGetId();

              // create and store measure for online repository
              I_MeasureRepository measureRepo = new MeasureRepository();

              for (int i = 0; i < 5; i++)
              {
            measureRepo.InsertMeasure(new Measure()
            {
              DateTime = DateTime.Now.AddMinutes(i),
              PrivateInverterId = onlinePlant.InverterId,
              OutputWattage = 41234
            });
              }

              _plantRepository.UpdatePlantOnlineStatus();

              //check on/offline state of plants
              Assert.IsFalse(_plantRepository.GetPlantById(offlinePlant.PlantId).IsOnline);
              Assert.IsTrue(_plantRepository.GetPlantById(onlinePlant.PlantId).IsOnline);
              Assert.IsFalse(_plantRepository.GetPlantById(plantWithoutInverter).IsOnline);
        }
コード例 #4
0
ファイル: TestDataApp.cs プロジェクト: Epstone/mypvlog
        private void InsertToTarget(List<Measure> result, string targetConStr)
        {
            DateTime startDate = GetDay(dtp_target_From.Value);
            DateTime endDate = GetDay(dtp_Target_To.Value).AddDays(1);

            DateTime countDate = startDate;

            var db = new MeasureRepository(targetConStr, targetConStr);

            while (countDate < endDate)
            {
                foreach (var measure in result)
                {
                    var oldDate = measure.DateTime;
                    var newDate = new DateTime(countDate.Year, countDate.Month, countDate.Day, oldDate.Hour, oldDate.Minute, oldDate.Second);
                    measure.DateTime = newDate;

                    db.InsertMeasure(measure);
                }
                //increase countdate
                countDate = countDate.AddDays(1);
            }
        }