Beispiel #1
0
        public CalcVariableDto RegisterVariableIfNotRegistered([NotNull] Variable variable, [NotNull] Location location,
                                                               [NotNull] HouseholdKey householdKey,
                                                               [NotNull] LocationDtoDict locationDict)
        {
            StrGuid locGuid = locationDict.LocationDict[location].Guid;

            return(RegisterVariableIfNotRegistered(variable, location.PrettyName, locGuid,
                                                   householdKey));
        }
Beispiel #2
0
        public List <CalcLocationDto> MakeCalcLocations([NotNull][ItemNotNull] List <Location> locations,
                                                        [NotNull] HouseholdKey householdKey, EnergyIntensityType et,
                                                        [NotNull] Dictionary <CalcLocationDto, List <IAssignableDevice> > deviceLocationDict,
                                                        [NotNull][ItemNotNull] ObservableCollection <DeviceAction> deviceActions,
                                                        [NotNull] LocationDtoDict locdict,
                                                        [ItemNotNull][NotNull] List <DeviceCategoryDto> deviceCategoryDtos)
        {
            var locs = new List <CalcLocationDto>();

            foreach (var t in locations)
            {
                // loc anlegen
                var cloc = new CalcLocationDto(t.Name, t.IntID, Guid.NewGuid().ToStrGuid());
                foreach (var locdev in t.LocationDevices)
                {
                    RealDevice rd;
                    if (locdev.Device == null)
                    {
                        throw new LPGException("Device was null");
                    }
                    if (locdev.Device.AssignableDeviceType == AssignableDeviceType.DeviceCategory)
                    {
                        rd = _picker.PickDeviceFromCategory((DeviceCategory)locdev.Device, et,
                                                            deviceActions);
                    }
                    else
                    {
                        rd = (RealDevice)locdev.Device;
                    }

                    var deviceName = CalcAffordanceFactory.FixAffordanceName(rd.Name, _calcParameters.CSVCharacter);
                    if (rd.DeviceCategory == null)
                    {
                        throw new LPGException("Device Category was null");
                    }

                    var devcatdto    = deviceCategoryDtos.Single(x => x.FullCategoryName == rd.DeviceCategory.FullPath);
                    var clightdevice = new CalcDeviceDto(deviceName, devcatdto.Guid,
                                                         householdKey, OefcDeviceType.Light, rd.DeviceCategory.FullPath,
                                                         string.Empty, Guid.NewGuid().ToStrGuid(), cloc.Guid, cloc.Name);
                    clightdevice.AddLoads(CalcDeviceDtoFactory.MakeCalcDeviceLoads(rd, _calcLoadTypeDict));
                    cloc.AddLightDevice(clightdevice);
                }
                deviceLocationDict.Add(cloc, new List <IAssignableDevice>());
                locs.Add(cloc);
                locdict.LocationDict.Add(t, cloc);
            }
            return(locs);
        }
Beispiel #3
0
        public List <CalcAffordanceDto> SetCalcAffordances([NotNull][ItemNotNull] IEnumerable <CalcLocationDto> locs,
                                                           [NotNull] TemperatureProfile temperatureProfile,
                                                           [NotNull] CalcLoadTypeDtoDictionary ltdict,
                                                           [NotNull] GeographicLocation geographicLocation,
                                                           [NotNull] Random rnd,
                                                           int timeStepsPerHour, TimeSpan internalStepSize,
                                                           [NotNull][ItemNotNull] List <VacationTimeframe> vacationTimeframes, [NotNull] string holidayKey,
                                                           [NotNull][ItemNotNull] ObservableCollection <DeviceAction> deviceActions,
                                                           [NotNull] Dictionary <CalcLocationDto, List <AffordanceWithTimeLimit> > affordanceDict,
                                                           [NotNull] LocationDtoDict locDict,
                                                           [NotNull] out List <DateTime> bridgeDays,
                                                           [NotNull] HouseholdKey householdKey, [NotNull][ItemNotNull] List <CalcDeviceDto> allCalcDeviceDtos,
                                                           [ItemNotNull][NotNull] List <DeviceCategoryDto> deviceCategoryDtos)
        {
            List <CalcAffordanceDto> allCalcAffordances = new List <CalcAffordanceDto>();

            bridgeDays = new List <DateTime>();
            // get affordances
            foreach (var calcLocation in locs)
            {
                var affs = affordanceDict[calcLocation];
                var tmp  = affs.Distinct();
                if (affs.Count != tmp.Count())
                {
                    throw new LPGException("double affordances!?!");
                }

                var devicesAtLoc = allCalcDeviceDtos.Where(x => x.LocationGuid == calcLocation.Guid).ToList();
                var affordances  = GetCalcAffordancesAtLocation(calcLocation, affs, internalStepSize, timeStepsPerHour, temperatureProfile,
                                                                ltdict, geographicLocation, rnd, vacationTimeframes, holidayKey, deviceActions,
                                                                locDict,
                                                                out var tmpBridgeDays, householdKey, devicesAtLoc, deviceCategoryDtos);
                allCalcAffordances.AddRange(affordances);
                foreach (var tmpBridgeDay in tmpBridgeDays)
                {
                    if (!bridgeDays.Contains(tmpBridgeDay))
                    {
                        bridgeDays.Add(tmpBridgeDay);
                    }
                }

                //calcLocation.SortAffordances();
            }

            return(allCalcAffordances);
        }
