Exemple #1
0
 private void MakeSubAffordances([NotNull] DtoCalcLocationDict locations, [NotNull] CalcVariableRepository variableRepository,
                                 [NotNull] CalcAffordanceDto affordancedto, [NotNull] CalcAffordance caff)
 {
     foreach (CalcSubAffordanceDto sdto in affordancedto.SubAffordance)
     {
         CalcLocation      subaffLocation     = locations.GetCalcLocationByGuid(sdto.LocGuid);
         List <CalcDesire> satisfactionValues = MakeCalcDesires(sdto.Satisfactionvalues);
         var varOps = MakeVariableOps(locations, sdto.VariableOps, variableRepository);
         //subaffordances have no time limits
         BitArray          isBusySub = new BitArray(_calcRepo.CalcParameters.InternalTimesteps, false);
         CalcSubAffordance csuf      = new CalcSubAffordance(sdto.Name,
                                                             subaffLocation,
                                                             satisfactionValues,
                                                             sdto.MiniumAge, sdto.MaximumAge,
                                                             sdto.Delaytimesteps,
                                                             sdto.PermittedGender,
                                                             sdto.AffCategory,
                                                             sdto.IsInterruptable,
                                                             sdto.IsInterrupting,
                                                             caff,
                                                             varOps,
                                                             sdto.Weight,
                                                             sdto.SourceTrait,
                                                             sdto.Guid, isBusySub, variableRepository, caff.BodilyActivityLevel, _calcRepo);
         caff.SubAffordances.Add(csuf);
     }
 }
        public void TestInterruptionTest()
        {
            using var wd = new WorkingDir(Utili.GetCurrentMethodAndClass());
            DateTime       startdate      = new DateTime(2018, 1, 1);
            DateTime       enddate        = startdate.AddMinutes(100);
            CalcParameters calcParameters = CalcParametersFactory.MakeGoodDefaults().SetStartDate(startdate).SetEndDate(enddate).SetSettlingDays(0).EnableShowSettlingPeriod().DisableShowSettlingPeriod().SetAffordanceRepetitionCount(1);
            //var r = new Random(1);
            //var nr = new NormalRandom(0, 1, r);
            var desire1 = new CalcDesire("desire1", 1, 0.5m, 4, 1, 1, 60, -1, null, "", "");
            var lt      = new CalcLoadType("calcLoadtype1", "kwh", "W", 1, true, Guid.NewGuid().ToStrGuid());

            //var variableOperator = new VariableOperator();
            using var fft = new FileFactoryAndTracker(wd.WorkingDirectory, "blub", wd.InputDataLogger);
            var key = new HouseholdKey("HH1");

            wd.InputDataLogger.AddSaver(new ActionEntryLogger(wd.SqlResultLoggingService));
            wd.InputDataLogger.AddSaver(new ColumnEntryLogger(wd.SqlResultLoggingService));
            wd.InputDataLogger.AddSaver(new HouseholdKeyLogger(wd.SqlResultLoggingService));
            wd.InputDataLogger.AddSaver(new ResultFileEntryLogger(wd.SqlResultLoggingService));
            wd.InputDataLogger.AddSaver(new LocationEntryLogger(wd.SqlResultLoggingService));
            fft.RegisterHousehold(key, "hh1", HouseholdKeyType.Household, "desc", null, null);
            fft.RegisterHousehold(Constants.GeneralHouseholdKey, "General", HouseholdKeyType.General, "Desc", null, null);
            //SqlResultLoggingService srls = new SqlResultLoggingService(wd.WorkingDirectory);
            DateStampCreator dsc = new DateStampCreator(calcParameters);

            using OnlineLoggingData old = new OnlineLoggingData(dsc, wd.InputDataLogger, calcParameters);
            using var lf = new LogFile(calcParameters, fft);
            var           cloc         = new CalcLocation("loc1", Guid.NewGuid().ToStrGuid());
            BitArray      isSick       = new BitArray(calcParameters.InternalTimesteps);
            BitArray      isOnVacation = new BitArray(calcParameters.InternalTimesteps);
            CalcPersonDto calcPerson   = CalcPersonDto.MakeExamplePerson();
            var           odap         = new OnlineDeviceActivationProcessor(old, calcParameters, fft);
            Random        rnd          = new Random();
            NormalRandom  nr           = new NormalRandom(0, 1, rnd);

            using CalcRepo calcRepo = new CalcRepo(lf: lf, odap: odap, calcParameters: calcParameters, rnd: rnd, normalRandom: nr, onlineLoggingData: old);
            var cp = new CalcPerson(calcPerson, cloc, isSick, isOnVacation, calcRepo);

            //"blub", 1, 1, r,20, PermittedGender.Male, lf, "HH1", cloc,"traittag","hhname0", calcParameters,isSick, Guid.NewGuid().ToStrGuid());
            cp.PersonDesires.AddDesires(desire1);
            cp.SicknessDesires.AddDesires(desire1);
            var deviceLoads = new List <CalcDeviceLoad>
            {
                new CalcDeviceLoad("devload1", 1, lt, 100, 1)
            };
            var           devCategoryGuid = Guid.NewGuid().ToStrGuid();
            CalcDeviceDto cdd1            = new CalcDeviceDto("cdevice1", devCategoryGuid, key,
                                                              OefcDeviceType.Device, "category", "", Guid.NewGuid().ToStrGuid(),
                                                              cloc.Guid, cloc.Name);
            var           cdev1 = new CalcDevice(deviceLoads, cloc, cdd1, calcRepo);
            CalcDeviceDto cdd2  = new CalcDeviceDto("cdevice2", devCategoryGuid, key,
                                                    OefcDeviceType.Device, "category", "", Guid.NewGuid().ToStrGuid(),
                                                    cloc.Guid, cloc.Name);
            var           cdev2 = new CalcDevice(deviceLoads, cloc, cdd2, calcRepo);
            CalcDeviceDto cdd3  = new CalcDeviceDto("cdevice3", devCategoryGuid, key,
                                                    OefcDeviceType.Device, "category", "", Guid.NewGuid().ToStrGuid(),
                                                    cloc.Guid, cloc.Name);
            var cdev3 = new CalcDevice(deviceLoads, cloc, cdd3, calcRepo);

            cloc.Devices.Add(cdev1);
            cloc.Devices.Add(cdev2);
            cloc.Devices.Add(cdev3);
            var daylight = new BitArray(100);

            daylight.SetAll(true);
            DayLightStatus dls = new DayLightStatus(daylight);

            double[] newValues = { 1, 1, 1.0, 1, 1, 1, 1, 1 };
            var      newList   = new List <double>(newValues);
            var      cprof     = new CalcProfile("cp1", Guid.NewGuid().ToStrGuid(), newList, ProfileType.Relative, "bla");

            var desires = new List <CalcDesire>
            {
                desire1
            };
            var color = new ColorRGB(255, 0, 0);
            CalcVariableRepository crv = new CalcVariableRepository();
            BitArray isBusy            = new BitArray(calcParameters.InternalTimesteps, false);
            var      aff1 = new CalcAffordance("aff1", cprof, cloc, false, desires, 1, 100,
                                               PermittedGender.All, false, 0, color, "aff category", true, false,
                                               new List <CalcAffordanceVariableOp>(), new List <VariableRequirement>(),
                                               ActionAfterInterruption.GoBackToOld, "bla", 100, false, "",
                                               Guid.NewGuid().ToStrGuid(), crv
                                               , new List <CalcAffordance.DeviceEnergyProfileTuple>(), isBusy, BodilyActivityLevel.Low, calcRepo);

            aff1.AddDeviceTuple(cdev1, cprof, lt, 0, calcParameters.InternalStepsize, 1, 1);
            cloc.AddAffordance(aff1);
            var aff2 = new CalcAffordance("aff2", cprof, cloc, false, desires, 1, 100,
                                          PermittedGender.All, false, 0, color, "aff category", false, false,
                                          new List <CalcAffordanceVariableOp>(), new List <VariableRequirement>(),
                                          ActionAfterInterruption.GoBackToOld, "bla", 100, false, "", Guid.NewGuid().ToStrGuid(), crv
                                          , new List <CalcAffordance.DeviceEnergyProfileTuple>(), isBusy, BodilyActivityLevel.Low, calcRepo);

            aff2.AddDeviceTuple(cdev2, cprof, lt, 0, calcParameters.InternalStepsize, 1, 1);
            cloc.AddAffordance(aff2);
            var clocs = new List <CalcLocation>
            {
                cloc
            };
            BitArray isBusySub         = new BitArray(calcParameters.InternalTimesteps, false);
            var      calcSubAffordance = new CalcSubAffordance("subaffname", cloc, desires, 0,
                                                               100, 1,
                                                               PermittedGender.All, "subaff", false, true,
                                                               aff1, new List <CalcAffordanceVariableOp>(), 100,
                                                               "testing", Guid.NewGuid().ToStrGuid(), isBusySub, crv, BodilyActivityLevel.Low,
                                                               calcRepo);

            aff2.SubAffordances.Add(calcSubAffordance);
            calcSubAffordance.SetDurations(2);
            var persons = new List <CalcPerson>
            {
                cp
            };

            for (var i = 0; i < 100; i++)
            {
                TimeStep ts = new TimeStep(i, 0, true);
                cp.NextStep(ts, clocs, dls, new HouseholdKey("hh1"), persons, 1);
            }

            //wd.CleanUp();
        }