public void CalcParameterLoggerTest()
        {
            CalcParameters cp = CalcParameters.GetNew();

            cp.SetStartDate(2017, 1, 1);
            cp.SetEndDate(2018, 1, 1);
            cp.Enable(CalcOption.ActivationsPerHour);
            using (WorkingDir wd = new WorkingDir(Utili.GetCurrentMethodAndClass()))
            {
                SqlResultLoggingService srls = new SqlResultLoggingService(wd.WorkingDirectory);
                CalcParameterLogger     cpl  = new CalcParameterLogger(srls);
                cpl.Run(Constants.GeneralHouseholdKey, cp);

                GC.Collect();
                GC.WaitForPendingFinalizers();

                CalcParameters cp2 = cpl.Load();
                GC.Collect();
                GC.WaitForPendingFinalizers();

                string s1 = JsonConvert.SerializeObject(cp, Formatting.Indented);
                string s2 = JsonConvert.SerializeObject(cp2, Formatting.Indented);
                s1.Should().Be(s2);
                cp2.IsSet(CalcOption.ActivationsPerHour).Should().BeTrue();
                Assert.NotNull(cp2);
                wd.CleanUp();
            }
        }
        public void EnergyStorageSignalTests2()
        {
            CalcParameters cp = CalcParameters.GetNew();

            cp.DummyCalcSteps = 0;
            //CalcLoadType clt = new CalcLoadType("clt",  "power", "sum", 1, true, Guid.NewGuid().ToStrGuid());
            CalcVariable cv = new CalcVariable("myvariable", Guid.NewGuid().ToStrGuid(), 0, "House", Guid.NewGuid().ToStrGuid(),
                                               Constants.HouseKey);
            CalcEnergyStorageSignal cess   = new CalcEnergyStorageSignal("blub", 100, 50, 2, cv, Guid.NewGuid().ToStrGuid());
            List <double>           values = new List <double>();
            int i = 0;

            TestCess(cess, new TimeStep(i++, cp), 100, 100, values);
            TestCess(cess, new TimeStep(i++, cp), 100, 5, values);
            TestCess(cess, new TimeStep(i++, cp), 100, 100, values);
            TestCess(cess, new TimeStep(i++, cp), 100, 5, values);
            TestCess(cess, new TimeStep(i++, cp), 100, 100, values);
            TestCess(cess, new TimeStep(i++, cp), 100, 5, values);
            TestCess(cess, new TimeStep(i++, cp), 100, 100, values);
            TestCess(cess, new TimeStep(i++, cp), 100, 5, values);
            TestCess(cess, new TimeStep(i++, cp), 100, 100, values);
            TestCess(cess, new TimeStep(i++, cp), 100, 5, values);
            TestCess(cess, new TimeStep(i++, cp), 100, 100, values);
            TestCess(cess, new TimeStep(i++, cp), 100, 5, values);
            TestCess(cess, new TimeStep(i++, cp), 100, 100, values);
            TestCess(cess, new TimeStep(i, cp), 100, 5, values);
        }
        public void CalcAffordanceActivateTest0Percent()
        {
            Logger.Info("hi");
            var       calcParameters = CalcParameters.GetNew();
            const int stepcount      = 150;

            SetupProbabilityTest(out var aff, out var lt, out var cd, out var loc, stepcount, 0);
            var      trueCount = 0;
            TimeStep ts1       = new TimeStep(0, 0, true);
            var      result    = aff.IsBusy(ts1, loc, "name");

            result.Should().BeFalse();
            const int resultcount = stepcount - 20;

            for (var i = 0; i < resultcount; i++)
            {
                for (var j = 0; j < stepcount; j++)
                {
                    TimeStep ts = new TimeStep(j, calcParameters);
                    cd.SetIsBusyForTesting(ts, false, lt);
                    cd.IsBusyForLoadType[lt][ts.InternalStep] = false;
                }
                TimeStep ts2 = new TimeStep(i, calcParameters);
                aff.IsBusy(ts2, loc, "name");
                //var variableOperator = new VariableOperator();
                aff.Activate(ts2, "blub", loc, out var _);
                if (cd.GetIsBusyForTesting(ts2, lt))
                {
                    trueCount++;
                }
            }

            Logger.Info("Truecount: " + trueCount);
            trueCount.Should().BeApproximately(0, 0.1);
        }