Beispiel #4
0
        private List <CalcAffordanceVariableOpDto> MakeVariableOps([NotNull] CalcLocationDto calcloc,
                                                                   [NotNull] LocationDtoDict
                                                                   locDict, [NotNull] HouseholdKey householdKey,
                                                                   AffordanceWithTimeLimit aff)
        {
            var variableOps = new List <CalcAffordanceVariableOpDto>();

            foreach (var affVariableOperation in aff.Affordance.ExecutedVariables)
            {
                CalcLocationDto loc = null;
                if (affVariableOperation.LocationMode == VariableLocationMode.OtherLocation)
                {
                    if (affVariableOperation.Location == null)
                    {
                        throw new LPGException("Location was null");
                    }
                    if (locDict.SimulateLocation(affVariableOperation.Location))
                    {
                        loc = locDict.GetDtoForLocation(affVariableOperation.Location);
                    }

                    // if the Location does not exist, don't do anything.
                }
                else
                {
                    loc = calcloc;
                }

                if (loc != null)
                {
                    if (affVariableOperation.Location == null)
                    {
                        throw new LPGException("Location was null");
                    }
                    var variable = _variableRepository.RegisterVariableIfNotRegistered(
                        affVariableOperation.Variable, affVariableOperation.Location, householdKey, locDict);

                    variableOps.Add(new CalcAffordanceVariableOpDto(affVariableOperation.Variable.Name,
                                                                    affVariableOperation.Value, loc.Name, loc.Guid, affVariableOperation.Action,
                                                                    affVariableOperation.ExecutionTime, variable.Guid));
                }
            }

            return(variableOps);
        }
Beispiel #5
0
        public void MakeCalcLocationsTest()
        {
            var locations = new List <Location>();
            var loc       = new Location("loc", 1, string.Empty, Guid.NewGuid().ToStrGuid());

            locations.Add(loc);
            Random r = new Random(1);
            DeviceCategoryPicker picker = new DeviceCategoryPicker(r, null);
            //var cp = new CalcFactoryParameters(picker);
            //var dict =new Dictionary<CalcLocation, List<IAssignableDevice>>();
            var deviceActions = new ObservableCollection <DeviceAction>();
            //var locdict = new Dictionary<Location, CalcLocation>();
            CalcParameters cp = CalcParametersFactory.MakeGoodDefaults();
            //var mock = new Mock<IOnlineDeviceActivationProcessor>();
            //var iodap = mock.Object;
            var locationDtoDict         = new CalcLoadTypeDtoDictionary(new Dictionary <VLoadType, CalcLoadTypeDto>());
            var ltDict                  = new CalcLoadTypeDictionary(new Dictionary <CalcLoadTypeDto, CalcLoadType>());
            CalcLocationDtoFactory cldt = new CalcLocationDtoFactory(cp, picker, locationDtoDict);
            Dictionary <CalcLocationDto, List <IAssignableDevice> > deviceLocationDict = new Dictionary <CalcLocationDto, List <IAssignableDevice> >();
            LocationDtoDict          calclocdict = new LocationDtoDict();
            List <DeviceCategoryDto> devcat      = new List <DeviceCategoryDto>();

            using CalcRepo calcRepo = new CalcRepo();
            //devcat.Add(new DeviceCategoryDto(dc.FullPath, Guid.NewGuid().ToStrGuid()));
            var locdtos = cldt.MakeCalcLocations(locations,
                                                 new HouseholdKey("hh1"),
                                                 EnergyIntensityType.EnergyIntensive,
                                                 deviceLocationDict,
                                                 deviceActions,
                                                 calclocdict,
                                                 devcat);

            locdtos.Count.Should().Be(1);
            locdtos[0].Name.Should().Be(loc.Name);
            CalcLocationFactory clf = new CalcLocationFactory(ltDict, calcRepo);
            //"HH1", EnergyIntensityType.EnergySaving, dict,deviceActions,
            DtoCalcLocationDict dcl = new DtoCalcLocationDict();
            var calclocs            = clf.MakeCalcLocations(locdtos, dcl, calcRepo);

            calclocs.Count.Should().Be(1);
            calclocs[0].Name.Should().Be(loc.Name);
            calclocs[0].Guid.Should().Be(locdtos[0].Guid);
        }
Beispiel #6
0
        private List <VariableRequirementDto> MakeVariableRequirements([NotNull] CalcLocationDto calcloc,
                                                                       [NotNull] LocationDtoDict locDict,
                                                                       [NotNull] HouseholdKey householdKey,
                                                                       AffordanceWithTimeLimit aff)
        {
            var variableRequirements =
                new List <VariableRequirementDto>();

            foreach (var affVariableRequirement in aff.Affordance.RequiredVariables)
            {
                CalcLocationDto loc = null;
                if (affVariableRequirement.LocationMode == VariableLocationMode.OtherLocation)
                {
                    if (affVariableRequirement.Location == null)
                    {
                        throw new LPGException("Location was null");
                    }
                    if (locDict.SimulateLocation(affVariableRequirement.Location))
                    {
                        loc = locDict.GetDtoForLocation(affVariableRequirement.Location);
                    }
                }
                else
                {
                    loc = calcloc;
                }

                if (loc != null)
                {
                    if (affVariableRequirement.Location == null)
                    {
                        throw new LPGException("Location was null");
                    }
                    var variable = _variableRepository.RegisterVariableIfNotRegistered
                                       (affVariableRequirement.Variable, affVariableRequirement.Location, householdKey, locDict);
                    variableRequirements.Add(new VariableRequirementDto(affVariableRequirement.Variable.Name,
                                                                        affVariableRequirement.Value, loc.Name, loc.Guid, affVariableRequirement.Condition,
                                                                        variable.Guid));
                }
            }

            return(variableRequirements);
        }
