/// <summary> /// starter for real calcs /// </summary> public CalcStartParameterSet( [NotNull] Func <bool, string, ObservableCollection <ResultFileEntry>, bool> reportFinishFuncForHouseAndSettlement, [NotNull] Func <bool, string, string, bool> reportFinishFuncForHousehold, [NotNull] Func <object, bool> openTabFunc, [CanBeNull] ILPGDispatcher dispatcher, [NotNull] GeographicLocation geographicLocation, [NotNull] TemperatureProfile temperatureProfile, [NotNull] ICalcObject calcTarget, EnergyIntensityType energyIntensity, [NotNull] Func <bool> reportCancelFunc, bool resumeSettlement, [CanBeNull] DeviceSelection deviceSelection, LoadTypePriority loadTypePriority, [CanBeNull] TransportationDeviceSet transportationDeviceSet, [CanBeNull] TravelRouteSet travelRouteSet, [NotNull] List <CalcOption> calcOptions, DateTime officialSimulationStartTime, DateTime officialSimulationEndTime, TimeSpan internalTimeResolution, [NotNull] string csvCharacter, int selectedRandomSeed, TimeSpan externalTimeResolution, bool deleteDatFiles, bool writeExcelColumn, bool showSettlingPeriod, int settlingDays, int affordanceRepetitionCount, [NotNull] CalculationProfiler calculationProfiler, [CanBeNull] ChargingStationSet chargingStationSet, [CanBeNull][ItemNotNull] List <string> loadTypesToProcess, DeviceProfileHeaderMode deviceProfileHeaderMode, bool ignorePreviousActivitiesWhenNeeded, string resultPath, bool transportationEnabled) { IgnorePreviousActivitiesWhenNeeded = ignorePreviousActivitiesWhenNeeded; ResultPath = resultPath; LoadTypesToProcess = loadTypesToProcess; ExternalTimeResolution = externalTimeResolution; DeleteDatFiles = deleteDatFiles; WriteExcelColumn = writeExcelColumn; ShowSettlingPeriod = showSettlingPeriod; SettlingDays = settlingDays; AffordanceRepetitionCount = affordanceRepetitionCount; CalculationProfiler = calculationProfiler; SelectedRandomSeed = selectedRandomSeed; OfficialSimulationStartTime = officialSimulationStartTime; OfficialSimulationEndTime = officialSimulationEndTime; InternalTimeResolution = internalTimeResolution; CsvCharacter = csvCharacter; ReportFinishFuncForHouseAndSettlement = reportFinishFuncForHouseAndSettlement; ReportFinishFuncForHousehold = reportFinishFuncForHousehold; OpenTabFunc = openTabFunc; Dispatcher = dispatcher; GeographicLocation = geographicLocation; TemperatureProfile = temperatureProfile; CalcTarget = calcTarget; EnergyIntensity = energyIntensity; ReportCancelFunc = reportCancelFunc; ResumeSettlement = resumeSettlement; LPGVersion = Utili.GetCurrentAssemblyVersion(); DeviceSelection = deviceSelection; LoadTypePriority = loadTypePriority; TransportationDeviceSet = transportationDeviceSet; TravelRouteSet = travelRouteSet; CalcOptions = calcOptions; ChargingStationSet = chargingStationSet; DeviceProfileHeaderMode = deviceProfileHeaderMode; CalculationStartTime = DateTime.Now; TransportationEnabled = transportationEnabled; }
public HouseEntry(int houseSize, int maximumHouseSize, int number, EnergyIntensityType energyIntensityType) { HouseSize = houseSize; MaximumHouseSize = maximumHouseSize; Number = number; EnergyIntensityType = energyIntensityType; Households = new List <ICalcObject>(); }
public JsonModularHousehold([NotNull] string name, [CanBeNull] string description, StrGuid guid, CreationType creationType, [CanBeNull] JsonReference deviceSelection, EnergyIntensityType energyIntensityType, JsonReference vacation) { Name = name; Description = description; Guid = guid; CreationType = creationType; DeviceSelection = deviceSelection; EnergyIntensityType = energyIntensityType; Vacation = vacation; }
public SettlementInformation([NotNull] string csvCharacter, [NotNull] string name, EnergyIntensityType energyIntensity, [NotNull] string lpgVersion) { CSVCharacter = csvCharacter; Name = name; EnergyIntensity = energyIntensity; LPGVersion = lpgVersion; }
public EnergyIntensityForDisplay GetAllDisplayElement(EnergyIntensityType eit) { foreach (var energyIntensityForDisplay in All) { if (energyIntensityForDisplay.EnergyIntensityType == eit) { return(energyIntensityForDisplay); } } throw new LPGException("Energy intensity was not found"); }
public STHouseholdDistribution([CanBeNull] int?pID, [NotNull] string connectionString, int minimumNumber, int maximumNumber, double percentOfHouseholds, int settlementTemplateID, [NotNull] string name, EnergyIntensityType energyIntensity, StrGuid guid) : base(name, TableName, connectionString, guid) { TypeDescription = "Settlement Template Household Distribution"; ID = pID; _maximumNumber = maximumNumber; _minimumNumber = minimumNumber; _percentOfHouseholds = percentOfHouseholds; _settlementTemplateID = settlementTemplateID; _energyIntensity = energyIntensity; }
public override int GetHashCode() { unchecked // Overflow is fine, just wrap { int hash = 17; // Suitable nullity checks etc, of course :) hash = hash * 23 + EnergyIntensityType.GetHashCode(); hash = hash * 23 + HouseholdList.GetHashCode(); hash = hash * 23 + HouseSize.GetHashCode(); hash = hash * 23 + MaximumHouseSize.GetHashCode(); return(hash * 23 + Number.GetHashCode()); } }
public House([NotNull] string pName, [CanBeNull] string description, [CanBeNull] TemperatureProfile temperatureProfile, [CanBeNull] GeographicLocation geographicLocation, [CanBeNull] HouseType houseType, [NotNull] string connectionString, EnergyIntensityType energyIntensity, [CanBeNull] string source, CreationType creationType, StrGuid guid, [CanBeNull] int?pID = null) : base(pName, TableName, connectionString, guid) { ID = pID; TypeDescription = "House"; _description = description; _energyIntensityType = energyIntensity; _temperatureProfile = temperatureProfile; _geographicLocation = geographicLocation; _houseType = houseType; _source = source; _creationType = creationType; }
public bool ItemExists([NotNull] ICalcObject mycalcObject, [NotNull] GeographicLocation geoloc, [NotNull] TemperatureProfile temperatureProfile, EnergyIntensityType intensity, [NotNull] string lpgVersion) { foreach (var co in MyItems) { if (co.HouseholdName == mycalcObject.Name && co.GeographicLocationName == geoloc.Name && co.TemperatureProfile == temperatureProfile.Name && co.EnergyIntensity == intensity.ToString() && co.LPGVersion == lpgVersion) { return(true); } } return(false); }
//public const string TableName = "CalcStartParameterSet"; /// <summary> /// starter for unit tests /// </summary> public CalcStartParameterSet( [NotNull] GeographicLocation geographicLocation, [NotNull] TemperatureProfile temperatureProfile, [NotNull] ICalcObject calcTarget, EnergyIntensityType energyIntensity, bool resumeSettlement, [CanBeNull] DeviceSelection deviceSelection, LoadTypePriority loadTypePriority, [CanBeNull] TransportationDeviceSet transportationDeviceSet, [CanBeNull] ChargingStationSet chargingStationSet, [CanBeNull] TravelRouteSet travelRouteSet, [NotNull] List <CalcOption> calcOptions, DateTime officialSimulationStartTime, DateTime officialSimulationEndTime, TimeSpan internalTimeResolution, [NotNull] string csvCharacter, int selectedRandomSeed, TimeSpan externalTimeResolution, bool deleteDatFiles, bool writeExcelColumn, bool showSettlingPeriod, int settlingDays, int affordanceRepetitionCount, [NotNull] CalculationProfiler calculationProfiler, string resultPath, bool transportationEnabled) { OfficialSimulationStartTime = officialSimulationStartTime; OfficialSimulationEndTime = officialSimulationEndTime; InternalTimeResolution = internalTimeResolution; CsvCharacter = csvCharacter; SelectedRandomSeed = selectedRandomSeed; ExternalTimeResolution = externalTimeResolution; DeleteDatFiles = deleteDatFiles; WriteExcelColumn = writeExcelColumn; ShowSettlingPeriod = showSettlingPeriod; SettlingDays = settlingDays; AffordanceRepetitionCount = affordanceRepetitionCount; CalculationProfiler = calculationProfiler; GeographicLocation = geographicLocation; TemperatureProfile = temperatureProfile; CalcTarget = calcTarget; EnergyIntensity = energyIntensity; ResumeSettlement = resumeSettlement; LPGVersion = Utili.GetCurrentAssemblyVersion(); DeviceSelection = deviceSelection; LoadTypePriority = loadTypePriority; TransportationDeviceSet = transportationDeviceSet; TravelRouteSet = travelRouteSet; CalcOptions = calcOptions; ChargingStationSet = chargingStationSet; DeviceProfileHeaderMode = DeviceProfileHeaderMode.Standard; ResultPath = resultPath; CalculationStartTime = DateTime.Now; TransportationEnabled = transportationEnabled; }
public ModularHousehold([NotNull] string pName, [CanBeNull] int?id, [NotNull] string description, [NotNull] string connectionString, [CanBeNull] DeviceSelection deviceSelection, [NotNull] string source, [CanBeNull] int?generatorID, [CanBeNull] Vacation vacation, EnergyIntensityType energyIntensityType, CreationType creationType, StrGuid guid) : base(pName, TableName, connectionString, guid) { ID = id; _vacation = vacation; _energyIntensityType = energyIntensityType; _generatorID = generatorID; _source = source; _deviceSelection = deviceSelection; TypeDescription = "Modular Household"; _description = description; _creationType = creationType; _traits = new ObservableCollection <ModularHouseholdTrait>(); _persons = new ObservableCollection <ModularHouseholdPerson>(); }
private DeviceAction PickDeviceFromGroup([NotNull] DeviceActionGroup deviceGroup, EnergyIntensityType energyIntensity, [NotNull][ItemNotNull] ObservableCollection <DeviceAction> allDeviceActions, int locationID) { var deviceActions = deviceGroup.GetDeviceActions(allDeviceActions); if (deviceActions.Count == 0) { throw new DataIntegrityException("The device action group " + deviceGroup.Name + " has no devices but it is used. A device could not be picked from it."); } if (deviceActions[0].Device == null) { throw new LPGException("Device was null"); } var usedDeviceCategory = deviceActions[0].Device.DeviceCategory; if (usedDeviceCategory == null) { throw new LPGException("usedDeviceCategory was null"); } var ldt2 = new LocationDeviceTuple(usedDeviceCategory, locationID); if (_pickedDevices.ContainsKey(ldt2)) { // find the device picked earlier var rd = _pickedDevices[ldt2]; deviceActions = deviceActions.Where(x => x.Device == rd).ToList(); if (deviceActions.Count == 0) { throw new DataIntegrityException( "The device action group " + deviceGroup.Name + " has no entry for the device " + rd.PrettyName + ". Please fix.", rd); } } DeviceAction pickedDevice = null; // look for this device group in the device selection if (_deviceSelection != null && _deviceSelection.Actions.Count > 0) { foreach (var item in _deviceSelection.Actions) { if (item.DeviceActionGroup == deviceGroup) { pickedDevice = item.DeviceAction; } } } if (pickedDevice == null) { switch (energyIntensity) { case EnergyIntensityType.Random: var dstval = _random.Next(deviceActions.Count); pickedDevice = deviceActions[dstval]; break; case EnergyIntensityType.EnergySaving: { var pickeDeviceAction = deviceActions[0]; foreach (var deviceAction in deviceActions) { if (pickeDeviceAction.CalculateWeightedEnergyUse() > deviceAction.CalculateWeightedEnergyUse()) { pickeDeviceAction = deviceAction; } } pickedDevice = pickeDeviceAction; } break; case EnergyIntensityType.EnergySavingPreferMeasured: { var actions = TryToGetMeasured(deviceActions); var pickeDeviceAction = actions[0]; foreach (var deviceAction in actions) { if (pickeDeviceAction.CalculateWeightedEnergyUse() > deviceAction.CalculateWeightedEnergyUse()) { pickeDeviceAction = deviceAction; } } pickedDevice = pickeDeviceAction; } break; case EnergyIntensityType.EnergyIntensive: { var pickeDeviceAction = deviceActions[0]; foreach (var deviceAction in deviceActions) { if (pickeDeviceAction.CalculateWeightedEnergyUse() < deviceAction.CalculateWeightedEnergyUse()) { pickeDeviceAction = deviceAction; } } pickedDevice = pickeDeviceAction; } break; case EnergyIntensityType.EnergyIntensivePreferMeasured: { var actions = TryToGetMeasured(deviceActions); var pickeDeviceAction = actions[0]; foreach (var deviceAction in deviceActions) { if (pickeDeviceAction.CalculateWeightedEnergyUse() < deviceAction.CalculateWeightedEnergyUse()) { pickeDeviceAction = deviceAction; } } pickedDevice = pickeDeviceAction; } break; default: throw new LPGException("Unknown EnergyIntensityType"); } } Logger.Debug( "Picked " + pickedDevice.Name + " from " + deviceActions.Count + " device actions in the group."); if (pickedDevice == null) { throw new LPGException("Picked device was null"); } return(pickedDevice); }
// the real picking function that selects a device public RealDevice PickDeviceFromCategory(DeviceCategory deviceCategory, EnergyIntensityType energyIntensity, ObservableCollection <DeviceAction> deviceActions) { deviceCategory.RefreshSubDevices(); var rds = deviceCategory.SubDevices; if (rds.Count == 0) { throw new DataIntegrityException("The device category " + deviceCategory.Name + " has no devices but it is used. A device could not be picked from it."); } RealDevice pickedDevice = null; // look for this device category in the device selection if (_deviceSelection != null && _deviceSelection.Items.Count > 0) { foreach (var item in _deviceSelection.Items) { if (item.DeviceCategory == deviceCategory) { pickedDevice = item.Device; } } } if (pickedDevice == null) { switch (energyIntensity) { case EnergyIntensityType.Random: var dstval = _random.Next(rds.Count); pickedDevice = rds[dstval]; break; case EnergyIntensityType.EnergySaving: pickedDevice = rds[0]; foreach (var t in rds) { if (pickedDevice.WeightedEnergyIntensity > t.WeightedEnergyIntensity) { pickedDevice = t; } } break; case EnergyIntensityType.EnergySavingPreferMeasured: var devices = GetMeasuredDevicesFromRealDevices(deviceActions, rds); pickedDevice = devices[0]; foreach (var t in devices) { if (pickedDevice.WeightedEnergyIntensity > t.WeightedEnergyIntensity) { pickedDevice = t; } } break; case EnergyIntensityType.EnergyIntensive: pickedDevice = rds[0]; foreach (var t in rds) { if (pickedDevice.WeightedEnergyIntensity < t.WeightedEnergyIntensity) { pickedDevice = t; } } break; case EnergyIntensityType.EnergyIntensivePreferMeasured: var rdevices = GetMeasuredDevicesFromRealDevices(deviceActions, rds); pickedDevice = rdevices[0]; foreach (var t in rdevices) { if (pickedDevice.WeightedEnergyIntensity < t.WeightedEnergyIntensity) { pickedDevice = t; } } break; case EnergyIntensityType.AsOriginal: throw new DataIntegrityException("Not permitted energy intensity type here: As Original"); default: throw new DataIntegrityException("Unknown EnergyIntensityType"); } } Logger.Debug("Picked " + pickedDevice + " from " + rds.Count + " devices."); return(pickedDevice); }
private DeviceAction PickDeviceActionFromGroupAtHHLocation([NotNull] DeviceActionGroup deviceActionGroup, [NotNull][ItemNotNull] List <IAssignableDevice> allDevLocations, EnergyIntensityType energyIntensity, [NotNull] Location targetLoc, [NotNull][ItemNotNull] ObservableCollection <DeviceAction> allDeviceActions) { // check if there is already such a device // first get all device actions in the group var deviceActions = deviceActionGroup.GetDeviceActions(allDeviceActions); //then get all devices in all device actions var devices = deviceActions.Select(da => da.Device).ToList(); //then find if any of the locations already has a device for any of the device actions foreach (var device in allDevLocations) { if (devices.Contains(device)) { var devac = deviceActions.Single(x => x.Device == device); Logger.Debug( "Picked " + devac.Name + " from " + targetLoc.Name + " since the device for it was already there."); return(devac); } } return(PickDeviceFromGroup(deviceActionGroup, energyIntensity, allDeviceActions, targetLoc.IntID)); }
// this tries to double check if it's a device selection that's already been done public RealDevice GetOrPickDevice(IAssignableDevice dev, Location devLocation, EnergyIntensityType energyIntensity, List <IAssignableDevice> allDevLocations, ObservableCollection <DeviceAction> allDeviceActions) { // if it's already a device, we are done switch (dev.AssignableDeviceType) { case AssignableDeviceType.Device: return((RealDevice)dev); case AssignableDeviceType.DeviceCategory: { // check if we already dealt with this category at this Location var dc = (DeviceCategory)dev; var ldt = new LocationDeviceTuple(dc, devLocation.IntID); if (_pickedDevices.ContainsKey(ldt)) // && _pickedDevices[ldt] != null) { return(_pickedDevices[ldt]); } // pick a new one var result = PickRealDeviceFromCategoryAtHHLocation(dc, allDevLocations, energyIntensity, devLocation, allDeviceActions); if (result != null) { _pickedDevices.Add(ldt, result); } return(result); } case AssignableDeviceType.DeviceAction: return(((DeviceAction)dev).Device); case AssignableDeviceType.DeviceActionGroup: { // check if we already dealt with this group at this Location var deviceActionGroup = (DeviceActionGroup)dev; var ldt = new LocationDeviceTuple(deviceActionGroup, devLocation.IntID); if (_pickedDeviceActions.ContainsKey(ldt)) // && _pickedDevices[ldt] != null) { return(_pickedDeviceActions[ldt].Device); } var firstDeviceAction = deviceActionGroup.GetDeviceActions(allDeviceActions).First(); if (firstDeviceAction.Device == null) { throw new LPGException("Device was null"); } var usedDeviceCategory = firstDeviceAction.Device.DeviceCategory; if (usedDeviceCategory == null) { throw new LPGException("used device category was null"); } var ldt2 = new LocationDeviceTuple(usedDeviceCategory, devLocation.IntID); if (_pickedDevices.ContainsKey(ldt2)) { // find the device picked earlier var rd = _pickedDevices[ldt2]; return(rd); } // pick a new one var result = PickDeviceActionFromGroupAtHHLocation(deviceActionGroup, allDevLocations, energyIntensity, devLocation, allDeviceActions); _pickedDeviceActions.Add(ldt, result); if (result == null) { throw new LPGException("Device was null"); } _pickedDevices.Add(ldt2, result.Device); return(result.Device); } default: throw new LPGException("Forgotten AssignableDeviceType. Please report!"); } }
public RealDevice GetAutoDeviceDeviceFromDeviceCategoryOrDevice(IAssignableDevice dev, List <IAssignableDevice> alldevices, EnergyIntensityType energyIntensity, ObservableCollection <DeviceAction> deviceActions, int locationID) { if (dev == null) { throw new LPGException("Device was null"); } // bereits ein realDevice switch (dev.AssignableDeviceType) { case AssignableDeviceType.Device: return((RealDevice)dev); case AssignableDeviceType.DeviceCategory: // schauen, ob schon zugeordnet var dc = (DeviceCategory)dev; var ldt = new LocationDeviceTuple(dc, locationID); if (_pickedDevices.ContainsKey(ldt)) { return(_pickedDevices[ldt]); } // pruefen, ob eins der anderen devices fuer diese category zutrifft foreach (var assignableDevice in alldevices) { if (assignableDevice.AssignableDeviceType == AssignableDeviceType.Device) { var rd = (RealDevice)assignableDevice; if (rd.DeviceCategory == dc) { _pickedDevices.Add(ldt, rd); return(rd); } } } // einfach eins aussuchen var pickdev = PickDeviceFromCategory(dc, energyIntensity, deviceActions); _pickedDevices.Add(ldt, pickdev); return(pickdev); default: throw new LPGException("Forgotten Assignable Device Type! Please Report."); } }
public CalcHouseholdDto MakeCalcModularHouseholdDto([NotNull] Simulator sim, [NotNull] ModularHousehold mhh, [NotNull] TemperatureProfile temperatureProfile, [NotNull] HouseholdKey householdKey, [NotNull] GeographicLocation geographicLocation, [NotNull] out LocationDtoDict locationDict, [CanBeNull] TransportationDeviceSet transportationDeviceSet, [CanBeNull] TravelRouteSet travelRouteSet, EnergyIntensityType energyIntensity, [CanBeNull] ChargingStationSet chargingStationSet) { // _lf.RegisterKey(householdKey, mhh.PrettyName); var name = CalcAffordanceFactory.FixAffordanceName(mhh.Name, sim.MyGeneralConfig.CSVCharacter); if (geographicLocation == null) { throw new DataIntegrityException("no geographic Location was set"); } var et = energyIntensity; if (et == EnergyIntensityType.AsOriginal) { et = mhh.EnergyIntensityType; } name = name + " " + householdKey.Key; var locations = mhh.CollectLocations(); //var deviceLocationDict = new Dictionary<CalcLocation, List<IAssignableDevice>>(); var deviceLocationDtoDict = new Dictionary <CalcLocationDto, List <IAssignableDevice> >(); locationDict = new LocationDtoDict(); List <DeviceCategoryDto> deviceCategoryDtos = new List <DeviceCategoryDto>(); foreach (var deviceCategory in sim.DeviceCategories.It) { deviceCategoryDtos.Add(new DeviceCategoryDto(deviceCategory.FullPath, Guid.NewGuid().ToStrGuid())); } var locationDtos = _calcLocationDtoFactory.MakeCalcLocations(locations, householdKey, et, deviceLocationDtoDict, sim.DeviceActions.It, locationDict, deviceCategoryDtos); // persons if (mhh.Vacation == null) { throw new LPGException("Vacation was null"); } var personDtos = _calcPersonDtoFactory.MakePersonDtos(mhh.Persons.ToList(), householdKey, mhh.Vacation.VacationTimeframes(), mhh.CollectTraitDesires(), mhh.Name); if (_calcRepo.CalcParameters.Options.Contains(CalcOption.HouseholdContents)) { _calcRepo.InputDataLogger.SaveList(personDtos.ConvertAll(x => (IHouseholdKey)x)); } //mhh.Persons.ToList(),mhh.Vacation.VacationTimeframes(), sim.MyGeneralConfig.RepetitionCount,householdKey, locs[0],name); //CalcPersonFactory.AddTraitDesires(mhh.CollectTraitDesires(), calcpersons,sim.MyGeneralConfig.TimeStepsPerHour, chh.Name, new Dictionary<Desire, SharedDesireValue>()); //check if unhungry and unhungry join only have been added both //can't check it in the integrity checker, because that would mean having to duplicate the entire // desire collection logic /* foreach (CalcPerson person in calcpersons) { * var desires = * person.PersonDesires.Desires.Values.Where(x => x.Name.ToLower().Contains("unhungry") || x.Name.ToLower().Contains("un-hungry")).ToList(); * if (desires.Count > 1) { * throw new DataIntegrityException("More than one unhungry desire for the person " + person.Name, mhh); * } * }*/ // devices var deviceLocations = new List <DeviceLocationTuple>(); foreach (var modularHouseholdTrait in mhh.Traits) { // ReSharper disable once ConditionIsAlwaysTrueOrFalse if (modularHouseholdTrait.HouseholdTrait != null) { CollectDevicesFromTrait(modularHouseholdTrait.HouseholdTrait, deviceLocations); } } var deviceDtos = _calcDeviceDtoFactory.MakeCalcDevices(locationDtos, deviceLocations, et, householdKey, deviceLocationDtoDict, sim.DeviceActions.It, _ltDict, deviceCategoryDtos); if (_calcRepo.CalcParameters.Options.Contains(CalcOption.HouseholdContents)) { _calcRepo.InputDataLogger.SaveList(deviceDtos.ConvertAll(x => (IHouseholdKey)x)); } //autodevs var autonomousDevices = mhh.CollectAutonomousDevices(); if (mhh.Vacation == null) { throw new LPGException("Vacation was null"); } var autoDevDtos = _calcDeviceDtoFactory.MakeCalcAutoDevDtos(autonomousDevices, energyIntensity, householdKey, mhh.Vacation.VacationTimeframes(), mhh.Name + "###" + householdKey, sim.DeviceActions.It, locationDict, temperatureProfile, geographicLocation, deviceCategoryDtos); if (_calcRepo.CalcParameters.Options.Contains(CalcOption.HouseholdContents)) { _calcRepo.InputDataLogger.SaveList(autoDevDtos.ConvertAll(x => (IHouseholdKey)x)); } //affordances var affordancesAtLoc = new Dictionary <CalcLocationDto, List <AffordanceWithTimeLimit> >(); foreach (var location in locations) { affordancesAtLoc.Add(locationDict.GetDtoForLocation(location), mhh.GetAllAffordancesForLocation(location)); } if (mhh.Vacation == null) { throw new LPGException("Vacation was null"); } List <CalcAffordanceDto> allAffordances = _calcAffordanceDtoFactory.SetCalcAffordances(locationDtos, temperatureProfile, _ltDict, geographicLocation, _random, sim.MyGeneralConfig.TimeStepsPerHour, sim.MyGeneralConfig.InternalStepSize, mhh.Vacation.VacationTimeframes(), mhh.Name + "###" + householdKey, sim.DeviceActions.MyItems, affordancesAtLoc, locationDict, out List <DateTime> bridgeDays, householdKey, deviceDtos, deviceCategoryDtos); if (_calcRepo.CalcParameters.Options.Contains(CalcOption.HouseholdContents)) { _calcRepo.InputDataLogger.SaveList(allAffordances.ConvertAll(x => (IHouseholdKey)x)); _calcRepo.InputDataLogger.SaveList(_calcVariableRepositoryDtoFactory.GetAllVariableDtos() .ConvertAll(x => (IHouseholdKey)x)); } // SaveVariableDefinitionsDtos(_calcVariableRepositoryDtoFactory.GetAllVariableDtos()); //CalcVariableRepository variableRepository = _calcVariableRepositoryDtoFactory.GetRepository(householdKey); List <CalcSiteDto> sites = null; List <CalcTransportationDeviceDto> transportationDevices = null; List <CalcTravelRouteDto> routes = null; if (_calcRepo.CalcParameters.TransportationEnabled) { _transportationDtoFactory.MakeTransportationDtos(sim, mhh, transportationDeviceSet, travelRouteSet, chargingStationSet, out sites, out transportationDevices, out routes, locationDtos, householdKey); if (_calcRepo.CalcParameters.IsSet(CalcOption.TransportationStatistics)) { _calcRepo.InputDataLogger.SaveList(sites.ConvertAll(x => (IHouseholdKey)x)); _calcRepo.InputDataLogger.SaveList(transportationDevices.ConvertAll(x => (IHouseholdKey)x)); _calcRepo.InputDataLogger.SaveList(routes.ConvertAll(x => (IHouseholdKey)x)); } } var chh = new CalcHouseholdDto(name, mhh.IntID, temperatureProfile.Name, householdKey, Guid.NewGuid().ToStrGuid(), geographicLocation.Name, bridgeDays, autoDevDtos, locationDtos, personDtos, deviceDtos, allAffordances, mhh.Vacation.VacationTimeframes(), sites, routes, transportationDevices, mhh.Description); if (_calcRepo.CalcParameters.Options.Contains(CalcOption.HouseholdContents)) { _calcRepo.InputDataLogger.Save(householdKey, chh); } if (_calcRepo.CalcParameters.Options.Contains(CalcOption.HouseholdContents)) { BridgeDayEntries bdes = new BridgeDayEntries(householdKey, chh.BridgeDays); _calcRepo.InputDataLogger.Save(householdKey, bdes); } return(chh); }
private CalcAutoDevDto MakeAutoDevFromDevice(EnergyIntensityType energyIntensity, [NotNull] HouseholdKey householdKey, [ItemNotNull][NotNull] ObservableCollection <DeviceAction> deviceActions, [ItemNotNull][NotNull] List <DeviceCategoryDto> deviceCategoryDtos, [NotNull] HouseTypeDevice hhautodev, [ItemNotNull][NotNull] List <IAssignableDevice> allAutonomousDevices, [NotNull] CalcLocationDto calcLocation, [NotNull] AvailabilityDataReferenceDto timearray ) { if (hhautodev.LoadType == null) { throw new LPGException("Loadtype was null"); } if (hhautodev.TimeProfile == null) { throw new LPGException("TimeProfile was null"); } if (_ltDict.SimulateLoadtype(hhautodev.LoadType)) { var profile = CalcDeviceDtoFactory.GetCalcProfileDto(hhautodev.TimeProfile); if (hhautodev.Location == null) { throw new LPGException("Location was null"); } var rd = _picker.GetAutoDeviceDeviceFromDeviceCategoryOrDevice(hhautodev.Device, allAutonomousDevices, energyIntensity, deviceActions, hhautodev.Location.IntID); var cdl = CalcDeviceDtoFactory.MakeCalcDeviceLoads(rd, _ltDict); var lt = _ltDict.Ltdtodict[hhautodev.LoadType]; CalcVariableDto variable = null; if (hhautodev.Variable != null) { var v = hhautodev.Variable; variable = _calcVariableDtoFactory.RegisterVariableIfNotRegistered(v, calcLocation.Name, calcLocation.Guid, householdKey); } List <VariableRequirementDto> reqDtos = new List <VariableRequirementDto>(); if (variable?.Name != null) { VariableRequirementDto req = new VariableRequirementDto(variable.Name, hhautodev.VariableValue, calcLocation.Name, calcLocation.Guid, hhautodev.VariableCondition, variable.Guid); reqDtos.Add(req); } //TODO: xxx missing probability? if (rd.DeviceCategory == null) { throw new LPGException("Device category was null"); } DeviceCategoryDto deviceCategoryDto = deviceCategoryDtos.Single(x => x.FullCategoryName == rd.DeviceCategory.FullPath); var cautodev = new CalcAutoDevDto(rd.Name, profile, lt.Name, lt.Guid, cdl, (double)hhautodev.TimeStandardDeviation, deviceCategoryDto.Guid, householdKey, 1, calcLocation.Name, calcLocation.Guid, deviceCategoryDto.FullCategoryName, Guid.NewGuid().ToStrGuid(), timearray, reqDtos, deviceCategoryDto.FullCategoryName); //cautodev.ApplyBitArry(busyarr, _ltDict.LtDict[hhautodev.LoadType]); return(cautodev); } return(null); }
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 List <CalcAutoDevDto> MakeCalcAutoDevsFromHouse([NotNull] TemperatureProfile temperatureProfile, [NotNull] GeographicLocation geographicLocation, [NotNull][ItemNotNull] ObservableCollection <HouseTypeDevice> houseDevices, EnergyIntensityType energyIntensity, [NotNull] HouseholdKey householdKey, [NotNull] string holidayKey, [NotNull][ItemNotNull] ObservableCollection <DeviceAction> deviceActions, [NotNull] House house, [NotNull][ItemNotNull] out List <CalcLocationDto> deviceLocations, [ItemNotNull][NotNull] List <DeviceCategoryDto> deviceCategoryDtos) { deviceLocations = new List <CalcLocationDto>(); var vacationTimeframes = new List <VacationTimeframe>(); if (house.HouseType?.HouseDevices != null) { if (house.Households.Count == 1) { vacationTimeframes.AddRange(house.Households[0].VacationTimeframes); } } var autodevs = new List <CalcAutoDevDto>(houseDevices.Count); // zur kategorien zuordnung var allAutonomousDevices = new List <IAssignableDevice>(); foreach (var hhautodev in houseDevices) { allAutonomousDevices.Add(hhautodev.Device); } foreach (var hhautodev in houseDevices) { var busyarr = new BitArray(_calcParameters.InternalTimesteps); busyarr.SetAll(false); if (hhautodev.TimeLimit != null) { Logger.Debug("Determining the permitted times for each autonomous device. Device: " + hhautodev.Name); if (hhautodev.TimeLimit.RootEntry == null) { throw new LPGException(" was null"); } busyarr = hhautodev.TimeLimit.RootEntry.GetOneYearArray(_calcParameters.InternalStepsize, _calcParameters.InternalStartTime, _calcParameters.InternalEndTime, temperatureProfile, geographicLocation, _random, vacationTimeframes, holidayKey, out _, 0, 0, 0, 0); // invertieren von erlaubten zu verbotenen zeiten busyarr = busyarr.Not(); } var availref = _availabilityDtoRepository.MakeNewReference(hhautodev.TimeLimit?.Name ?? "No Name", busyarr); if (hhautodev.TimeLimit == null) { throw new LPGException("Time limit was null on the autonomous device in the house " + house.Name + " for the device " + hhautodev.Name); } var timearray = _availabilityDtoRepository.MakeNewReference(hhautodev.TimeLimit.Name, busyarr); if (hhautodev.Location == null) { throw new LPGException("Location was null"); } if (hhautodev.Device == null) { throw new LPGException("Device was null"); } if (deviceLocations.All(x => x.Name != hhautodev.Location.Name)) { deviceLocations.Add(new CalcLocationDto(hhautodev.Location.Name, hhautodev.Location.IntID, Guid.NewGuid().ToStrGuid())); } var calcLocation = deviceLocations.Single(x => x.Name == hhautodev.Location.Name); switch (hhautodev.Device.AssignableDeviceType) { case AssignableDeviceType.Device: case AssignableDeviceType.DeviceCategory: var adev1 = MakeAutoDevFromDevice(energyIntensity, householdKey, deviceActions, deviceCategoryDtos, hhautodev, allAutonomousDevices, calcLocation, timearray); autodevs.Add(adev1); break; case AssignableDeviceType.DeviceAction: case AssignableDeviceType.DeviceActionGroup: MakeAutoDevFromDeviceAction(energyIntensity, householdKey, deviceActions, deviceCategoryDtos, hhautodev, allAutonomousDevices, calcLocation, availref, autodevs); break; default: throw new LPGException("Forgotten AssignableDeviceType. Please Report!"); } } /* if (autodevs.Count > houseDevices.Count) { * throw new LPGException("Made too many autonomous devices in the house. This is a bug."); * }*/ return(autodevs); }
public CalcHouseDto MakeHouseDto([NotNull] Simulator sim, [NotNull] House house, [NotNull] TemperatureProfile temperatureProfile, [NotNull] GeographicLocation geographicLocation, //List<CalcDeviceTaggingSet> taggingSets, EnergyIntensityType energyIntensity) { if (house.HouseType == null) { throw new LPGException("Housetype was null"); } if (energyIntensity == EnergyIntensityType.AsOriginal) { energyIntensity = house.EnergyIntensityType; } if (energyIntensity == EnergyIntensityType.AsOriginal) { var calcObject = house.Households[0].CalcObject; if (calcObject == null) { throw new LPGException("House was null"); } energyIntensity = calcObject.EnergyIntensityType; } var houseLocations = new List <CalcLocationDto>(); HouseholdKey houseKey = Constants.HouseKey; List <DeviceCategoryDto> deviceCategoryDtos = new List <DeviceCategoryDto>(); foreach (var deviceCategory in sim.DeviceCategories.It) { deviceCategoryDtos.Add(new DeviceCategoryDto(deviceCategory.FullPath, Guid.NewGuid().ToStrGuid())); } HouseIntegrityChecker.Run(house, sim); var householdIndex = 1; var calcAbleObjects = new List <CalcHouseholdDto>(); var globalLocationDict = new Dictionary <Location, CalcLocationDto>(); foreach (var household in house.Households) { if (household.CalcObject == null) { throw new LPGException("Calcobject was null"); } if (household.CalcObject.CalcObjectType == CalcObjectType.ModularHousehold) { CalcHouseholdDto hhdto = _hhDtoFactory.MakeCalcModularHouseholdDto(sim, (ModularHousehold)household.CalcObject, temperatureProfile, new HouseholdKey("HH" + householdIndex), geographicLocation, out var locationDtoDict, household.TransportationDeviceSet, household.TravelRouteSet, energyIntensity, household.ChargingStationSet); calcAbleObjects.Add(hhdto); foreach (var pair in locationDtoDict.LocationDict) { if (!globalLocationDict.ContainsKey(pair.Key)) { globalLocationDict.Add(pair.Key, pair.Value); } } } else { throw new LPGException("Unknown Calc Object Type in the house! This is a bug."); } householdIndex++; } var spaceHeating = CreateSpaceHeatingObject(house, temperatureProfile, houseKey, out var heatingLocation, _calcParameters.InternalStartTime, _calcParameters.InternalEndTime , _ltDict); //, taggingSets); if (heatingLocation != null) { houseLocations.Add(heatingLocation); } var airconditioning = MakeAirConditioning(temperatureProfile, house.HouseType, houseKey, out var airconditioningLocation); if (airconditioningLocation != null) { houseLocations.Add(airconditioningLocation); } List <CalcAutoDevDto> autoDevs = new List <CalcAutoDevDto>(); var autodevs2 = MakeCalcAutoDevsFromHouse(temperatureProfile, geographicLocation, house.HouseType.HouseDevices, energyIntensity, houseKey, house.Name, sim.DeviceActions.It, house, out var devLocations, deviceCategoryDtos); houseLocations.AddRange(devLocations); autoDevs.AddRange(autodevs2); // energy Storage var calcEnergyStorages = MakeEnergyStorages(house, houseKey); //, taggingSets); // transformation devices var transformationDevices = MakeAllTransformationDevices(house.HouseType, houseKey); //taggingSets, // generators var generators = MakeGenerators(house.HouseType.HouseGenerators.Select(x => x.Generator).ToList(), houseKey); //taggingSets, var calchouse = new CalcHouseDto(house.Name, autoDevs, airconditioning, spaceHeating, calcEnergyStorages, generators, transformationDevices, calcAbleObjects, houseKey, houseLocations, house.Description); //check the calc variables return(calchouse); }
private RealDevice PickRealDeviceFromCategoryAtHHLocation([NotNull] DeviceCategory deviceCategory, [NotNull][ItemNotNull] List <IAssignableDevice> allDevicesAtLocations, EnergyIntensityType energyIntensity, [NotNull] Location targetLoc, [NotNull][ItemNotNull] ObservableCollection <DeviceAction> deviceActions) { // check if there is already such a device foreach (var device in allDevicesAtLocations) { if (device.AssignableDeviceType == AssignableDeviceType.Device) { var rd = (RealDevice)device; if (rd.DeviceCategory == deviceCategory) { Logger .Debug( "Picked " + rd.Name + " from " + targetLoc.Name + " since it was already there."); return(null); } } } return(PickDeviceFromCategory(deviceCategory, energyIntensity, deviceActions)); }
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); }
private void MakeAutoDevFromDeviceAction(EnergyIntensityType energyIntensity, [NotNull] HouseholdKey householdKey, [ItemNotNull][NotNull] ObservableCollection <DeviceAction> deviceActions, [ItemNotNull][NotNull] List <DeviceCategoryDto> deviceCategoryDtos, [NotNull] HouseTypeDevice hhautodev, [ItemNotNull][NotNull] List <IAssignableDevice> allAutonomousDevices, [NotNull] CalcLocationDto calcLocation, [NotNull] AvailabilityDataReferenceDto availref, List <CalcAutoDevDto> autodevs ) { if (hhautodev.Location == null) { throw new LPGException("Location was null"); } if (hhautodev.Device == null) { throw new LPGException("Device was null"); } var deviceAction = _picker.GetAutoDeviceActionFromGroup(hhautodev.Device, allAutonomousDevices, energyIntensity, deviceActions, hhautodev.Location.IntID); foreach (var actionProfile in deviceAction.Profiles) { if (actionProfile.VLoadType == null) { throw new LPGException("Loadtype was null"); } if (actionProfile.Timeprofile == null) { throw new LPGException("Timeprofile was null"); } if (_ltDict.SimulateLoadtype(actionProfile.VLoadType)) { var profile = CalcDeviceDtoFactory.GetCalcProfileDto(actionProfile.Timeprofile); if (deviceAction.Device == null) { throw new LPGException("Device was null"); } var cdl = CalcDeviceDtoFactory.MakeCalcDeviceLoads(deviceAction.Device, _ltDict); var lt = _ltDict.Ltdtodict[actionProfile.VLoadType]; CalcVariableDto variable = null; if (hhautodev.Variable != null) { var v = hhautodev.Variable; variable = _calcVariableDtoFactory.RegisterVariableIfNotRegistered(v, calcLocation.Name, calcLocation.Guid, householdKey); } List <VariableRequirementDto> reqDtos = new List <VariableRequirementDto>(); if (variable?.Name != null) { VariableRequirementDto req = new VariableRequirementDto(variable.Name, hhautodev.VariableValue, calcLocation.Name, calcLocation.Guid, hhautodev.VariableCondition, variable.Guid); reqDtos.Add(req); } if (deviceAction.Device.DeviceCategory == null) { throw new LPGException("Device was null"); } DeviceCategoryDto devcat = 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, devcat.Guid, householdKey, actionProfile.Multiplier, calcLocation.Name, calcLocation.Guid, devcat.FullCategoryName, Guid.NewGuid().ToStrGuid(), availref, reqDtos, devcat.FullCategoryName); autodevs.Add(cautodev); //cautodev.ApplyBitArry(, _ltDict.LtDict[actionProfile.VLoadType]); } } }
public List <CalcDeviceDto> MakeCalcDevices([NotNull][ItemNotNull] List <CalcLocationDto> locs, [ItemNotNull][NotNull] List <DeviceLocationTuple> devlocs, EnergyIntensityType energyIntensity, [NotNull] HouseholdKey householdKey, [NotNull] Dictionary <CalcLocationDto, List <IAssignableDevice> > allreadyAssigendDeviceLocationDict, [NotNull][ItemNotNull] ObservableCollection <DeviceAction> deviceActions, [NotNull] CalcLoadTypeDtoDictionary loadtypes, [ItemNotNull][NotNull] List <DeviceCategoryDto> deviceCategories) { List <CalcDeviceDto> calcDeviceDtos = new List <CalcDeviceDto>(); foreach (var devloc in devlocs) { var locdto = locs.First(x => x.ID == devloc.Location.IntID); // ggf dev category / device action in dev umwandeln var devicesAtLocation = devlocs.Where(x => x.Location == devloc.Location).Select(x => x.Device).ToList(); var rd = _picker.GetOrPickDevice(devloc.Device, devloc.Location, energyIntensity, devicesAtLocation, deviceActions); //save the picked device so that next time it will be picked again if (!allreadyAssigendDeviceLocationDict[locdto].Contains(devloc.Device)) { allreadyAssigendDeviceLocationDict[locdto].Add(devloc.Device); } if (!allreadyAssigendDeviceLocationDict[locdto].Contains(rd)) { allreadyAssigendDeviceLocationDict[locdto].Add(rd); } if (rd == null) // null means that no device needed to be picked since it already exists { continue; } bool found = calcDeviceDtos.Any(x => rd.Name == x.Name && locdto.Guid == x.LocationGuid); if (found) { Logger.Info( "Device " + rd.Name + " existed already in the Location " + locdto.Name + ". Skipping..."); } else { if (rd.DeviceCategory == null) { throw new LPGException("Device Category was null"); } DeviceCategoryDto dcdto = deviceCategories.Single(x => x.FullCategoryName == rd.DeviceCategory.FullPath); CalcDeviceDto cdd = new CalcDeviceDto(rd.Name, dcdto.Guid, householdKey, OefcDeviceType.Device, rd.DeviceCategory.FullPath, string.Empty, Guid.NewGuid().ToStrGuid(), locdto.Guid, locdto.Name); cdd.AddLoads(MakeCalcDeviceLoads(rd, loadtypes)); calcDeviceDtos.Add(cdd); } } return(calcDeviceDtos); }
public DeviceAction GetAutoDeviceActionFromGroup(IAssignableDevice dev, List <IAssignableDevice> otherDevicesAtLocation, EnergyIntensityType energyIntensity, ObservableCollection <DeviceAction> allDeviceActions, int locationID) { if (dev == null) { throw new LPGException("Device was null"); } switch (dev.AssignableDeviceType) { case AssignableDeviceType.DeviceAction: return((DeviceAction)dev); case AssignableDeviceType.DeviceActionGroup: // schauen, ob schon zugeordnet var deviceActionGroup = (DeviceActionGroup)dev; var ldt = new LocationDeviceTuple(deviceActionGroup, locationID); if (_pickedDeviceActions.ContainsKey(ldt)) { return(_pickedDeviceActions[ldt]); } // pruefen, ob eins der anderen devices fuer diese group zutrifft var myActions = deviceActionGroup.GetDeviceActions(allDeviceActions); foreach (var deviceAction in myActions) { if (otherDevicesAtLocation.Contains(deviceAction)) { var action = (DeviceAction)otherDevicesAtLocation.First(anondev => anondev == deviceAction); _pickedDevices.Add(ldt, action.Device); return(action); } } // see if another device from the same device category was already picked // einfach eins aussuchen var pickdevAction = PickDeviceFromGroup(deviceActionGroup, energyIntensity, allDeviceActions, locationID); _pickedDeviceActions.Add(ldt, pickdevAction); // ReSharper disable once ConditionIsAlwaysTrueOrFalse // ReSharper disable once HeuristicUnreachableCode if (pickdevAction == null) { // ReSharper disable once HeuristicUnreachableCode throw new LPGException("Picked device was null"); } return(pickdevAction); default: throw new LPGException("Forgotten AssignableDeviceType in GetAutoDeviceDevice. Please Report!"); } }
public EnergyIntensityForDisplay(EnergyIntensityType energyIntensityType, [NotNull] string name) { EnergyIntensityType = energyIntensityType; Name = name; }
public CalcDataRepository StartHousehold(int householdNumber, [JetBrains.Annotations.NotNull] string csvCharacter, LoadTypePriority priority = LoadTypePriority.Mandatory, [CanBeNull] DateTime?enddate = null, [CanBeNull] Action <GeneralConfig> configSetter = null, EnergyIntensityType energyIntensity = EnergyIntensityType.EnergyIntensive, bool useHouse = false) #pragma warning restore RCS1141 // Add parameter to documentation comment. { Config.IsInUnitTesting = true; //string dstDirName;// = "Household" + householdNumber; //if (useHouse) { // dstDirName = "House" + householdNumber; //} //if (directoryName != null) { _db = new DatabaseSetup("CalcStarterTests." + _directoryName); var sim = new Simulator(_db.ConnectionString) { MyGeneralConfig = { StartDateDateTime = new DateTime(2012, 1, 1), EndDateDateTime = new DateTime(2012, 1, 31) } }; if (enddate != null) { sim.MyGeneralConfig.EndDateDateTime = enddate.Value; } sim.MyGeneralConfig.RandomSeed = -1; sim.MyGeneralConfig.CSVCharacter = csvCharacter; sim.MyGeneralConfig.ExternalTimeResolution = "00:15:00"; sim.MyGeneralConfig.InternalTimeResolution = "00:01:00"; sim.MyGeneralConfig.ApplyOptionDefault(OutputFileDefault.NoFiles); configSetter?.Invoke(sim.MyGeneralConfig); Logger.Info("Enabled options are:"); foreach (var option in sim.MyGeneralConfig.AllEnabledOptions()) { Logger.Info(option.ToString()); } Logger.Info("External time resolution is: " + sim.MyGeneralConfig.ExternalTimeResolution); var cs = new CalcStarter(sim); Logger.Info("Number of modular households:" + sim.ModularHouseholds.MyItems.Count); if (sim.ModularHouseholds.MyItems.Count <= householdNumber) { return(null); } if ( sim.ModularHouseholds[householdNumber].Description.ToLower(CultureInfo.CurrentCulture) .StartsWith("only for modular", StringComparison.Ordinal)) { return(null); } string workingDir = Wd.WorkingDirectory; CalculationProfiler calculationProfiler = new CalculationProfiler(); if (useHouse) { var house = sim.Houses.It[householdNumber]; Logger.Info("CHH Device selection:" + house.Name); var cspsHouse = new CalcStartParameterSet(ReportFinishFuncForHouseAndSettlement, ReportFinishFuncForHousehold, OpenTabFunc, null, sim.GeographicLocations[0], sim.TemperatureProfiles[0], house, energyIntensity, ReportCancelFunc, false, null, priority, null, null, sim.MyGeneralConfig.AllEnabledOptions(), sim.MyGeneralConfig.StartDateDateTime, sim.MyGeneralConfig.EndDateDateTime, sim.MyGeneralConfig.InternalStepSize, ";", -1, new TimeSpan(0, 15, 0), false, false, false, 3, 3, calculationProfiler, null, null, DeviceProfileHeaderMode.Standard, false, workingDir, false); var duration = cspsHouse.OfficialSimulationEndTime - cspsHouse.OfficialSimulationStartTime; if (duration.TotalDays > 370) { throw new LPGException("Trying to test with more than 1 year"); } cs.Start(cspsHouse); return(null); } var chh = sim.ModularHouseholds[householdNumber]; Logger.Info("Modular Household Device selection:" + chh.DeviceSelection?.Name); var csps = new CalcStartParameterSet(ReportFinishFuncForHouseAndSettlement, ReportFinishFuncForHousehold, OpenTabFunc, null, sim.GeographicLocations[0], sim.TemperatureProfiles[0], chh, energyIntensity, ReportCancelFunc, false, null, priority, null, null, sim.MyGeneralConfig.AllEnabledOptions(), sim.MyGeneralConfig.StartDateDateTime, sim.MyGeneralConfig.EndDateDateTime, sim.MyGeneralConfig.InternalStepSize, ";", -1, new TimeSpan(0, 15, 0), false, false, false, 3, 3, calculationProfiler, null, null, DeviceProfileHeaderMode.Standard, false, workingDir, false); var simduration = csps.OfficialSimulationEndTime - csps.OfficialSimulationStartTime; if (simduration.TotalDays > 370) { throw new LPGException("Trying to test with more than 1 year"); } cs.Start(csps); CalcDataRepository cdr = new CalcDataRepository(Wd.SqlResultLoggingService); //sim.ModularHouseholds[householdNumber].Name return(cdr); }