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 CalcHouseFactory([NotNull] CalcLoadTypeDictionary ltDict, [NotNull] CalcModularHouseholdFactory cmhf, [NotNull] AvailabilityDtoRepository availabilityDtoRepository, [NotNull] CalcVariableRepository variableRepository, [NotNull] CalcDeviceTaggingSets calcDeviceTaggingSets, CalcRepo calcRepo) { _ltDict = ltDict; _cmhf = cmhf; _availabilityDtoRepository = availabilityDtoRepository; _variableRepository = variableRepository; _calcDeviceTaggingSets = calcDeviceTaggingSets; _calcRepo = calcRepo; }
public void RunTest() { using (WorkingDir wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { SqlResultLoggingService srls = new SqlResultLoggingService(wd.WorkingDirectory); var calcParameters = CalcParametersFactory.MakeGoodDefaults(); CalcLoadTypeDtoDictionary cltd = new CalcLoadTypeDtoDictionary(new Dictionary <VLoadType, CalcLoadTypeDto>()); CalcDeviceTaggingSetFactory cdtsf = new CalcDeviceTaggingSetFactory(calcParameters, cltd); using (DatabaseSetup ds = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { Simulator sim = new Simulator(ds.ConnectionString); CalcDeviceTaggingSets devicetaggingset = cdtsf.GetDeviceTaggingSets(sim, 2); DeviceTaggingSetLogger dtsl = new DeviceTaggingSetLogger(srls); List <DeviceTaggingSetInformation> cdts = new List <DeviceTaggingSetInformation>(); cdts.AddRange(devicetaggingset.AllCalcDeviceTaggingSets); dtsl.Run(Constants.GeneralHouseholdKey, cdts); wd.CleanUp(); ds.Cleanup(); } } }
public CalcManager GetCalcManager([NotNull] Simulator sim, [NotNull] CalcStartParameterSet csps, bool forceRandom) //, ICalcObject hh, //bool forceRandom, TemperatureProfile temperatureProfile, //GeographicLocation geographicLocation, EnergyIntensityType energyIntensity, //string fileVersion, LoadTypePriority loadTypePriority, [CanBeNull] DeviceSelection deviceSelection, //TransportationDeviceSet transportationDeviceSet, TravelRouteSet travelRouteSet, //) { csps.CalculationProfiler.StartPart(Utili.GetCurrentMethodAndClass() + " Initializing"); if (sim == null) { throw new LPGException("Simulation was null"); } if (csps.CalcOptions.Contains(CalcOption.LogAllMessages)) { Logger.Get().StartCollectingAllMessages(); } CalcManager cm = null; Logger.Info("Starting the calculation of " + csps.CalcTarget.Name); try { if (DoIntegrityRun) { SimIntegrityChecker.Run(sim); } if (csps.CalcTarget.CalcObjectType == CalcObjectType.House && (csps.LoadTypePriority == LoadTypePriority.RecommendedForHouseholds || csps.LoadTypePriority == LoadTypePriority.Mandatory)) { throw new DataIntegrityException( "You are trying to calculate a house with only the load types for a household. This would mess up the warm water calculations. Please fix the load type selection."); } var chh = csps.CalcTarget as ModularHousehold; var ds = GetDeviceSelection(csps, csps.CalcTarget, chh); var cpf = new CalcParametersFactory(); var calcParameters = cpf.MakeCalculationParametersFromConfig(csps, forceRandom); var sqlFileName = Path.Combine(csps.ResultPath, "Results.sqlite"); var builder = new ContainerBuilder(); RegisterEverything(sim, csps.ResultPath, csps, csps.CalcTarget, builder, sqlFileName, calcParameters, ds); csps.CalculationProfiler.StopPart(Utili.GetCurrentMethodAndClass() + " Initializing"); csps.CalculationProfiler.StartPart(Utili.GetCurrentMethodAndClass() + " Generating Model"); var container = builder.Build(); using (var scope = container.BeginLifetimeScope()) { var calcRepo = PrepareCalculation(sim, csps, scope, out var dtoltdict, out var dls, out var variableRepository); cm = new CalcManager(csps.ResultPath, //hh.Name, //householdPlans, //csps.LPGVersion, calcParameters.ActualRandomSeed, dls, variableRepository, calcRepo //scope.Resolve<SqlResultLoggingService>() ); //_calcParameters.Logfile = cm.Logfile; //_calcParameters.NormalDistributedRandom = normalDistributedRandom; //_calcParameters.RandomGenerator = randomGenerator; //_calcParameters.Odap = cm.Odap; //_calcParameters.EnergyIntensity = csps.EnergyIntensity; // no vacation times needed for the light array CalcObjectType cot; ICalcAbleObject ch; CalcVariableDtoFactory cvrdto = scope.Resolve <CalcVariableDtoFactory>(); CalcDeviceTaggingSets devicetaggingSets = scope.Resolve <CalcDeviceTaggingSets>(); if (csps.CalcTarget.GetType() == typeof(House)) { ch = MakeCalcHouseObject(sim, csps, csps.CalcTarget, scope, cvrdto, variableRepository, out cot, calcRepo); CalcHouse chd = (CalcHouse)ch; if (chd.EnergyStorages != null) { foreach (var calcEnergyStorage in chd.EnergyStorages) { foreach (var taggingSet in devicetaggingSets.AllCalcDeviceTaggingSets) { taggingSet.AddTag(calcEnergyStorage.Name, "Energy Storage"); } } } } else if (csps.CalcTarget.GetType() == typeof(ModularHousehold)) { ch = MakeCalcHouseholdObject(sim, csps, csps.CalcTarget, scope, cvrdto, variableRepository, out cot, calcRepo); } else { throw new LPGException("The type " + csps.CalcTarget.GetType() + " is missing!"); } if (calcRepo.CalcParameters.Options.Contains(CalcOption.HouseholdContents)) { calcRepo.InputDataLogger.Save(Constants.GeneralHouseholdKey, devicetaggingSets.AllCalcDeviceTaggingSets); } CalcObjectInformation coi = new CalcObjectInformation(cot, ch.Name, csps.ResultPath); if (calcRepo.CalcParameters.Options.Contains(CalcOption.HouseholdContents)) { calcRepo.InputDataLogger.Save(Constants.GeneralHouseholdKey, coi); } //this logger doesnt save json, but strings! calcRepo.InputDataLogger.Save(Constants.GeneralHouseholdKey, csps); calcRepo.InputDataLogger.Save(Constants.GeneralHouseholdKey, dtoltdict.GetLoadTypeDtos()); cm.SetCalcObject(ch); CalcManager.ExitCalcFunction = false; //LogSeed(calcParameters.ActualRandomSeed, lf.FileFactoryAndTracker, calcParameters); csps.CalculationProfiler.StopPart(Utili.GetCurrentMethodAndClass() + " Generating Model"); return(cm); } } catch { cm?.Dispose(); throw; } }