Beispiel #7
0
        public List <CalcAutoDevDto> MakeCalcAutoDevDtos(
            [NotNull][ItemNotNull] List <IAutonomousDevice> autoDevices,
            EnergyIntensityType energyIntensity,
            [NotNull] HouseholdKey householdKey,
            [NotNull][ItemNotNull] List <VacationTimeframe> vacationTimeframes,
            [NotNull] string holidayKey,
            [NotNull][ItemNotNull] ObservableCollection <DeviceAction> deviceActions,
            [NotNull] LocationDtoDict locationDict,
            [NotNull] TemperatureProfile temperatureProfile, [NotNull] GeographicLocation geographicLocation,
            [ItemNotNull][NotNull] List <DeviceCategoryDto> deviceCategoryDtos)
        {
            var autodevs = new List <CalcAutoDevDto>(autoDevices.Count);
            //// zur kategorien zuordnung
            var allAutonomousDevices = new List <IAssignableDevice>();

            allAutonomousDevices.AddRange(autoDevices.Select(x => x.Device));

            foreach (var hhautodev in autoDevices)
            {
                var busyarr = new BitArray(_calcParameters.InternalTimesteps);
                busyarr.SetAll(false);
                Logger.Debug(
                    "Determining the permitted times for each autonomous device. Device: " + hhautodev.Name);
                if (hhautodev.TimeLimit?.RootEntry == null)
                {
                    throw new DataIntegrityException("Time limit was null");
                }

                busyarr =
                    hhautodev.TimeLimit.RootEntry.GetOneYearArray(
                        _calcParameters.InternalStepsize,
                        _calcParameters.InternalStartTime,
                        _calcParameters.InternalEndTime, temperatureProfile, geographicLocation,
                        _rnd, vacationTimeframes, holidayKey, out _, 0, 0, 0, 0);
                // invertieren von erlaubten zu verbotenen zeiten
                busyarr = busyarr.Not();
                var timeprofilereference =
                    _availabilityDtoRepository.MakeNewReference(hhautodev.TimeLimit.Name, busyarr);
                if (hhautodev.Location == null)
                {
                    throw new DataIntegrityException("Location was null");
                }

                var calcLocation = locationDict.LocationDict[hhautodev.Location];
                if (hhautodev.Device == null)
                {
                    throw new DataIntegrityException("Device was null");
                }

                switch (hhautodev.Device.AssignableDeviceType)
                {
                case AssignableDeviceType.Device:
                case AssignableDeviceType.DeviceCategory:
                    if (hhautodev.LoadType == null || hhautodev.TimeProfile == null)
                    {
                        throw new LPGException("load type was null");
                    }

                    if (_loadTypeDictionary.SimulateLoadtype(hhautodev.LoadType))
                    {
                        var profile = GetCalcProfileDto(hhautodev.TimeProfile);
                        var rd      = _picker.GetAutoDeviceDeviceFromDeviceCategoryOrDevice(
                            hhautodev.Device, allAutonomousDevices, energyIntensity, deviceActions,
                            hhautodev.Location.IntID);
                        var cdl   = MakeCalcDeviceLoads(rd, _loadTypeDictionary);
                        var ltdto = _loadTypeDictionary.GetLoadtypeDtoByLoadType(hhautodev.LoadType);
                        List <VariableRequirementDto> requirementDtos = new List <VariableRequirementDto>();
                        if (hhautodev.Variable != null)
                        {
                            var myVariable =
                                _calcVariableRepositoryDtoFactory.RegisterVariableIfNotRegistered(hhautodev.Variable,
                                                                                                  hhautodev.Location, householdKey, locationDict);
                            VariableRequirementDto req = new VariableRequirementDto(hhautodev.Variable.Name,
                                                                                    hhautodev.VariableValue, calcLocation.Name, calcLocation.Guid,
                                                                                    hhautodev.VariableCondition, myVariable.Guid);
                            requirementDtos.Add(req);
                        }
                        if (rd.DeviceCategory == null)
                        {
                            throw new LPGException("Device category was null");
                        }

                        var deviceCategoryDto =
                            deviceCategoryDtos.Single(x => x.FullCategoryName == rd.DeviceCategory.FullPath);
                        var cautodev = new CalcAutoDevDto(rd.Name, profile,
                                                          ltdto.Name, ltdto.Guid, cdl,
                                                          (double)hhautodev.TimeStandardDeviation,
                                                          deviceCategoryDto.Guid, householdKey, 1, calcLocation.Name, calcLocation.Guid,
                                                          deviceCategoryDto.FullCategoryName, Guid.NewGuid().ToStrGuid(),
                                                          timeprofilereference, requirementDtos, deviceCategoryDto.FullCategoryName);
                        autodevs.Add(cautodev);
                    }

                    break;

                case AssignableDeviceType.DeviceAction:
                case AssignableDeviceType.DeviceActionGroup:
                    var deviceAction = _picker.GetAutoDeviceActionFromGroup(hhautodev.Device,
                                                                            allAutonomousDevices, energyIntensity, deviceActions, hhautodev.Location.IntID);

                    foreach (var actionProfile in deviceAction.Profiles)
                    {
                        if (actionProfile.VLoadType == null)
                        {
                            throw new DataIntegrityException("Vloadtype  was null");
                        }

                        if (actionProfile.Timeprofile == null)
                        {
                            throw new DataIntegrityException("Timeprofile  was null");
                        }

                        if (_loadTypeDictionary.SimulateLoadtype(actionProfile.VLoadType))
                        {
                            var profile = GetCalcProfileDto(actionProfile.Timeprofile);
                            if (deviceAction.Device == null)
                            {
                                throw new LPGException("Device was null");
                            }
                            var cdl = MakeCalcDeviceLoads(deviceAction.Device, _loadTypeDictionary);
                            var lt  = _loadTypeDictionary.GetLoadtypeDtoByLoadType(actionProfile.VLoadType);
                            List <VariableRequirementDto> requirementDtos = new List <VariableRequirementDto>();
                            if (hhautodev.Variable != null)
                            {
                                var myVariable =
                                    _calcVariableRepositoryDtoFactory.RegisterVariableIfNotRegistered(hhautodev.Variable,
                                                                                                      hhautodev.Location, householdKey, locationDict);
                                VariableRequirementDto req = new VariableRequirementDto(hhautodev.Variable?.Name,
                                                                                        hhautodev.VariableValue, calcLocation.Name, calcLocation.Guid,
                                                                                        hhautodev.VariableCondition, myVariable.Guid);
                                requirementDtos.Add(req);
                            }
                            if (deviceAction.Device.DeviceCategory == null)
                            {
                                throw new LPGException("device category was null");
                            }
                            var deviceCategoryDto =
                                deviceCategoryDtos.Single(x => x.FullCategoryName == deviceAction.Device.DeviceCategory.FullPath);
                            var cautodev = new CalcAutoDevDto(deviceAction.Device.Name,
                                                              profile, lt.Name, lt.Guid, cdl,
                                                              (double)hhautodev.TimeStandardDeviation,
                                                              deviceCategoryDto.Guid,
                                                              householdKey, actionProfile.Multiplier, calcLocation.Name, calcLocation.Guid,
                                                              deviceAction.Device.DeviceCategory.FullPath, Guid.NewGuid().ToStrGuid(),
                                                              timeprofilereference, requirementDtos,
                                                              deviceCategoryDto.FullCategoryName);
                            autodevs.Add(cautodev);
                        }
                    }

                    break;

                default:
                    throw new LPGException("Forgotten AssignableDeviceType. Please Report!");
                }
            }

            return(autodevs);
        }
        public CalcHouseholdDto MakeCalcModularHouseholdDto([NotNull] Simulator sim, [NotNull] ModularHousehold mhh,
                                                            [NotNull] TemperatureProfile temperatureProfile, [NotNull] HouseholdKey householdKey, [NotNull] GeographicLocation geographicLocation,
                                                            [NotNull] out LocationDtoDict locationDict,
                                                            [CanBeNull] TransportationDeviceSet transportationDeviceSet,
                                                            [CanBeNull] TravelRouteSet travelRouteSet, EnergyIntensityType energyIntensity,
                                                            [CanBeNull] ChargingStationSet chargingStationSet)
        {
            //  _lf.RegisterKey(householdKey, mhh.PrettyName);
            var name = CalcAffordanceFactory.FixAffordanceName(mhh.Name, sim.MyGeneralConfig.CSVCharacter);

            if (geographicLocation == null)
            {
                throw new DataIntegrityException("no geographic Location was set");
            }
            var et = energyIntensity;

            if (et == EnergyIntensityType.AsOriginal)
            {
                et = mhh.EnergyIntensityType;
            }
            name = name + " " + householdKey.Key;
            var locations = mhh.CollectLocations();
            //var deviceLocationDict = new Dictionary<CalcLocation, List<IAssignableDevice>>();
            var deviceLocationDtoDict = new Dictionary <CalcLocationDto, List <IAssignableDevice> >();

            locationDict = new LocationDtoDict();
            List <DeviceCategoryDto> deviceCategoryDtos = new List <DeviceCategoryDto>();

            foreach (var deviceCategory in sim.DeviceCategories.It)
            {
                deviceCategoryDtos.Add(new DeviceCategoryDto(deviceCategory.FullPath, Guid.NewGuid().ToStrGuid()));
            }
            var locationDtos = _calcLocationDtoFactory.MakeCalcLocations(locations,
                                                                         householdKey,
                                                                         et, deviceLocationDtoDict, sim.DeviceActions.It, locationDict, deviceCategoryDtos);

            // persons

            if (mhh.Vacation == null)
            {
                throw new LPGException("Vacation was null");
            }

            var personDtos = _calcPersonDtoFactory.MakePersonDtos(mhh.Persons.ToList(), householdKey,
                                                                  mhh.Vacation.VacationTimeframes(), mhh.CollectTraitDesires(), mhh.Name);

            if (_calcRepo.CalcParameters.Options.Contains(CalcOption.HouseholdContents))
            {
                _calcRepo.InputDataLogger.SaveList(personDtos.ConvertAll(x => (IHouseholdKey)x));
            }

            //mhh.Persons.ToList(),mhh.Vacation.VacationTimeframes(),  sim.MyGeneralConfig.RepetitionCount,householdKey, locs[0],name);
            //CalcPersonFactory.AddTraitDesires(mhh.CollectTraitDesires(), calcpersons,sim.MyGeneralConfig.TimeStepsPerHour, chh.Name, new Dictionary<Desire, SharedDesireValue>());
            //check if unhungry and unhungry join only have been added both
            //can't check it in the integrity checker, because that would mean having to duplicate the entire
            // desire collection logic

            /*  foreach (CalcPerson person in calcpersons) {
             *    var desires =
             *        person.PersonDesires.Desires.Values.Where(x => x.Name.ToLower().Contains("unhungry") || x.Name.ToLower().Contains("un-hungry")).ToList();
             *    if (desires.Count > 1) {
             *        throw new DataIntegrityException("More than one unhungry desire for the person " + person.Name, mhh);
             *    }
             * }*/

            // devices

            var deviceLocations = new List <DeviceLocationTuple>();

            foreach (var modularHouseholdTrait in mhh.Traits)
            {
                // ReSharper disable once ConditionIsAlwaysTrueOrFalse
                if (modularHouseholdTrait.HouseholdTrait != null)
                {
                    CollectDevicesFromTrait(modularHouseholdTrait.HouseholdTrait, deviceLocations);
                }
            }

            var deviceDtos = _calcDeviceDtoFactory.MakeCalcDevices(locationDtos,
                                                                   deviceLocations, et, householdKey, deviceLocationDtoDict, sim.DeviceActions.It, _ltDict, deviceCategoryDtos);

            if (_calcRepo.CalcParameters.Options.Contains(CalcOption.HouseholdContents))
            {
                _calcRepo.InputDataLogger.SaveList(deviceDtos.ConvertAll(x => (IHouseholdKey)x));
            }

            //autodevs
            var autonomousDevices = mhh.CollectAutonomousDevices();

            if (mhh.Vacation == null)
            {
                throw new LPGException("Vacation was null");
            }

            var autoDevDtos = _calcDeviceDtoFactory.MakeCalcAutoDevDtos(autonomousDevices,
                                                                        energyIntensity, householdKey, mhh.Vacation.VacationTimeframes(),
                                                                        mhh.Name + "###" + householdKey,
                                                                        sim.DeviceActions.It, locationDict,
                                                                        temperatureProfile, geographicLocation, deviceCategoryDtos);

            if (_calcRepo.CalcParameters.Options.Contains(CalcOption.HouseholdContents))
            {
                _calcRepo.InputDataLogger.SaveList(autoDevDtos.ConvertAll(x => (IHouseholdKey)x));
            }

            //affordances
            var affordancesAtLoc =
                new Dictionary <CalcLocationDto, List <AffordanceWithTimeLimit> >();

            foreach (var location in locations)
            {
                affordancesAtLoc.Add(locationDict.GetDtoForLocation(location), mhh.GetAllAffordancesForLocation(location));
            }
            if (mhh.Vacation == null)
            {
                throw new LPGException("Vacation was null");
            }

            List <CalcAffordanceDto> allAffordances = _calcAffordanceDtoFactory.SetCalcAffordances(locationDtos, temperatureProfile,
                                                                                                   _ltDict,
                                                                                                   geographicLocation, _random, sim.MyGeneralConfig.TimeStepsPerHour,
                                                                                                   sim.MyGeneralConfig.InternalStepSize, mhh.Vacation.VacationTimeframes(),
                                                                                                   mhh.Name + "###" + householdKey, sim.DeviceActions.MyItems, affordancesAtLoc, locationDict,
                                                                                                   out List <DateTime> bridgeDays, householdKey, deviceDtos, deviceCategoryDtos);

            if (_calcRepo.CalcParameters.Options.Contains(CalcOption.HouseholdContents))
            {
                _calcRepo.InputDataLogger.SaveList(allAffordances.ConvertAll(x => (IHouseholdKey)x));
                _calcRepo.InputDataLogger.SaveList(_calcVariableRepositoryDtoFactory.GetAllVariableDtos()
                                                   .ConvertAll(x => (IHouseholdKey)x));
            }

            //                SaveVariableDefinitionsDtos(_calcVariableRepositoryDtoFactory.GetAllVariableDtos());
            //CalcVariableRepository variableRepository = _calcVariableRepositoryDtoFactory.GetRepository(householdKey);
            List <CalcSiteDto> sites = null;
            List <CalcTransportationDeviceDto> transportationDevices = null;
            List <CalcTravelRouteDto>          routes = null;

            if (_calcRepo.CalcParameters.TransportationEnabled)
            {
                _transportationDtoFactory.MakeTransportationDtos(sim, mhh, transportationDeviceSet,
                                                                 travelRouteSet, chargingStationSet,
                                                                 out sites, out transportationDevices,
                                                                 out routes, locationDtos, householdKey);
                if (_calcRepo.CalcParameters.IsSet(CalcOption.TransportationStatistics))
                {
                    _calcRepo.InputDataLogger.SaveList(sites.ConvertAll(x => (IHouseholdKey)x));
                    _calcRepo.InputDataLogger.SaveList(transportationDevices.ConvertAll(x => (IHouseholdKey)x));
                    _calcRepo.InputDataLogger.SaveList(routes.ConvertAll(x => (IHouseholdKey)x));
                }
            }
            var chh = new CalcHouseholdDto(name, mhh.IntID, temperatureProfile.Name, householdKey, Guid.NewGuid().ToStrGuid(),
                                           geographicLocation.Name,
                                           bridgeDays, autoDevDtos, locationDtos, personDtos, deviceDtos,
                                           allAffordances, mhh.Vacation.VacationTimeframes(),
                                           sites, routes, transportationDevices,
                                           mhh.Description);

            if (_calcRepo.CalcParameters.Options.Contains(CalcOption.HouseholdContents))
            {
                _calcRepo.InputDataLogger.Save(householdKey, chh);
            }

            if (_calcRepo.CalcParameters.Options.Contains(CalcOption.HouseholdContents))
            {
                BridgeDayEntries bdes = new BridgeDayEntries(householdKey, chh.BridgeDays);
                _calcRepo.InputDataLogger.Save(householdKey, bdes);
            }

            return(chh);
        }
