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); }
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); }
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."); } }