コード例 #1
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);
        }
コード例 #2
0
ファイル: PlantController.cs プロジェクト: Epstone/mypvlog
        public ActionResult View(int id)
        {
            var plant = _plantRepository.GetPlantById( id );
              var kwhRepository = new KwhRepository();

              // build view model
              var plantModel = PlantHomeModel.Create( plant );
              //var today =Utils.GetTodaysDate();
              var today = Utils.GetTodaysDate();
              plantModel.SummaryTable = new PlantSummaryTableModel();

              plantModel.SummaryTable.Today = _dataProvider.GetkwhAndMoneyPerTimeFrame( today, today.AddDays( 1 ), id, E_TimeMode.day );
              plantModel.SummaryTable.ThisMonth = _dataProvider.GetkwhAndMoneyPerTimeFrame( Utils.FirstDayOfMonth(), Utils.FirstDayNextMonth(), id, E_TimeMode.month );
              plantModel.SummaryTable.ThisYear = _dataProvider.GetkwhAndMoneyPerTimeFrame( Utils.FirstDayOfYear(), Utils.FirstDayNextYear(), id, E_TimeMode.year );

              //is user allowed to edit the plant?
              plantModel.HeaderModel = GetHeaderModel( plant );

              return View( plantModel );
        }