Beispiel #9
0
        public void MakeCalcLocationsTestWithDeviceCategory()
        {
            using WorkingDir wd = new WorkingDir(Utili.GetCurrentMethodAndClass());
            var            builder        = new ContainerBuilder();
            var            r              = new Random(1);
            CalcParameters calcParameters = CalcParametersFactory.MakeGoodDefaults().SetStartDate(2018, 1, 1)
                                            .SetEndDate(new DateTime(2018, 1, 1, 2, 0, 0)).SetSettlingDays(0).EnableShowSettlingPeriod();
            //CalcFactoryParameters.SetSkipChecking(true);
            //var nr = new NormalRandom(0, 1, r);
            var locations = new List <Location>();
            var loc       = new Location("loc", 1, string.Empty, Guid.NewGuid().ToStrGuid());

            locations.Add(loc);
            var devices = new ObservableCollection <RealDevice>();

            var dc  = new DeviceCategory("dc", -1, string.Empty, false, devices, Guid.NewGuid().ToStrGuid(), 1, true);
            var rd  = new RealDevice("rd", 1, string.Empty, dc, string.Empty, false, false, string.Empty, Guid.NewGuid().ToStrGuid(), 1);
            var rd2 = new RealDevice("rd2", 1, string.Empty, dc, string.Empty, false, false, string.Empty, Guid.NewGuid().ToStrGuid(), 1);

            dc.SubDevices.Add(rd);
            loc.AddDevice(dc, false);
            loc.AddDevice(rd2, false);
            var deviceLocationDict = new Dictionary <CalcLocationDto, List <IAssignableDevice> >();

            List <DeviceCategoryDto> devcat = new List <DeviceCategoryDto> {
                new DeviceCategoryDto(dc.FullPath, Guid.NewGuid().ToStrGuid())
            };

            devices.Add(rd);
            devices.Add(rd2);
            //var dict =new Dictionary<CalcLocation, List<IAssignableDevice>>();
            var allDeviceActions = new ObservableCollection <DeviceAction>();

            //var locdict = new Dictionary<Location, CalcLocation>();
            builder.Register(x => new CalcLoadTypeDtoDictionary(new Dictionary <VLoadType, CalcLoadTypeDto>())).As <CalcLoadTypeDtoDictionary>()
            .SingleInstance();
            builder.Register(x => new CalcLoadTypeDictionary(new Dictionary <CalcLoadTypeDto, CalcLoadType>())).As <CalcLoadTypeDictionary>()
            .SingleInstance();
            builder.Register(x => new DeviceCategoryPicker(r, null)).As <IDeviceCategoryPicker>().SingleInstance();
            builder.Register(x => calcParameters).As <CalcParameters>().SingleInstance();
            //builder.RegisterType<CalcLocationFactory>().As<CalcLocationFactory>().SingleInstance();
            Mock <IOnlineDeviceActivationProcessor> odapmock = new Mock <IOnlineDeviceActivationProcessor>();

            builder.Register(x => odapmock.Object).As <IOnlineDeviceActivationProcessor>().SingleInstance();
            builder.Register(x => r).As <Random>().SingleInstance();
            var idl = wd.InputDataLogger;

            builder.Register(x => idl).As <IInputDataLogger>().SingleInstance();
            string path = wd.WorkingDirectory;

            builder.Register(x => new FileFactoryAndTracker(path, "HH1", idl)).As <FileFactoryAndTracker>()
            .SingleInstance();
            builder.Register(x => new SqlResultLoggingService(path)).As <SqlResultLoggingService>().SingleInstance();
            builder.Register(x => new DateStampCreator(x.Resolve <CalcParameters>())).As <DateStampCreator>().SingleInstance();
            builder.Register(x => new DateStampCreator(x.Resolve <CalcParameters>())).As <DateStampCreator>().SingleInstance();
            builder.Register(x => new OnlineLoggingData(x.Resolve <DateStampCreator>(), x.Resolve <IInputDataLogger>(), x.Resolve <CalcParameters>()))
            .As <OnlineLoggingData>().SingleInstance();
            builder.Register(x => new LogFile(calcParameters,
                                              x.Resolve <FileFactoryAndTracker>())).As <ILogFile>().SingleInstance();
            builder.RegisterType <CalcDeviceFactory>().As <CalcDeviceFactory>().SingleInstance();
            builder.RegisterType <CalcLocationFactory>().As <CalcLocationFactory>().SingleInstance();
            builder.RegisterType <CalcPersonFactory>().As <CalcPersonFactory>().SingleInstance();
            builder.RegisterType <CalcModularHouseholdFactory>().As <CalcModularHouseholdFactory>().SingleInstance();
            builder.RegisterType <CalcLocationDtoFactory>().As <CalcLocationDtoFactory>();
            builder.RegisterType <InputDataLogger>().As <InputDataLogger>().SingleInstance();
            builder.RegisterType <CalcRepo>().As <CalcRepo>().SingleInstance();
            var container = builder.Build();

            using (var scope = container.BeginLifetimeScope()) {
                var             cldt        = scope.Resolve <CalcLocationDtoFactory>();
                var             calcRepo    = scope.Resolve <CalcRepo>();
                LocationDtoDict calclocdict = new LocationDtoDict();
                var             locdtos     = cldt.MakeCalcLocations(locations,
                                                                     new HouseholdKey("HH1"),
                                                                     EnergyIntensityType.EnergySaving,
                                                                     deviceLocationDict,
                                                                     allDeviceActions,
                                                                     calclocdict,
                                                                     devcat);

                CalcLocationFactory clf = scope.Resolve <CalcLocationFactory>();
                DtoCalcLocationDict dtl = new DtoCalcLocationDict();
                var clocations          = clf.MakeCalcLocations(locdtos, dtl, calcRepo);

                clocations.Count.Should().Be(1);
                clocations[0].LightDevices.Count.Should().Be(2);
                foreach (var device in clocations[0].LightDevices)
                {
                    Logger.Info(device.Name);
                }
            }

            wd.CleanUp();
        }
