Пример #1
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);
        }
Пример #2
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);
            }
        }