public CalcDeviceTaggingSets GetDeviceTaggingSets([NotNull] Simulator sim, int personCount)
        {
            CalcDeviceTaggingSets cs = new CalcDeviceTaggingSets
            {
                AllCalcDeviceTaggingSets = new List <DeviceTaggingSetInformation>()
            };

            foreach (var deviceTaggingSet in sim.DeviceTaggingSets.MyItems)
            {
                var calcset = new DeviceTaggingSetInformation(deviceTaggingSet.Name);
                foreach (var entry in deviceTaggingSet.Entries)
                {
                    if (entry.Device == null)
                    {
                        throw new LPGException("Device was null");
                    }

                    if (entry.Tag == null)
                    {
                        throw new LPGException("Tag was null");
                    }

                    var devname = entry.Device.Name;
                    //sim.MyGeneralConfig.CSVCharacter);
                    var tagname = CalcAffordanceFactory.FixAffordanceName(entry.Tag.Name,
                                                                          _calcParameters.CSVCharacter);
                    calcset.AddTag(devname, tagname);
                }

                foreach (var reference in
                         deviceTaggingSet.References.Where(x => x.PersonCount == personCount))
                {
                    if (reference.Tag == null)
                    {
                        throw new LPGException("Tag was null");
                    }

                    calcset.AddRefValue(reference.Tag.Name, reference.ReferenceValue, reference.LoadType.Name);
                }

                foreach (var loadType in deviceTaggingSet.LoadTypes)
                {
                    if (loadType.LoadType == null)
                    {
                        throw new LPGException("Loadtype was null");
                    }

                    if (_ltDict.SimulateLoadtype(loadType.LoadType))
                    {
                        var clt = _ltDict.GetLoadtypeDtoByLoadType(loadType.LoadType);
                        calcset.AddLoadType(clt.ConvertToLoadTypeInformation());
                    }
                }

                cs.AllCalcDeviceTaggingSets.Add(calcset);
            }

            return(cs);
        }
Пример #2
0
        public static List <CalcDeviceLoadDto> MakeCalcDeviceLoads([NotNull] RealDevice device,
                                                                   [NotNull] CalcLoadTypeDtoDictionary ltdtodict)
        {
            var deviceLoads = new List <CalcDeviceLoadDto>();

            foreach (var realDeviceLoadType in device.Loads)
            {
                if (realDeviceLoadType.LoadType == null)
                {
                    throw new LPGException("Loadtype was null");
                }

                if (ltdtodict.SimulateLoadtype(realDeviceLoadType.LoadType))
                {
                    var cdl = new CalcDeviceLoadDto(realDeviceLoadType.Name, realDeviceLoadType.IntID,
                                                    ltdtodict.Ltdtodict[realDeviceLoadType.LoadType].Name, ltdtodict.Ltdtodict[realDeviceLoadType.LoadType].Guid,
                                                    realDeviceLoadType.AverageYearlyConsumption, realDeviceLoadType.StandardDeviation,
                                                    Guid.NewGuid().ToStrGuid(), realDeviceLoadType.MaxPower);
                    deviceLoads.Add(cdl);
                }
            }

            return(deviceLoads);
        }
Пример #3
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);
        }