Beispiel #10
0
        public void MakeCalcLocationsTestWithDevice()
        {
            var            builder        = new ContainerBuilder();
            var            r              = new Random(1);
            CalcParameters calcParameters = CalcParametersFactory.MakeGoodDefaults().SetStartDate(2018, 1, 1)
                                            .SetEndDate(new DateTime(2018, 1, 1, 2, 0, 0)).SetSettlingDays(0).EnableShowSettlingPeriod();
            var picker = new DeviceCategoryPicker(r, null);

            builder.Register(x => picker).As <DeviceCategoryPicker>().SingleInstance();
            //var nr = new NormalRandom(0, 1, r);
            var locations = new List <Location>();
            var loc       = new Location("loc", 1, string.Empty, Guid.NewGuid().ToStrGuid());

            locations.Add(loc);
            var devices = new ObservableCollection <RealDevice>();
            var dc      = new DeviceCategory("dc", -1, string.Empty, false, devices, Guid.NewGuid().ToStrGuid(), 1, true);
            List <DeviceCategoryDto> devcat = new List <DeviceCategoryDto> {
                new DeviceCategoryDto(dc.FullPath, Guid.NewGuid().ToStrGuid())
            };
            var rd = new RealDevice("rd", 1, string.Empty, dc, string.Empty, false, false, string.Empty, Guid.NewGuid().ToStrGuid(), 1);

            loc.AddDevice(rd, false);
            var deviceLocationDict = new Dictionary <CalcLocationDto, List <IAssignableDevice> >();
            var allDeviceActions   = new ObservableCollection <DeviceAction>();

            //CalcLoadTypeDictionary cltd = CalcLoadTypeFactory.MakeLoadTypes(new ObservableCollection<VLoadType>(),calcParameters.InternalStepsize, calcParameters.LoadTypePriority);
            builder.Register(x => new DateStampCreator(x.Resolve <CalcParameters>())).As <DateStampCreator>().SingleInstance();
            builder.Register(x => new CalcLoadTypeDtoDictionary(new Dictionary <VLoadType, CalcLoadTypeDto>())).As <CalcLoadTypeDtoDictionary>()
            .SingleInstance();
            builder.Register(x => new CalcLoadTypeDictionary(new Dictionary <CalcLoadTypeDto, CalcLoadType>())).As <CalcLoadTypeDictionary>()
            .SingleInstance();
            builder.Register(x => new DeviceCategoryPicker(r, null)).As <IDeviceCategoryPicker>().SingleInstance();
            builder.Register(_ => calcParameters).As <CalcParameters>().SingleInstance();
            //builder.RegisterType<CalcLocationFactory>().As<CalcLocationFactory>().SingleInstance();
            Mock <IOnlineDeviceActivationProcessor> odapmock = new Mock <IOnlineDeviceActivationProcessor>();

            builder.Register(x => odapmock.Object).As <IOnlineDeviceActivationProcessor>().SingleInstance();
            builder.Register(x => r).As <Random>().SingleInstance();
            builder.RegisterType <CalcDeviceFactory>().As <CalcDeviceFactory>().SingleInstance();
            builder.RegisterType <CalcLocationFactory>().As <CalcLocationFactory>().SingleInstance();
            builder.RegisterType <CalcLocationDtoFactory>().As <CalcLocationDtoFactory>();
            builder.RegisterType <CalcRepo>().As <CalcRepo>().SingleInstance();
            var container = builder.Build();

            using var scope = container.BeginLifetimeScope();
            var             calcRepo    = scope.Resolve <CalcRepo>();
            var             cldt        = scope.Resolve <CalcLocationDtoFactory>();
            LocationDtoDict calclocdict = new LocationDtoDict();
            var             locdtos     = cldt.MakeCalcLocations(locations,
                                                                 new HouseholdKey("HH1"),
                                                                 EnergyIntensityType.EnergyIntensive,
                                                                 deviceLocationDict,
                                                                 allDeviceActions,
                                                                 calclocdict,
                                                                 devcat);

            //CalcDeviceFactory cdf = scope.Resolve<CalcDeviceFactory>();
            CalcLocationFactory clf = scope.Resolve <CalcLocationFactory>();
            DtoCalcLocationDict dtl = new DtoCalcLocationDict();
            var clocations          = clf.MakeCalcLocations(locdtos, dtl, calcRepo);

            clocations.Count.Should().Be(1);
            clocations[0].LightDevices.Count.Should().Be(2);
        }