Ejemplo n.º 4
0
 public static CalcParameters MakeGoodDefaults()
 {
     CalcParameters cp = CalcParameters.GetNew();
     cp.SetStartDate(2018, 1, 1).SetEndDate(2018, 12, 31);
     cp.SetInternalTimeResolution(new TimeSpan(0, 1, 0)).SetExternalTimeResolution(new TimeSpan(0, 1, 0));
     cp.SetCsvCharacter(";");
     cp.SetLoadTypePriority(LoadTypePriority.RecommendedForHouses);
     cp.DisableShowSettlingPeriod();
     cp.SetSettlingDays(3);
     cp.SetRandomSeed(17,false);
     cp.SetWriteExcelColumn(false);
     cp.SetAffordanceRepetitionCount(3);
     cp.CheckSettings();
     return cp;
 }
Ejemplo n.º 5
0
 public CalcParameters MakeCalculationParametersFromConfig([NotNull] CalcStartParameterSet csps, bool forceRandom)
 {
     CalcParameters cp = CalcParameters.GetNew();
     cp.LoadtypesToPostprocess = csps.LoadTypesToProcess;
     cp.SetDeleteDatFiles(csps.DeleteDatFiles);
     cp.SetWriteExcelColumn (csps.WriteExcelColumn);
     cp.SetManyOptionsWithClear(csps.CalcOptions);
     FileFactoryAndTrackerDummy fftd = new FileFactoryAndTrackerDummy();
     var container =PostProcessingManager.RegisterEverything(csps.ResultPath,csps.CalculationProfiler, fftd);
     using (var scope = container.BeginLifetimeScope())
     {
         var odm = scope.Resolve<OptionDependencyManager>();
         odm.EnableRequiredOptions(cp.Options);
     }
     cp.SetShowSettlingPeriod(csps.ShowSettlingPeriod);
     cp.SetRandomSeed(csps.SelectedRandomSeed, forceRandom);
     cp.SetCsvCharacter(csps.CsvCharacter);
     cp.SetStartDate(csps.OfficialSimulationStartTime);
     cp.SetEndDate(csps.OfficialSimulationEndTime.AddDays(1));
     cp.SetInternalTimeResolution(csps.InternalTimeResolution);
     cp.SetExternalTimeResolution(csps.ExternalTimeResolution);
     cp.SetLoadTypePriority(csps.LoadTypePriority);
     cp.SetSettlingDays(csps.SettlingDays);
     cp.SetAffordanceRepetitionCount(csps.AffordanceRepetitionCount);
     cp.DeviceProfileHeaderMode = csps.DeviceProfileHeaderMode;
     cp.IgnorePreviousActivitesWhenNeeded = csps.IgnorePreviousActivitiesWhenNeeded;
     cp.TransportationEnabled = csps.TransportationEnabled;
     if (cp.TransportationEnabled && csps.CalcTarget.CalcObjectType == CalcObjectType.House) {
         if (csps.ChargingStationSet != null) {
             throw new LPGException("trying to set transportation options on a house. that won't work.");
         }
         if (csps.TransportationDeviceSet != null)
         {
             throw new LPGException("trying to set transportation options on a house. that won't work.");
         }
         if (csps.TravelRouteSet != null)
         {
             throw new LPGException("trying to set transportation options on a house. that won't work.");
         }
     }
     if (cp.TransportationEnabled && csps.CalcTarget.CalcObjectType == CalcObjectType.ModularHousehold)
     {
         if (csps.ChargingStationSet == null)
         {
             throw new LPGException("Trying to set transportation options on a household without charging station set. That won't work.");
         }
         if (csps.TransportationDeviceSet == null)
         {
             throw new LPGException("Trying to set transportation options on a household without transportation device set. That won't work.");
         }
         if (csps.TravelRouteSet != null)
         {
             throw new LPGException("trying to set transportation options on a house. that won't work.");
         }
     }
     cp.CheckSettings();
     //transport mode
     /*if (csps.TransportationDeviceSet != null || csps.TravelRouteSet != null) {
         cp.SetTransportMode(true);
         if (csps.TransportationDeviceSet == null ) {
             throw new DataIntegrityException("Only a transportation device set was defined, but not a travel route set. This can't work.");
         }
         if (csps.TravelRouteSet == null)
         {
             throw new DataIntegrityException("Only a travel route set was defined, but not a transportation device set. This can't work.");
         }
     }*/
     return cp;
 }