Exemplo n.º 1
0
        private void MakeAffordanceTimelimit([NotNull] TemperatureProfile temperatureProfile,
                                             [NotNull] GeographicLocation geographicLocation,
                                             [NotNull] Random rnd, [NotNull][ItemNotNull] List <VacationTimeframe> vacationTimeframes,
                                             [NotNull] string holidayKey, [NotNull] List <DateTime> bridgeDays,
                                             AffordanceWithTimeLimit aff,
                                             [NotNull] out AvailabilityDataReferenceDto availabilityDataReference)
        {
            //time limit stuff
            if (aff.Affordance.TimeLimit == null)
            {
                throw new DataIntegrityException("The time limit on the affordance was null. Please fix",
                                                 aff.Affordance);
            }

            var tl = aff.Affordance.TimeLimit;

            if (aff.TimeLimit != null)
            {
                tl = aff.TimeLimit;
            }
            if (tl.RootEntry == null)
            {
                throw new LPGException("Root Entry was null");
            }

            var tmparr = tl.RootEntry.GetOneYearArray(
                _cp.InternalStepsize,
                _cp.InternalStartTime,
                _cp.InternalEndTime, temperatureProfile, geographicLocation, rnd,
                vacationTimeframes, holidayKey, out var tmpBridgeDays, aff.StartMinusTime, aff.StartPlusTime,
                aff.EndMinusTime,
                aff.EndPlusTime);

            foreach (var tmpBridgeDay in tmpBridgeDays)
            {
                if (!bridgeDays.Contains(tmpBridgeDay))
                {
                    bridgeDays.Add(tmpBridgeDay);
                }
            }

            // invertieren von erlaubten zu verbotenen zeiten
            tmparr = tmparr.Not();
            availabilityDataReference = _availabilityDtoRepository.MakeNewReference(tl.Name, tmparr);
        }
Exemplo n.º 2
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);
        }