Beispiel #11
0
        private List <CalcAffordanceDto> GetCalcAffordancesAtLocation([NotNull] CalcLocationDto calcloc,
                                                                      [NotNull] List <AffordanceWithTimeLimit> affordancesAtLocation,
                                                                      TimeSpan internalStepSize, int timeStepsPerHour,
                                                                      [NotNull] TemperatureProfile temperatureProfile,
                                                                      [NotNull] CalcLoadTypeDtoDictionary ltdict,
                                                                      [NotNull] GeographicLocation geographicLocation, [NotNull] Random rnd,
                                                                      [NotNull][ItemNotNull] List <VacationTimeframe> vacationTimeframes,
                                                                      [NotNull] string holidayKey,
                                                                      [NotNull][ItemNotNull] ObservableCollection <DeviceAction> allDeviceActions,
                                                                      [NotNull]
                                                                      LocationDtoDict locDict,
                                                                      [NotNull] out List <DateTime> bridgeDays, [NotNull] HouseholdKey householdKey,
                                                                      [NotNull][ItemNotNull] List <CalcDeviceDto> deviceDtosAtLocation,
                                                                      [ItemNotNull][NotNull] List <DeviceCategoryDto> deviceCategoryDtos)
        {
            List <CalcAffordanceDto> createdAffordances = new List <CalcAffordanceDto>();

            bridgeDays = new List <DateTime>();
            foreach (AffordanceWithTimeLimit aff in affordancesAtLocation)
            {
                var affordanceName = CalcAffordanceFactory.FixAffordanceName(aff.Affordance.Name, _cp.CSVCharacter);
                if (aff.Affordance.PersonProfile == null)
                {
                    throw new DataIntegrityException("Person profile on " + aff.Affordance.PrettyName + " was null. Please fix.");
                }

                var cp1 = CalcDeviceDtoFactory.GetCalcProfileDto(aff.Affordance.PersonProfile);
                List <CalcDesireDto> calcDesires = MakeCalcDesires(timeStepsPerHour, aff, affordanceName);
                List <CalcAffordanceVariableOpDto> variableOps          = MakeVariableOps(calcloc, locDict, householdKey, aff);
                List <VariableRequirementDto>      variableRequirements =
                    MakeVariableRequirements(calcloc, locDict, householdKey, aff);

                MakeAffordanceTimelimit(temperatureProfile, geographicLocation, rnd, vacationTimeframes,
                                        holidayKey, bridgeDays, aff, out var availabilityDataReference);

                //make the affordance
                Logger.Debug("Converting the time limit to a bitarray for the affordance " + aff.Affordance.Name);
                //caff.IsBusyArray = tmparr;
                string timeLimitName = "";

                if (aff.TimeLimit != null)
                {
                    timeLimitName = aff.TimeLimit.Name;
                }

                var caff = new CalcAffordanceDto(affordanceName, aff.Affordance.IntID, cp1, calcloc.Name, calcloc.Guid,
                                                 aff.Affordance.RandomDesireResults, calcDesires, aff.Affordance.MinimumAge,
                                                 aff.Affordance.MaximumAge,
                                                 aff.Affordance.PermittedGender,
                                                 aff.Affordance.NeedsLight, (double)aff.Affordance.TimeStandardDeviation,
                                                 aff.Affordance.CarpetPlotColor.R, aff.Affordance.CarpetPlotColor.G, aff.Affordance.CarpetPlotColor.B,
                                                 aff.Affordance.AffCategory,
                                                 aff.Affordance.IsInterruptable, aff.Affordance.IsInterrupting, variableOps, variableRequirements,
                                                 aff.Affordance.ActionAfterInterruption, timeLimitName, aff.Weight,
                                                 aff.Affordance.RequireAllDesires, aff.SrcTraitName,
                                                 Guid.NewGuid().ToStrGuid(), availabilityDataReference, householdKey, aff.Affordance.BodilyActivityLevel);
                foreach (var devtup in aff.Affordance.AffordanceDevices)
                {
                    MakeAffordanceDevices(calcloc, internalStepSize, ltdict, allDeviceActions, aff, caff, devtup, deviceDtosAtLocation,
                                          deviceCategoryDtos);
                }

                MakeSubAffordances(caff, aff.Affordance, timeStepsPerHour, internalStepSize, calcloc,
                                   locDict, _cp.CSVCharacter, aff.Weight, aff.SrcTraitName, householdKey);
                createdAffordances.Add(caff);
            }
            return(createdAffordances);
        }