Пример #4
0
        private void MakeAffordanceDevices([NotNull] CalcLocationDto calcloc, TimeSpan internalStepSize,
                                           [NotNull] CalcLoadTypeDtoDictionary ltdict,
                                           [NotNull][ItemNotNull] ObservableCollection <DeviceAction> allDeviceActions,
                                           AffordanceWithTimeLimit aff, [NotNull] CalcAffordanceDto caff, [NotNull] AffordanceDevice devtup,
                                           [NotNull][ItemNotNull] List <CalcDeviceDto> devicesAtLocation,
                                           [ItemNotNull][NotNull] List <DeviceCategoryDto> deviceCategoryDtos)
        {
            if (devtup.Device == null)
            {
                throw new LPGException("Device was null");
            }
            // pick the device itself
            var pickedDevice = _picker.GetDeviceDtoForAffordance(devtup.Device, devicesAtLocation,
                                                                 calcloc.ID, allDeviceActions, deviceCategoryDtos);

            if (pickedDevice == null)
            {
                throw new DataIntegrityException(
                          "Affordance " + aff.Affordance.Name + " has broken devices. Please fix",
                          aff.Affordance);
            }

            // find the device in the calc devices
            var dev = devicesAtLocation.Single(calcDevice => calcDevice.Name == pickedDevice.Name);

            if (dev == null)
            {
                throw new DataIntegrityException(
                          "Affordance " + aff.Affordance.Name + " has broken devices. Please fix",
                          aff.Affordance);
            }

            if (devtup.Device == null)
            {
                throw new LPGException("Device was null");
            }

            switch (devtup.Device.AssignableDeviceType)
            {
            case AssignableDeviceType.Device:
            case AssignableDeviceType.DeviceCategory:
            {
                if (devtup.LoadType == null)
                {
                    throw new LPGException("No load type set");
                }
                if (ltdict.SimulateLoadtype(devtup.LoadType))
                {
                    if (devtup.TimeProfile == null)
                    {
                        throw new DataIntegrityException(
                                  "Affordance " + aff.Affordance.Name + " has broken time profiles. Please fix.",
                                  aff.Affordance);
                    }

                    var newprof =
                        CalcDeviceDtoFactory.GetCalcProfileDto(devtup.TimeProfile);
                    CalcLoadTypeDto loadtype = ltdict.GetLoadtypeDtoByLoadType(devtup.LoadType);
                    caff.AddDeviceTuple(dev.Name, dev.Guid, newprof, loadtype.Name, loadtype.Guid,
                                        devtup.TimeOffset, internalStepSize, 1, devtup.Probability);
                }
            }
            break;

            case AssignableDeviceType.DeviceAction:
            case AssignableDeviceType.DeviceActionGroup:
            {
                DeviceAction da;
                // if it's a device action group, then go back to the picker to select a specific
                // device action based on the available devices
                if (devtup.Device.AssignableDeviceType == AssignableDeviceType.DeviceActionGroup)
                {
                    da =
                        _picker.GetDeviceActionFromGroup(devtup.Device, devicesAtLocation,
                                                         allDeviceActions);
                }
                else
                {
                    da = (DeviceAction)devtup.Device;
                }
                if (da == null)
                {
                    throw new LPGException("Device action was null");
                }

                if (da.Profiles.Count == 0)
                {
                    throw new DataIntegrityException(
                              "The device action " + da.Name + " has no time profiles. Please fix", da);
                }

                foreach (var profile in da.Profiles)
                {
                    if (profile.VLoadType == null)
                    {
                        throw new LPGException("Profile was null");
                    }

                    if (ltdict.SimulateLoadtype(profile.VLoadType))
                    {
                        if (profile.Timeprofile == null)
                        {
                            throw new DataIntegrityException(
                                      "The device action " + da.Name + " has broken time profiles. Please fix.",
                                      da);
                        }

                        if (profile.VLoadType == null)
                        {
                            throw new DataIntegrityException(
                                      "The device action " + da.Name + " has broken load types. Please fix.", da);
                        }

                        var newprof =
                            CalcDeviceDtoFactory.GetCalcProfileDto(profile.Timeprofile);
                        CalcLoadTypeDto loadType = ltdict.GetLoadtypeDtoByLoadType(profile.VLoadType);
                        caff.AddDeviceTuple(dev.Name, dev.Guid, newprof, loadType.Name, loadType.Guid,
                                            profile.TimeOffset + devtup.TimeOffset, internalStepSize, profile.Multiplier,
                                            devtup.Probability);
                    }
                }
            }
            break;

            default:
                throw new LPGException(
                          "Missing an AssignableDeviceType at GetCalcAffordancesAtLocation! Please report to the programmer.");
            }
        }
Пример #5
0
        public List <CalcAffordanceTaggingSetDto> GetAffordanceTaggingSets([NotNull] Simulator sim)
        {
            var calcSets = new List <CalcAffordanceTaggingSetDto>();

            foreach (var affordanceTaggingSet in sim.AffordanceTaggingSets.MyItems)
            {
                var calcset = new CalcAffordanceTaggingSetDto(affordanceTaggingSet.Name,
                                                              affordanceTaggingSet.MakeCharts);
                foreach (var entry in affordanceTaggingSet.Entries)
                {
                    if (entry.Affordance == null)
                    {
                        throw new LPGException("Affordance was null");
                    }
                    var affName = CalcAffordanceFactory.FixAffordanceName(entry.Affordance.Name,
                                                                          sim.MyGeneralConfig.CSVCharacter);
                    if (entry.Tag == null)
                    {
                        throw new LPGException("Tag was null");
                    }
                    var tagname = CalcAffordanceFactory.FixAffordanceName(entry.Tag.Name,
                                                                          sim.MyGeneralConfig.CSVCharacter);
                    calcset.AddTag(affName, tagname);

                    foreach (var affordanceSubAffordance in entry.Affordance.SubAffordances)
                    {
                        if (affordanceSubAffordance.SubAffordance == null)
                        {
                            throw new LPGException("Subaffordance was null");
                        }

                        var subname = CalcAffordanceFactory.FixAffordanceName(
                            affordanceSubAffordance.SubAffordance.Name,
                            sim.MyGeneralConfig.CSVCharacter) + " (" + affName + ")";
                        if (!calcset.AffordanceToTagDict.ContainsKey(subname))
                        {
                            calcset.AddTag(subname, tagname);
                        }
                    }
                }

                foreach (var reference in affordanceTaggingSet.TagReferences)
                {
                    calcset.AddReference(reference.Tag.Name, reference.Gender, reference.MinAge, reference.MaxAge,
                                         reference.Percentage);
                }

                foreach (var tag in affordanceTaggingSet.Tags)
                {
                    calcset.Colors.Add(tag.Name, tag.CarpetPlotColor);
                }

                calcset.AddTag("taking a vacation", "vacation");
                foreach (var affordanceTaggingSetLoadType in affordanceTaggingSet.LoadTypes)
                {
                    if (affordanceTaggingSetLoadType.LoadType == null)
                    {
                        throw new LPGException("Load type was null");
                    }
                    if (_ltDict.SimulateLoadtype(affordanceTaggingSetLoadType.LoadType))
                    {
                        calcset.AddLoadType(_ltDict.Ltdtodict[affordanceTaggingSetLoadType.LoadType]);
                    }
                }

                calcSets.Add(calcset);
            }

            return(calcSets);
        }