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); }
public CalcModularHouseholdDtoFactory([NotNull] CalcLoadTypeDtoDictionary ltDict, [NotNull] Random random, [NotNull] CalcPersonDtoFactory calcPersonDtoFactory, [NotNull] CalcDeviceDtoFactory calcDeviceDtoFactory, [NotNull] CalcLocationDtoFactory calcLocationDtoFactory, [NotNull] CalcVariableDtoFactory calcVariableRepositoryDtoFactory, [NotNull] CalcAffordanceDtoFactory calcAffordanceDtoFactory, [NotNull] CalcTransportationDtoFactory transportationDtoFactory, CalcRepo calcRepo) { _ltDict = ltDict; _random = random; _calcPersonDtoFactory = calcPersonDtoFactory; _calcDeviceDtoFactory = calcDeviceDtoFactory; _calcLocationDtoFactory = calcLocationDtoFactory; _calcVariableRepositoryDtoFactory = calcVariableRepositoryDtoFactory; _calcAffordanceDtoFactory = calcAffordanceDtoFactory; _transportationDtoFactory = transportationDtoFactory; _calcRepo = calcRepo; }
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); }
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."); } }