Beispiel #12
0
        private void MakeSubAffordances([NotNull] CalcAffordanceDto caff, [NotNull] Affordance aff, int timeStepsPerHour,
                                        TimeSpan internalStepSize, [NotNull] CalcLocationDto calcloc,
                                        [NotNull] LocationDtoDict locDict,
                                        [NotNull] string csvCharacter, int weight, [NotNull] string srcTrait,
                                        [NotNull] HouseholdKey householdKey)
        {
            // Subaffordanzen durchgehen
            foreach (var affsubaff in aff.SubAffordances)
            {
                var calcDesires = new List <CalcDesireDto>();
                if (affsubaff.SubAffordance == null)
                {
                    throw new LPGException("SubAffordance was null");
                }

                var name = CalcAffordanceFactory.FixAffordanceName(affsubaff.SubAffordance.Name, csvCharacter);
                // f�r alle desires calcdesires anlegen
                foreach (var subaffDesire in affsubaff.SubAffordance.SubAffordanceDesires)
                {
                    if (subaffDesire.Desire == null)
                    {
                        throw new LPGException("Desire was null");
                    }

                    var cd = new CalcDesireDto(name + " - " + subaffDesire.Name, subaffDesire.Desire.IntID, 0, 0,
                                               subaffDesire.SatisfactionValue, 0, timeStepsPerHour, subaffDesire.Desire.CriticalThreshold,
                                               null, srcTrait, "");
                    calcDesires.Add(cd);
                }

                var minutesperstep   = (decimal)internalStepSize.TotalMinutes;
                var delayTimeInSteps = (int)(affsubaff.DelayTime / minutesperstep);
                // variables
                var calcAffordanceVariableOps = new List <CalcAffordanceVariableOpDto>();
                foreach (var affVariableOp in affsubaff.SubAffordance.SubAffordanceVariableOps)
                {
                    CalcLocationDto loc = null;
                    if (affVariableOp.LocationMode == VariableLocationMode.OtherLocation)
                    {
                        if (affVariableOp.Location != null && locDict.SimulateLocation(affVariableOp.Location))
                        {
                            loc = locDict.GetDtoForLocation(affVariableOp.Location);
                        }
                    }
                    else
                    {
                        loc = calcloc;
                    }

                    if (loc != null && affVariableOp.Variable != null)
                    {
                        if (affVariableOp.Location == null)
                        {
                            throw new LPGException("Variable Location was null");
                        }
                        var variable =
                            _variableRepository.RegisterVariableIfNotRegistered(affVariableOp.Variable,
                                                                                affVariableOp.Location, householdKey, locDict);
                        calcAffordanceVariableOps.Add(new CalcAffordanceVariableOpDto(affVariableOp.Variable.Name,
                                                                                      affVariableOp.Value, loc.Name, loc.Guid, affVariableOp.VariableAction, affVariableOp.ExecutionTime,
                                                                                      variable.Guid));
                    }
                }

                // CalcSubaffordanz anlegen
                var affName = CalcAffordanceFactory.FixAffordanceName(aff.Name, csvCharacter);
                // ReSharper disable once ConditionIsAlwaysTrueOrFalse
                var csubaff = new CalcSubAffordanceDto(name + " (" + affName + ")", affsubaff.IntID, calcloc.Name, calcloc.Guid,
                                                       calcDesires, affsubaff.SubAffordance.MinimumAge, affsubaff.SubAffordance.MaximumAge,
                                                       delayTimeInSteps, affsubaff.SubAffordance.PermittedGender, aff.AffCategory,
                                                       affsubaff.SubAffordance.IsInterruptable, affsubaff.SubAffordance.IsInterrupting,
                                                       calcAffordanceVariableOps, weight, srcTrait, Guid.NewGuid().ToStrGuid());
                caff.SubAffordance.Add(csubaff);
            }
        }