public void GetCalcManagerHouseTest() { using (var wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { var sim = new Simulator(db.ConnectionString); sim.MyGeneralConfig.ApplyOptionDefault(OutputFileDefault.OnlyOverallSum); //ConfigSetter.SetGlobalTimeParameters(sim.MyGeneralConfig); sim.Should().NotBeNull(); var cmf = new CalcManagerFactory(); CalculationProfiler calculationProfiler = new CalculationProfiler(); CalcStartParameterSet csps = new CalcStartParameterSet(sim.GeographicLocations[0], sim.TemperatureProfiles[0], sim.Houses[sim.Houses.MyItems.Count - 1], EnergyIntensityType.Random, false, null, LoadTypePriority.RecommendedForHouses, null, null, null, sim.MyGeneralConfig.AllEnabledOptions(), new DateTime(2015, 1, 15), new DateTime(2015, 1, 18), new TimeSpan(0, 1, 0), ";", -1, new TimeSpan(0, 1, 0), false, false, false, 3, 3, calculationProfiler, wd.WorkingDirectory, false); var cm = cmf.GetCalcManager(sim, csps, false); cm.Run(ReportCancelFunc); db.Cleanup(); } wd.CleanUp(); } }
private static CalcRepo PrepareCalculation([NotNull] Simulator sim, [NotNull] CalcStartParameterSet csps, [NotNull] ILifetimeScope scope, [NotNull] out CalcLoadTypeDtoDictionary dtoltdict, [NotNull] out DayLightStatus dls, [NotNull] out CalcVariableRepository variableRepository ) { CalcRepo calcRepo = scope.Resolve <CalcRepo>(); var inputDataLogger = scope.Resolve <IInputDataLogger>(); inputDataLogger.Save(Constants.GeneralHouseholdKey, calcRepo.CalcParameters); inputDataLogger.Save(Constants.GeneralHouseholdKey, csps.TemperatureProfile); dtoltdict = scope.Resolve <CalcLoadTypeDtoDictionary>(); var affordanceTaggingSetFactory = scope.Resolve <AffordanceTaggingSetFactory>(); var affordanceTaggingSets = affordanceTaggingSetFactory.GetAffordanceTaggingSets(sim); if (calcRepo.CalcParameters.Options.Contains(CalcOption.AffordanceTaggingSets)) { inputDataLogger.Save(affordanceTaggingSets); } calcRepo.FileFactoryAndTracker.RegisterGeneralHouse(); dls = scope.Resolve <DayLightStatus>(); if (calcRepo.CalcParameters.Options.Contains(CalcOption.DaylightTimesList)) { inputDataLogger.Save(Constants.GeneralHouseholdKey, dls); } variableRepository = scope.Resolve <CalcVariableRepository>(); return(calcRepo); }
private static ICalcAbleObject MakeCalcHouseObject([NotNull] Simulator sim, [NotNull] CalcStartParameterSet csps, [NotNull] ICalcObject hh, [NotNull] ILifetimeScope scope, [NotNull] CalcVariableDtoFactory cvrdto, [NotNull] CalcVariableRepository variableRepository, out CalcObjectType cot, [NotNull] CalcRepo calcRepo) { var house = (House)hh; calcRepo.FileFactoryAndTracker.RegisterHousehold(Constants.HouseKey, "House Infrastructure", HouseholdKeyType.House, "House Infrastructure", house.Name, house.Description); var housedtoFac = scope.Resolve <CalcHouseDtoFactory>(); var housedto = housedtoFac.MakeHouseDto(sim, house, csps.TemperatureProfile, csps.GeographicLocation, csps.EnergyIntensity); foreach (HouseholdKeyEntry entry in housedto.GetHouseholdKeyEntries()) { calcRepo.InputDataLogger.Save(Constants.GeneralHouseholdKey, entry); } var convertedAutoDevList = housedto.AutoDevs.ConvertAll(x => (IHouseholdKey)x).ToList(); if (calcRepo.CalcParameters.Options.Contains(CalcOption.HouseholdContents)) { calcRepo.InputDataLogger.SaveList(convertedAutoDevList); calcRepo.InputDataLogger.Save(Constants.GeneralHouseholdKey, housedto); } var chf = scope.Resolve <CalcHouseFactory>(); RegisterAllDtoVariables(cvrdto, variableRepository); ICalcAbleObject ch = chf.MakeCalcHouse(housedto, calcRepo); cot = CalcObjectType.House; return(ch); }
public override void Run(HouseholdKey key, object o) { CalcStartParameterSet csps = (CalcStartParameterSet)o; SaveableEntry se = new SaveableEntry(key, ResultTableDefinition); se.AddField("Name", SqliteDataType.Text); se.AddField("Value", SqliteDataType.Text); se.AddRow(RowBuilder.Start("Name", "CsvCharacter").Add("Value", csps.CsvCharacter).ToDictionary()); se.AddRow(RowBuilder.Start("Name", "Temperature Profile").Add("Value", csps.TemperatureProfile.Name).ToDictionary()); se.AddRow(RowBuilder.Start("Name", "AffordanceRepetitionCount").Add("Value", csps.AffordanceRepetitionCount.ToString(CultureInfo.InvariantCulture)).ToDictionary()); se.AddRow(RowBuilder.Start("Name", "CalcOptions").Add("Value", JsonConvert.SerializeObject(csps.CalcOptions, Formatting.Indented)).ToDictionary()); se.AddRow(RowBuilder.Start("Name", "CalcTarget").Add("Value", csps.CalcTarget.Name).ToDictionary()); se.AddRow(RowBuilder.Start("Name", "DeleteDatFiles").Add("Value", csps.DeleteDatFiles.ToString()).ToDictionary()); se.AddRow(RowBuilder.Start("Name", "DeviceSelection").Add("Value", csps.DeviceSelection?.Name ?? "None").ToDictionary()); se.AddRow(RowBuilder.Start("Name", "EnergyIntensity").Add("Value", csps.EnergyIntensity.ToString()).ToDictionary()); se.AddRow(RowBuilder.Start("Name", "ExternalTimeResolution").Add("Value", csps.ExternalTimeResolution.ToString()).ToDictionary()); se.AddRow(RowBuilder.Start("Name", "GeographicLocation").Add("Value", csps.GeographicLocation.Name).ToDictionary()); se.AddRow(RowBuilder.Start("Name", "InternalTimeResolution").Add("Value", csps.InternalTimeResolution.ToString()).ToDictionary()); se.AddRow(RowBuilder.Start("Name", "LPGVersion").Add("Value", csps.LPGVersion).ToDictionary()); se.AddRow(RowBuilder.Start("Name", "LoadTypePriority").Add("Value", csps.LoadTypePriority.ToString()).ToDictionary()); se.AddRow(RowBuilder.Start("Name", "OfficialSimulationStartTime").Add("Value", csps.OfficialSimulationStartTime.ToString(CultureInfo.InvariantCulture)).ToDictionary()); se.AddRow(RowBuilder.Start("Name", "OfficialSimulationEndTime").Add("Value", csps.OfficialSimulationEndTime.ToString(CultureInfo.InvariantCulture)).ToDictionary()); se.AddRow(RowBuilder.Start("Name", "SelectedRandomSeed").Add("Value", csps.SelectedRandomSeed.ToString(CultureInfo.InvariantCulture)).ToDictionary()); se.AddRow(RowBuilder.Start("Name", "SettlingDays").Add("Value", csps.SettlingDays.ToString(CultureInfo.InvariantCulture)).ToDictionary()); se.AddRow(RowBuilder.Start("Name", "ShowSettlingPeriod").Add("Value", csps.ShowSettlingPeriod.ToString()).ToDictionary()); se.AddRow(RowBuilder.Start("Name", "TransportationDeviceSet").Add("Value", csps.TransportationDeviceSet?.Name ?? "None").ToDictionary()); se.AddRow(RowBuilder.Start("Name", "TravelRouteSet").Add("Value", csps.TravelRouteSet?.Name ?? "None").ToDictionary()); if (Srls == null) { throw new LPGException("Data Logger was null."); } Srls.SaveResultEntry(se); }
private static void RunTest([NotNull] Action <GeneralConfig> setOption, [NotNull] string name) { CleanTestBase.RunAutomatically(false); using (var wd1 = new WorkingDir(Utili.GetCurrentMethodAndClass() + name)) { Logger.Threshold = Severity.Error; var path = wd1.WorkingDirectory; if (Directory.Exists(path)) { Directory.Delete(path, true); } Directory.CreateDirectory(path); using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { var sim = new Simulator(db.ConnectionString); Config.IsInUnitTesting = true; Config.ExtraUnitTestChecking = false; sim.MyGeneralConfig.ApplyOptionDefault(OutputFileDefault.NoFiles); sim.MyGeneralConfig.WriteExcelColumn = "False"; //if (setOption == null) { throw new LPGException("Action was null."); } setOption(sim.MyGeneralConfig); Logger.Info("Temperature:" + sim.MyGeneralConfig.SelectedTemperatureProfile); Logger.Info("Geographic:" + sim.MyGeneralConfig.GeographicLocation); sim.Should().NotBeNull(); var cmf = new CalcManagerFactory(); CalculationProfiler calculationProfiler = new CalculationProfiler(); CalcStartParameterSet csps = new CalcStartParameterSet(sim.GeographicLocations[0], sim.TemperatureProfiles[0], sim.ModularHouseholds[0], EnergyIntensityType.Random, false, null, LoadTypePriority.All, null, null, null, sim.MyGeneralConfig.AllEnabledOptions(), new DateTime(2018, 1, 1), new DateTime(2018, 1, 2), new TimeSpan(0, 1, 0), ";", 5, new TimeSpan(0, 10, 0), false, false, false, 3, 3, calculationProfiler, wd1.WorkingDirectory, false); var cm = cmf.GetCalcManager(sim, csps, false);
private static DeviceSelection GetDeviceSelection([NotNull] CalcStartParameterSet csps, [NotNull] ICalcObject hh, [CanBeNull] ModularHousehold chh) { // device selection DeviceSelection ds = null; if (csps.DeviceSelection != null) { ds = csps.DeviceSelection; } else { if (chh != null) { ds = chh.DeviceSelection; } if (hh.CalcObjectType == CalcObjectType.House) { var house = (House)hh; foreach (var houseHousehold in house.Households) { var houseModularHousehold = houseHousehold.CalcObject as ModularHousehold; if (houseModularHousehold?.DeviceSelection != null) { ds = houseModularHousehold.DeviceSelection; } } } } return(ds); }
public void GetCalcManagerModularHousehold03Test() { using (var wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { Config.IsInUnitTesting = true; var sim = new Simulator(db.ConnectionString); sim.MyGeneralConfig.ApplyOptionDefault(OutputFileDefault.ReasonableWithChartsAndPDF); DeviceCategory light = null; foreach (var deviceCategory in sim.DeviceCategories.MyItems) { deviceCategory.RefreshSubDevices(); if (deviceCategory.Name.Contains("Light")) { light = deviceCategory; } } if (light != null) { Logger.Info(light.SubDevices.Count.ToString(CultureInfo.CurrentCulture)); } sim.MyGeneralConfig.ApplyOptionDefault(OutputFileDefault.NoFiles); sim.MyGeneralConfig.Enable(CalcOption.TotalsPerLoadtype); sim.MyGeneralConfig.Enable(CalcOption.TotalsPerDevice); sim.MyGeneralConfig.Enable(CalcOption.MakePDF); sim.MyGeneralConfig.Enable(CalcOption.HouseholdContents); sim.Should().NotBeNull(); var cmf = new CalcManagerFactory(); ModularHousehold chs3 = null; foreach (var modularHousehold in sim.ModularHouseholds.MyItems) { if (modularHousehold.Name.StartsWith("CHS01", StringComparison.Ordinal)) { chs3 = modularHousehold; } } if (chs3 == null) { throw new LPGException("Could not find the household CHS01"); } Logger.Info(chs3.ToString()); CalculationProfiler calculationProfiler = new CalculationProfiler(); CalcStartParameterSet csps = new CalcStartParameterSet(sim.GeographicLocations[0], sim.TemperatureProfiles[0], chs3, EnergyIntensityType.Random, false, null, LoadTypePriority.Mandatory, null, null, null, sim.MyGeneralConfig.AllEnabledOptions(), new DateTime(2015, 1, 15), new DateTime(2015, 1, 18), new TimeSpan(0, 1, 0), ";", -1, new TimeSpan(0, 1, 0), false, false, false, 3, 3, calculationProfiler, wd.WorkingDirectory, false); var cm = cmf.GetCalcManager(sim, csps, false); cm.Run(ReportCancelFunc); cm.Dispose(); db.Cleanup(); } wd.CleanUp(); } }
public void TimeOffsetBugTest() { Config.AdjustTimesForSettlement = false; CleanTestBase.RunAutomatically(false); var start = DateTime.Now; using (var wd1 = new WorkingDir(Utili.GetCurrentMethodAndClass())) { var path = wd1.WorkingDirectory; Config.MakePDFCharts = false; if (Directory.Exists(path)) { Directory.Delete(path, true); } Directory.CreateDirectory(path); using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { var sim = new Simulator(db.ConnectionString); var calcstart = DateTime.Now; sim.MyGeneralConfig.StartDateUIString = "1.1.2015"; sim.MyGeneralConfig.EndDateUIString = "31.1.2015"; sim.MyGeneralConfig.InternalTimeResolution = "00:01:00"; sim.MyGeneralConfig.RandomSeed = 5; sim.MyGeneralConfig.ApplyOptionDefault(OutputFileDefault.Reasonable); sim.MyGeneralConfig.ShowSettlingPeriod = "false"; sim.MyGeneralConfig.CSVCharacter = ";"; sim.MyGeneralConfig.SelectedLoadTypePriority = LoadTypePriority.RecommendedForHouseholds; SimIntegrityChecker.Run(sim); sim.Should().NotBeNull(); var cmf = new CalcManagerFactory(); //CalcDevice.UseRanges = true; var geoloc = sim.GeographicLocations.FindFirstByName("Chemnitz", FindMode.Partial); if (geoloc == null) { throw new LPGException("Geoloc was null"); } var chh = sim.ModularHouseholds.It.First(x => x.Name.StartsWith("CHR09", StringComparison.Ordinal)); CalculationProfiler calculationProfiler = new CalculationProfiler(); CalcStartParameterSet csps = new CalcStartParameterSet(geoloc, sim.TemperatureProfiles[0], chh, EnergyIntensityType.Random, false, null, sim.MyGeneralConfig.SelectedLoadTypePriority, null, null, null, sim.MyGeneralConfig.AllEnabledOptions(), new DateTime(2015, 1, 1), new DateTime(2015, 1, 31), new TimeSpan(0, 1, 0), ";", 5, new TimeSpan(0, 1, 0), false, false, false, 3, 3, calculationProfiler, wd1.WorkingDirectory, false); var cm = cmf.GetCalcManager(sim, csps, false);
public void DumpHouseholdContentsToTextTest() { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { using (var wd1 = new WorkingDir(Utili.GetCurrentMethodAndClass())) { var sim = new Simulator(db.ConnectionString) { MyGeneralConfig = { StartDateUIString = "01.01.2015", EndDateUIString = "02.01.2015", InternalTimeResolution = "00:01:00", ExternalTimeResolution = "00:15:00", RandomSeed = 5 } }; sim.MyGeneralConfig.ApplyOptionDefault(OutputFileDefault.NoFiles); sim.MyGeneralConfig.Enable(CalcOption.TotalsPerDevice); sim.MyGeneralConfig.CSVCharacter = ";"; //ConfigSetter.SetGlobalTimeParameters(sim.MyGeneralConfig); sim.Should().NotBeNull(); SimIntegrityChecker.Run(sim); CalcManagerFactory.DoIntegrityRun = false; var cmf = new CalcManagerFactory(); var calculationProfiler = new CalculationProfiler(); var csps = new CalcStartParameterSet(sim.GeographicLocations[0], sim.TemperatureProfiles[0], sim.ModularHouseholds[0], EnergyIntensityType.Random, false, null, LoadTypePriority.RecommendedForHouses, null, null, null, sim.MyGeneralConfig.AllEnabledOptions(), new DateTime(2015, 1, 1), new DateTime(2015, 1, 2), new TimeSpan(0, 1, 0), ";", 5, new TimeSpan(0, 15, 0), false, false, false, 3, 3, calculationProfiler, wd1.WorkingDirectory, false); var cm = cmf.GetCalcManager(sim, csps, false); //,, wd1.WorkingDirectory, sim.ModularHouseholds[0], false, //sim.TemperatureProfiles[0], sim.GeographicLocations[0], EnergyIntensityType.Random, version, //LoadTypePriority.RecommendedForHouses, null,null var dls = new DayLightStatus(new BitArray(100)); if (cm.CalcObject == null) { throw new LPGException("xxx"); } cm.CalcObject.Init(dls, 1); CalcManager.ExitCalcFunction = true; cm.CalcObject.DumpHouseholdContentsToText(); cm.Dispose(); db.Cleanup(); wd1.CleanUp(); } } }
public void Run() { using (var wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { var sim = new Simulator(db.ConnectionString); var calculationProfiler = new CalculationProfiler(); var csps = new CalcStartParameterSet(sim.GeographicLocations[0], sim.TemperatureProfiles[0], sim.ModularHouseholds[0], EnergyIntensityType.EnergySaving, false, null, LoadTypePriority.OptionalLoadtypes, null, null, null, new List <CalcOption>(), new DateTime(2018, 1, 1), new DateTime(2018, 1, 10), new TimeSpan(0, 1, 0), ";", 1, new TimeSpan(0, 1, 0), false, false, false, 3, 3, calculationProfiler, wd.WorkingDirectory, false); var cmf = new CalcManagerFactory(); var cm = cmf.GetCalcManager(sim, csps, false); cm.Run(null); var mq = new Mock <ICalculationProfiler>(); wd.InputDataLogger.AddSaver(new ResultFileEntryLogger(wd.SqlResultLoggingService)); //FileFactoryAndTracker fft = new FileFactoryAndTracker(wd.WorkingDirectory,"objname",cm.Logfile.FileFactoryAndTracker); //fft.RegisterHouseholdKey(Constants.GeneralHouseholdKey,"general"); //fft.RegisterHouseholdKey(Constants.GeneralHouseholdKey,"general"); var pcm = new PostProcessingManager(mq.Object, cm.CalcRepo.FileFactoryAndTracker); //Debug.Assert(calcResult != null, nameof(calcResult) + " != null"); pcm.Run(wd.WorkingDirectory); db.Cleanup(); } wd.CleanUp(); } }
private static void CalculateOneHousehold([NotNull] string path) { if (Directory.Exists(path)) { Directory.Delete(path, true); } Directory.CreateDirectory(path); using var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()); var sim = new Simulator(db.ConnectionString); Config.IsInUnitTesting = true; sim.MyGeneralConfig.ApplyOptionDefault(OutputFileDefault.Reasonable); sim.MyGeneralConfig.Enable(CalcOption.DeviceProfilesIndividualHouseholds); sim.MyGeneralConfig.ShowSettlingPeriodBool = true; //ConfigSetter.SetGlobalTimeParameters(sim.MyGeneralConfig); sim.Should().NotBeNull(); var cmf = new CalcManagerFactory(); CalculationProfiler calculationProfiler = new CalculationProfiler(); //todo: put in a full house with transportation //var house = sim.Houses.CreateNewItem() CalcStartParameterSet csps = new CalcStartParameterSet(sim.GeographicLocations[0], sim.TemperatureProfiles[0], sim.ModularHouseholds[0], EnergyIntensityType.Random, false, null, LoadTypePriority.Mandatory, null, null, null, sim.MyGeneralConfig.AllEnabledOptions(), new DateTime(2015, 1, 15), new DateTime(2015, 1, 18), new TimeSpan(0, 1, 0), ";", 5, new TimeSpan(0, 1, 0), false, false, false, 3, sim.MyGeneralConfig.RepetitionCount, calculationProfiler, path, false); var cm = cmf.GetCalcManager(sim, csps, false); bool success = cm.Run(ReportCancelFunc); if (!success) { throw new LPGException("Calculation failed"); } db.Cleanup(); }
public static void StartHouse(int house) { CleanTestBase.RunAutomatically(false); var start = DateTime.Now; using (var wd1 = new WorkingDir(Utili.GetCurrentMethodAndClass())) { var path = wd1.WorkingDirectory; Config.MakePDFCharts = false; using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { var sim = new Simulator(db.ConnectionString); var calcstart = DateTime.Now; sim.MyGeneralConfig.StartDateUIString = "1.1.2015"; sim.MyGeneralConfig.EndDateUIString = "31.1.2015"; sim.MyGeneralConfig.InternalTimeResolution = "00:01:00"; sim.MyGeneralConfig.RandomSeed = 5; sim.MyGeneralConfig.ApplyOptionDefault(OutputFileDefault.NoFiles); sim.MyGeneralConfig.Enable(CalcOption.HouseSumProfilesFromDetailedDats); sim.MyGeneralConfig.CSVCharacter = ";"; sim.MyGeneralConfig.SelectedLoadTypePriority = LoadTypePriority.All; SimIntegrityChecker.Run(sim); //CalcParameters //CalcParametersFactory.SetGlobalTimeParameters(sim.MyGeneralConfig); //ConfigSetter.SetGlobalTimeParameters(sim.MyGeneralConfig); sim.Should().NotBeNull(); var cmf = new CalcManagerFactory(); //CalcDevice.UseRanges = true; var geoloc = sim.GeographicLocations.FindFirstByName("Chemnitz", FindMode.Partial); if (geoloc == null) { throw new LPGException("Geoloc was null"); } var house1 = sim.Houses.It[house]; CalculationProfiler calculationProfiler = new CalculationProfiler(); CalcStartParameterSet csps = new CalcStartParameterSet(geoloc, sim.TemperatureProfiles[0], house1, EnergyIntensityType.Random, false, null, LoadTypePriority.All, null, null, null, sim.MyGeneralConfig.AllEnabledOptions(), new DateTime(2015, 1, 1), new DateTime(2015, 1, 31), new TimeSpan(0, 1, 0), ";", 5, new TimeSpan(0, 1, 0), false, false, false, 3, 3, calculationProfiler, path, false); var cm = cmf.GetCalcManager(sim, csps, false);
public void GetCalcManagerModularHouseholdTest() { using (var wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { var sim = new Simulator(db.ConnectionString); DeviceCategory light = null; foreach (var deviceCategory in sim.DeviceCategories.MyItems) { deviceCategory.RefreshSubDevices(); if (deviceCategory.Name.Contains("Light")) { light = deviceCategory; } } if (light != null) { Logger.Info("Light devices:" + light.SubDevices.Count); } sim.MyGeneralConfig.ApplyOptionDefault(OutputFileDefault.NoFiles); sim.MyGeneralConfig.Enable(CalcOption.OverallSum); sim.Should().NotBeNull(); var cmf = new CalcManagerFactory(); CalculationProfiler calculationProfiler = new CalculationProfiler(); CalcStartParameterSet csps = new CalcStartParameterSet(sim.GeographicLocations[0], sim.TemperatureProfiles[0], sim.ModularHouseholds[0], EnergyIntensityType.Random, false, null, LoadTypePriority.Mandatory, null, null, null, sim.MyGeneralConfig.AllEnabledOptions(), new DateTime(2015, 1, 15), new DateTime(2015, 1, 18), new TimeSpan(0, 1, 0), ";", -1, new TimeSpan(0, 1, 0), false, false, false, 3, 3, calculationProfiler, wd.WorkingDirectory, false); var cm = cmf.GetCalcManager(sim, csps, false); cm.Run(ReportCancelFunc); db.Cleanup(); } wd.CleanUp(); } }
public void RunLocationStatisticsMakerTest() { using WorkingDir wd = new WorkingDir(Utili.GetCurrentMethodAndClass()); using DatabaseSetup db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()); Simulator sim = new Simulator(db.ConnectionString) { MyGeneralConfig = { StartDateUIString = "15.1.2015", EndDateUIString = "18.1.2015", InternalTimeResolution = "00:01:00" } }; sim.MyGeneralConfig.ApplyOptionDefault(OutputFileDefault.NoFiles); sim.MyGeneralConfig.Enable(CalcOption.LocationsFile); //ConfigSetter.SetGlobalTimeParameters(sim.MyGeneralConfig); sim.Should().NotBeNull(); sim.MyGeneralConfig.RandomSeed = 10; CalcManagerFactory cmf = new CalcManagerFactory(); CalculationProfiler calculationProfiler = new CalculationProfiler(); CalcStartParameterSet csps = new CalcStartParameterSet(sim.GeographicLocations[0], sim.TemperatureProfiles[0], sim.ModularHouseholds[0], EnergyIntensityType.Random, false, null, LoadTypePriority.All, null, null, null, sim.MyGeneralConfig.AllEnabledOptions(), new DateTime(2015, 1, 15), new DateTime(2015, 1, 18), new TimeSpan(0, 1, 0), ";", 10, new TimeSpan(0, 1, 0), false, false, false, 3, 3, calculationProfiler, wd.WorkingDirectory, false); CalcManager cm = cmf.GetCalcManager(sim, csps, false);
public void RunCalcStarter() { using (var wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { var sim = new Simulator(db.ConnectionString); sim.MyGeneralConfig.StartDateString = "01.01.2013"; Config.IsInUnitTesting = true; Config.ExtraUnitTestChecking = true; sim.MyGeneralConfig.EndDateString = "02.01.2013"; sim.MyGeneralConfig.ApplyOptionDefault(OutputFileDefault.Reasonable); sim.MyGeneralConfig.Enable(CalcOption.TotalsPerLoadtype); sim.MyGeneralConfig.Enable(CalcOption.TotalsPerDevice); sim.MyGeneralConfig.InternalTimeResolution = "00:01:00"; var cp = new CalculationProfiler(); var csps = new CalcStartParameterSet(ReportFinishFuncForHouseAndSettlement, ReportFinishFuncForHousehold, OpenTabFunc, null, sim.GeographicLocations[0], sim.TemperatureProfiles[0], sim.ModularHouseholds[0], EnergyIntensityType.EnergySaving, ReportCancelFunc, false, null, LoadTypePriority.Mandatory, null, null, sim.MyGeneralConfig.AllEnabledOptions(), new DateTime(2018, 1, 1), new DateTime(2018, 1, 2), new TimeSpan(0, 1, 0), ";", 5, new TimeSpan(0, 1, 0), false, false, false, 3, 3, cp, null, null, DeviceProfileHeaderMode.Standard, false, wd.WorkingDirectory, false); var cs = new CalcStarter(sim); cs.Start(csps); /*var dstpath = Path.Combine(wd.WorkingDirectory, * DirectoryNames.CalculateTargetdirectory(TargetDirectory.Reports), "TotalsPerLoadtype.csv"); * using (var sr = new StreamReader(dstpath)) { * sr.ReadLine(); * while (!sr.EndOfStream) { * var line = sr.ReadLine(); * if (line == null) { * throw new LPGException("Result was null"); * } * * var arr = line.Split(';'); * Logger.Info(line); * var devicesumFileName = Path.Combine(wd.WorkingDirectory, * DirectoryNames.CalculateTargetdirectory(TargetDirectory.Reports), * "DeviceSums." + arr[0] + ".csv"); * using (var devsum = new StreamReader(devicesumFileName)) { * while (!devsum.EndOfStream) { * var s = devsum.ReadLine(); * if (s == null) { * throw new LPGException("Result was null"); * } * * if (s.StartsWith("Sums;", StringComparison.Ordinal)) { * var sumarr = s.Split(';'); * Logger.Info("Line from totalsPerLoadType"); * Logger.Info(line); * Logger.Info("Line from " + devicesumFileName); * Logger.Info(s); * var arr1 = sumarr[1]; * if (arr1.Length > 6) { * arr1 = arr1.Substring(0, 6); * } * * var arr2 = arr[3]; * if (arr2.Length > 6) { * arr2 = arr2.Substring(0, 6); * } * * (arr2).Should().Be(arr1); * } * } * } * } * }*/ wd.CleanUp(); db.Cleanup(); } } }
public CalcParameters MakeCalculationParametersFromConfig([NotNull] CalcStartParameterSet csps, bool forceRandom) { CalcParameters cp = CalcParameters.GetNew(); cp.LoadtypesToPostprocess = csps.LoadTypesToProcess; cp.SetDeleteDatFiles(csps.DeleteDatFiles); cp.SetWriteExcelColumn (csps.WriteExcelColumn); cp.SetManyOptionsWithClear(csps.CalcOptions); FileFactoryAndTrackerDummy fftd = new FileFactoryAndTrackerDummy(); var container =PostProcessingManager.RegisterEverything(csps.ResultPath,csps.CalculationProfiler, fftd); using (var scope = container.BeginLifetimeScope()) { var odm = scope.Resolve<OptionDependencyManager>(); odm.EnableRequiredOptions(cp.Options); } cp.SetShowSettlingPeriod(csps.ShowSettlingPeriod); cp.SetRandomSeed(csps.SelectedRandomSeed, forceRandom); cp.SetCsvCharacter(csps.CsvCharacter); cp.SetStartDate(csps.OfficialSimulationStartTime); cp.SetEndDate(csps.OfficialSimulationEndTime.AddDays(1)); cp.SetInternalTimeResolution(csps.InternalTimeResolution); cp.SetExternalTimeResolution(csps.ExternalTimeResolution); cp.SetLoadTypePriority(csps.LoadTypePriority); cp.SetSettlingDays(csps.SettlingDays); cp.SetAffordanceRepetitionCount(csps.AffordanceRepetitionCount); cp.DeviceProfileHeaderMode = csps.DeviceProfileHeaderMode; cp.IgnorePreviousActivitesWhenNeeded = csps.IgnorePreviousActivitiesWhenNeeded; cp.TransportationEnabled = csps.TransportationEnabled; if (cp.TransportationEnabled && csps.CalcTarget.CalcObjectType == CalcObjectType.House) { if (csps.ChargingStationSet != null) { throw new LPGException("trying to set transportation options on a house. that won't work."); } if (csps.TransportationDeviceSet != null) { throw new LPGException("trying to set transportation options on a house. that won't work."); } if (csps.TravelRouteSet != null) { throw new LPGException("trying to set transportation options on a house. that won't work."); } } if (cp.TransportationEnabled && csps.CalcTarget.CalcObjectType == CalcObjectType.ModularHousehold) { if (csps.ChargingStationSet == null) { throw new LPGException("Trying to set transportation options on a household without charging station set. That won't work."); } if (csps.TransportationDeviceSet == null) { throw new LPGException("Trying to set transportation options on a household without transportation device set. That won't work."); } if (csps.TravelRouteSet != null) { throw new LPGException("trying to set transportation options on a house. that won't work."); } } cp.CheckSettings(); //transport mode /*if (csps.TransportationDeviceSet != null || csps.TravelRouteSet != null) { cp.SetTransportMode(true); if (csps.TransportationDeviceSet == null ) { throw new DataIntegrityException("Only a transportation device set was defined, but not a travel route set. This can't work."); } if (csps.TravelRouteSet == null) { throw new DataIntegrityException("Only a travel route set was defined, but not a transportation device set. This can't work."); } }*/ return cp; }
public void StartHousehold([NotNull] Simulator sim, [NotNull] JsonCalcSpecification jcs, [NotNull] JsonReference calcObjectReference, [CanBeNull] Action <CalculationProfiler, string> makeAllCharts) { if (!CheckSimulator(jcs, sim)) { throw new LPGPBadParameterException("Invalid simulation state"); } var calcObject = GetCalcObject(sim, calcObjectReference); if (jcs.OutputDirectory == null) { jcs.OutputDirectory = AutomationUtili.CleanFileName(calcObject.Name) + " - " + calcObject; } _calculationProfiler.StartPart(Utili.GetCurrentMethodAndClass()); if (calcObjectReference == null) { throw new LPGException("No calculation object was selected."); } var calculationStartTime = DateTime.Now; if (calcObject == null) { throw new LPGException("Could not find the Calc Object with the guid " + calcObjectReference.Guid); } var generalResultsDirectory = new DirectoryInfo(jcs.OutputDirectory ?? throw new LPGException("Output directory was null.")); var finishedFile = Path.Combine(generalResultsDirectory.FullName, Constants.FinishedFileFlag); if (Directory.Exists(generalResultsDirectory.FullName)) { if (jcs.SkipExisting) { if (File.Exists(finishedFile)) { Logger.Error("Directory already exists and calculation is finished. Exiting."); _calculationProfiler.StopPart(Utili.GetCurrentMethodAndClass()); return; } } Logger.Warning("Directory already exists, but calculation is not finished or skip existing is not specified. Deleting folder."); var files = generalResultsDirectory.GetFiles(); foreach (FileInfo file in files) { if (file.Name.StartsWith("Log.", StringComparison.OrdinalIgnoreCase)) { continue; } if (file.Name.EndsWith(".db3", StringComparison.OrdinalIgnoreCase)) { continue; } file.Delete(); } var directories = generalResultsDirectory.GetDirectories(); foreach (DirectoryInfo info in directories) { info.Delete(true); } Thread.Sleep(1000); } generalResultsDirectory.Create(); Thread.Sleep(500); Logger.SetLogFilePath(Path.Combine(generalResultsDirectory.FullName, "Log.CommandlineCalculation.txt")); Logger.LogToFile = true; Logger.Get().FlushExistingMessages(); Logger.Info("---------------------------"); Logger.Info("Used calculation specification:"); Logger.Info(JsonConvert.SerializeObject(jcs, Formatting.Indented), true); Logger.Info("---------------------------"); Logger.Info("Directory: " + generalResultsDirectory.FullName); sim.MyGeneralConfig.StartDateUIString = jcs.StartDate.ToString(); sim.MyGeneralConfig.EndDateUIString = jcs.EndDate.ToString(); sim.MyGeneralConfig.InternalTimeResolution = "00:01:00"; sim.MyGeneralConfig.DestinationPath = generalResultsDirectory.FullName; sim.MyGeneralConfig.ApplyOptionDefault(jcs.DefaultForOutputFiles); if (jcs.CalcOptions != null) { foreach (var option in jcs.CalcOptions) { //var option = option; /*if (option == null) { * throw new LPGException("Could not identify Calc Option " + option + ". Stopping."); * }*/ Logger.Info("Enabling option " + option); sim.MyGeneralConfig.Enable(option); } } if (jcs.DeleteDAT) { sim.MyGeneralConfig.DeleteDatFiles = "TRUE"; } else { sim.MyGeneralConfig.DeleteDatFiles = "FALSE"; } if (jcs.ExternalTimeResolution == null) { sim.MyGeneralConfig.ExternalTimeResolution = sim.MyGeneralConfig.InternalTimeResolution; } else { sim.MyGeneralConfig.ExternalTimeResolution = jcs.ExternalTimeResolution; } sim.MyGeneralConfig.RandomSeed = jcs.RandomSeed; var eit = jcs.EnergyIntensityType; if (eit == EnergyIntensityType.AsOriginal) { eit = calcObject.EnergyIntensityType; } var cs = new CalcStarter(sim); var temperatureProfile = sim.TemperatureProfiles.FindByJsonReference(jcs.TemperatureProfile); if (temperatureProfile == null) { throw new LPGException("Temperature Profile not found."); } if (jcs.GeographicLocation == null) { throw new LPGPBadParameterException("No geographic location was set in the calculation request"); } var geographicLocation = sim.GeographicLocations.FindByJsonReference(jcs.GeographicLocation); if (geographicLocation == null) { throw new LPGException("Geographic location not found."); } DeviceSelection deviceSelection = null; if (jcs.DeviceSelection != null) { deviceSelection = sim.DeviceSelections.FindByJsonReference(jcs.DeviceSelection); if (deviceSelection == null) { throw new LPGException("Unknown device selection \"" + jcs.DeviceSelection.Guid + "\""); } } if (jcs.EnableTransportation) { } if (jcs.LoadTypePriority == LoadTypePriority.Undefined) { if (calcObject.CalcObjectType == CalcObjectType.ModularHousehold) { jcs.LoadTypePriority = LoadTypePriority.RecommendedForHouseholds; } else { jcs.LoadTypePriority = LoadTypePriority.RecommendedForHouses; } } var options = sim.MyGeneralConfig.AllEnabledOptions(); //options.Add(CalcOption.OverallDats); var calcStartParameterSet = new CalcStartParameterSet(ReportFinishFuncForHouseAndSettlement, ReportFinishFuncForHousehold, OpenTabFunc, null, geographicLocation, temperatureProfile, calcObject, eit, ReportCancelFunc, false, deviceSelection, jcs.LoadTypePriority, null, null, options, sim.MyGeneralConfig.StartDateDateTime, sim.MyGeneralConfig.EndDateDateTime, sim.MyGeneralConfig.InternalStepSize, sim.MyGeneralConfig.CSVCharacter, jcs.RandomSeed, sim.MyGeneralConfig.ExternalStepSize, sim.MyGeneralConfig.DeleteDatFilesBool, sim.MyGeneralConfig.WriteExcelColumnBool, sim.MyGeneralConfig.ShowSettlingPeriodBool, 3, sim.MyGeneralConfig.RepetitionCount, _calculationProfiler, null, jcs.LoadtypesForPostprocessing, sim.MyGeneralConfig.DeviceProfileHeaderMode, jcs.IgnorePreviousActivitiesWhenNeeded, jcs.OutputDirectory, jcs.EnableTransportation); calcStartParameterSet.PreserveLogfileWhileClearingFolder = true; cs.Start(calcStartParameterSet); if (jcs.CalcOptions != null && jcs.CalcOptions.Contains(CalcOption.CalculationFlameChart)) { string targetfile = Path.Combine(generalResultsDirectory.FullName, Constants.CalculationProfilerJson); using (StreamWriter sw = new StreamWriter(targetfile)) { _calculationProfiler.WriteJson(sw); } } _calculationProfiler.StopPart(Utili.GetCurrentMethodAndClass()); if (makeAllCharts != null) { makeAllCharts(_calculationProfiler, calcStartParameterSet.ResultPath); } var duration = DateTime.Now - calculationStartTime; if (jcs.DeleteAllButPDF) { var allFileInfos = generalResultsDirectory.GetFiles("*.*", SearchOption.AllDirectories); foreach (var fi in allFileInfos) { if (fi.Name.ToUpperInvariant().EndsWith(".PDF", StringComparison.Ordinal)) { continue; } if (fi.Name.ToUpperInvariant().StartsWith("SUMPROFILES.", StringComparison.Ordinal)) { continue; } if (fi.Name.ToUpperInvariant().StartsWith("HOUSEHOLDNAME.", StringComparison.Ordinal)) { continue; } fi.Delete(); } } if (jcs.DeleteSqlite) { var allFileInfos = generalResultsDirectory.GetFiles("*.sqlite", SearchOption.AllDirectories); GC.Collect(); GC.WaitForPendingFinalizers(); foreach (var fi in allFileInfos) { try { fi.Delete(); } catch (Exception ex) { Logger.Exception(ex); } } } Logger.ImportantInfo("Calculation duration:" + duration); //cleanup empty directories var subdirs = generalResultsDirectory.GetDirectories(); foreach (var subdir in subdirs) { var files = subdir.GetFiles(); var subsubdirs = subdir.GetDirectories(); if (files.Length == 0 && subsubdirs.Length == 0) { subdir.Delete(); } } using (var sw = new StreamWriter(finishedFile)) { sw.WriteLine("Finished at " + DateTime.Now); sw.WriteLine("Duration in seconds:"); sw.WriteLine(duration.TotalSeconds); } }
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; } }
private void RegisterEverything([NotNull] Simulator sim, [NotNull] string resultpath, [NotNull] CalcStartParameterSet csps, [NotNull] ICalcObject hh, [NotNull] ContainerBuilder builder, [NotNull] string sqlFileName, [NotNull] CalcParameters calcParameters, [CanBeNull] DeviceSelection ds) { builder.Register(c => new SqlResultLoggingService(sqlFileName)).As <SqlResultLoggingService>() .SingleInstance(); builder.Register(c => calcParameters).As <CalcParameters>().SingleInstance(); Random rnd = new Random(calcParameters.ActualRandomSeed); builder.Register(c => rnd).As <Random>().SingleInstance(); builder.Register(c => csps.CalculationProfiler).As <CalculationProfiler>().SingleInstance(); builder.Register(c => new NormalRandom(0, 0.1, rnd)).As <NormalRandom>().SingleInstance(); builder.RegisterType <OnlineDeviceActivationProcessor>().As <IOnlineDeviceActivationProcessor>() .SingleInstance(); builder.RegisterType <CalcHouseFactory>().As <CalcHouseFactory>().SingleInstance(); builder.RegisterType <CalcManager>().As <CalcManager>().SingleInstance(); builder.RegisterType <AffordanceTaggingSetFactory>().As <AffordanceTaggingSetFactory>().SingleInstance(); builder.Register(x => CalcLoadTypeDtoFactory.MakeLoadTypes(sim.LoadTypes.It, calcParameters.InternalStepsize, csps.LoadTypePriority)) .As <CalcLoadTypeDtoDictionary>().SingleInstance(); builder.Register(x => CalcLoadTypeFactory.MakeLoadTypes(x.Resolve <CalcLoadTypeDtoDictionary>())) .As <CalcLoadTypeDictionary>().SingleInstance(); //builder.Register(x =>ds).As<DeviceSelection>().SingleInstance(); builder.Register(x => { CalcDeviceTaggingSetFactory ctsf = new CalcDeviceTaggingSetFactory(x.Resolve <CalcParameters>(), x.Resolve <CalcLoadTypeDtoDictionary>()); return(ctsf.GetDeviceTaggingSets(sim, hh.CalculatePersonCount())); }).As <CalcDeviceTaggingSets>().SingleInstance(); builder.Register(x => new DeviceCategoryPicker(rnd, ds)).As <IDeviceCategoryPicker>().SingleInstance(); builder.RegisterType <CalcModularHouseholdFactory>().As <CalcModularHouseholdFactory>().SingleInstance(); builder.RegisterType <CalcHouseFactory>().As <CalcHouseFactory>().SingleInstance(); builder.RegisterType <CalcLocationFactory>().As <CalcLocationFactory>().SingleInstance(); builder.RegisterType <CalcPersonFactory>().As <CalcPersonFactory>().SingleInstance(); builder.RegisterType <CalcDeviceFactory>().As <CalcDeviceFactory>().SingleInstance(); builder.RegisterType <CalcRepo>().As <CalcRepo>().SingleInstance(); builder.RegisterType <CalcAffordanceFactory>().As <CalcAffordanceFactory>().SingleInstance(); builder.RegisterType <CalcTransportationFactory>().As <CalcTransportationFactory>().SingleInstance(); builder.RegisterType <CalcVariableDtoFactory>().As <CalcVariableDtoFactory>().SingleInstance(); builder.RegisterType <VacationDtoFactory>().As <VacationDtoFactory>().SingleInstance(); builder.RegisterType <CalcVariableRepository>().As <CalcVariableRepository>().SingleInstance(); builder.RegisterType <TemperatureDataLogger>().As <TemperatureDataLogger>().SingleInstance(); builder.Register(x => new FileFactoryAndTracker(resultpath, hh.Name, x.Resolve <IInputDataLogger>())) .As <FileFactoryAndTracker>().SingleInstance(); builder.Register(_ => new SqlResultLoggingService(resultpath)).As <SqlResultLoggingService>().SingleInstance(); builder.Register(x => new DateStampCreator(x.Resolve <CalcParameters>())).As <DateStampCreator>().SingleInstance(); builder.Register(c => new OnlineLoggingData(c.Resolve <DateStampCreator>(), c.Resolve <IInputDataLogger>(), c.Resolve <CalcParameters>())) .As <OnlineLoggingData>().As <IOnlineLoggingData>().SingleInstance(); builder.Register(x => new LogFile(calcParameters, x.Resolve <FileFactoryAndTracker>())).As <ILogFile>().SingleInstance(); builder.RegisterType <AffordanceTaggingSetFactory>().As <AffordanceTaggingSetFactory>(); builder.RegisterType <CalcPersonDtoFactory>().As <CalcPersonDtoFactory>(); builder.RegisterType <CalcDeviceDtoFactory>().As <CalcDeviceDtoFactory>(); builder.RegisterType <CalcLocationDtoFactory>().As <CalcLocationDtoFactory>(); builder.RegisterType <CalcAffordanceDtoFactory>().As <CalcAffordanceDtoFactory>(); builder.RegisterType <CalcHouseDtoFactory>().As <CalcHouseDtoFactory>(); builder.RegisterType <CalcModularHouseholdDtoFactory>().As <CalcModularHouseholdDtoFactory>(); builder.RegisterType <AvailabilityDtoRepository>().As <AvailabilityDtoRepository>().SingleInstance(); builder.RegisterType <CalcTransportationDtoFactory>().As <CalcTransportationDtoFactory>(); //data save loggers + input data loggers builder.RegisterType <InputDataLogger>().As <IInputDataLogger>().SingleInstance(); builder.RegisterType <CalcParameterLogger>().As <IDataSaverBase>(); builder.RegisterType <DeviceTaggingSetLogger>().As <IDataSaverBase>(); builder.RegisterType <HouseholdDtoLogger>().As <IDataSaverBase>(); builder.RegisterType <DaylightTimesLogger>().As <IDataSaverBase>(); builder.RegisterType <TemperatureDataLogger>().As <IDataSaverBase>(); builder.RegisterType <CalcStartParameterSetLogger>().As <IDataSaverBase>(); builder.RegisterType <CalcLoadTypeDtoLogger>().As <IDataSaverBase>(); builder.RegisterType <ActionEntryLogger>().As <IDataSaverBase>(); builder.RegisterType <CalcPersonDtoLogger>().As <IDataSaverBase>(); builder.RegisterType <CalcDeviceDtoLogger>().As <IDataSaverBase>(); builder.RegisterType <CalcAutoDevDtoLogger>().As <IDataSaverBase>(); builder.RegisterType <CalcVariableDtoLogger>().As <IDataSaverBase>(); builder.RegisterType <HouseholdKeyLogger>().As <IDataSaverBase>(); builder.RegisterType <CalcObjectInformationLogger>().As <IDataSaverBase>(); builder.RegisterType <BodilyActivityLevelStatisticsLogger>().As <IDataSaverBase>(); builder.RegisterType <ResultFileEntryLogger>().As <IDataSaverBase>(); builder.RegisterType <CalcAffordanceDtoLogger>().As <IDataSaverBase>(); builder.RegisterType <CalcAffordanceTaggingSetDtoLogger>().As <IDataSaverBase>(); builder.RegisterType <DeviceActivationEntryLogger>().As <IDataSaverBase>(); builder.RegisterType <ColumnEntryLogger>().As <IDataSaverBase>(); builder.RegisterType <BridgeDayEntryLogger>().As <IDataSaverBase>(); builder.RegisterType <HouseDtoLogger>().As <IDataSaverBase>(); builder.RegisterType <LocationEntryLogger>().As <IDataSaverBase>(); builder.RegisterType <CalcSiteDtoLogger>().As <IDataSaverBase>(); builder.RegisterType <CalcTransportationDeviceDtoLogger>().As <IDataSaverBase>(); builder.RegisterType <CalcTravelRouteDtoLogger>().As <IDataSaverBase>(); builder.RegisterType <TransportationEventLogger>().As <IDataSaverBase>(); builder.RegisterType <TransportationStatusLogger>().As <IDataSaverBase>(); builder.RegisterType <PersonStatusLogger>().As <IDataSaverBase>(); builder.RegisterType <TransportationStateEntryLogger>().As <IDataSaverBase>(); builder.RegisterType <ChargingStationStateLogger>().As <IDataSaverBase>(); builder.RegisterType <VariableEntryLogger>().As <IDataSaverBase>(); builder.RegisterType <TransportationDeviceStatisticsLogger>().As <IDataSaverBase>(); builder.RegisterType <AffordanceEnergyUseLogger>().As <IDataSaverBase>(); //builder.Register(x=> x.Resolve<CalcVariableDtoFactory>().GetRepository()).As<CalcVariableRepository>().SingleInstance(); builder.Register(x => MakeLightNeededArray(csps.GeographicLocation, csps.TemperatureProfile, rnd, new List <VacationTimeframe>(), hh.Name, calcParameters)).As <DayLightStatus>().SingleInstance(); }
private static ICalcAbleObject MakeCalcHouseholdObject([NotNull] Simulator sim, [NotNull] CalcStartParameterSet csps, [NotNull] ICalcObject hh, [NotNull] ILifetimeScope scope, [NotNull] CalcVariableDtoFactory cvrdto, [NotNull] CalcVariableRepository variableRepository, out CalcObjectType cot, [NotNull] CalcRepo calcRepo) { var cmhdf = scope.Resolve <CalcModularHouseholdDtoFactory>(); HouseholdKey householdKey = new HouseholdKey("HH1"); CalcHouseholdDto dto = cmhdf.MakeCalcModularHouseholdDto(sim, (ModularHousehold)hh, csps.TemperatureProfile, householdKey, csps.GeographicLocation, out _, csps.TransportationDeviceSet, csps.TravelRouteSet, csps.EnergyIntensity, csps.ChargingStationSet); var cmhf = scope.Resolve <CalcModularHouseholdFactory>(); /*foreach (var v in dto.CalcVariables) * { * variableRepository.RegisterVariable(new CalcVariable(v.Name, v.Guid, v.Value, v.LocationName, v.LocationGuid, v.HouseholdKey)); * }*/ foreach (HouseholdKeyEntry entry in dto.GetHouseholdKeyEntries()) { calcRepo.InputDataLogger.Save(Constants.GeneralHouseholdKey, entry); } calcRepo.InputDataLogger.Save(Constants.GeneralHouseholdKey, dto); RegisterAllDtoVariables(cvrdto, variableRepository); ICalcAbleObject ch = cmhf.MakeCalcModularHousehold(dto, out _, null, null, calcRepo); cot = CalcObjectType.ModularHousehold; return(ch); }
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); }
public void GetCalcManagerModularHouseholdTestForDevicePicking() { using (var wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { var sim = new Simulator(db.ConnectionString); DeviceCategory light = null; foreach (var deviceCategory in sim.DeviceCategories.MyItems) { deviceCategory.RefreshSubDevices(); if (deviceCategory.Name.Contains("Light")) { light = deviceCategory; } } if (light != null) { Logger.Info("Light devices:" + light.SubDevices.Count); } sim.MyGeneralConfig.ApplyOptionDefault(OutputFileDefault.OnlyOverallSum); sim.Should().NotBeNull(); var cmf = new CalcManagerFactory(); CalculationProfiler calculationProfiler = new CalculationProfiler(); CalcStartParameterSet csps = new CalcStartParameterSet(sim.GeographicLocations[0], sim.TemperatureProfiles[0], sim.ModularHouseholds[0], EnergyIntensityType.Random, false, null, LoadTypePriority.Mandatory, null, null, null, sim.MyGeneralConfig.AllEnabledOptions(), new DateTime(2015, 1, 15), new DateTime(2015, 1, 18), new TimeSpan(0, 1, 0), ";", -1, new TimeSpan(0, 1, 0), false, false, false, 3, 3, calculationProfiler, wd.WorkingDirectory, false); var cm = cmf.GetCalcManager(sim, csps, false); var chh = (CalcHousehold)cm.CalcObject; var devicenameByCategoryAndLocationID = new Dictionary <string, string>(); if (chh == null) { throw new LPGException("xxx"); } foreach (var device in chh.CollectDevices()) { var key = device.DeviceCategoryGuid + "##" + device.CalcLocation.Name; if (devicenameByCategoryAndLocationID.ContainsKey(key)) { var otherDev = devicenameByCategoryAndLocationID[key]; Logger.Warning("Suspicious: " + key + " dev 1:" + otherDev + " dev 2:" + device.Name); } else { devicenameByCategoryAndLocationID.Add(key, device.Name); } } Logger.Info("-----"); foreach (var autoDev in chh.CollectAutoDevs()) { var key = autoDev.DeviceCategoryGuid + "##" + autoDev.CalcLocation.Name; if (devicenameByCategoryAndLocationID.ContainsKey(key)) { var devicename = devicenameByCategoryAndLocationID[key]; if (devicename != autoDev.Name) { Logger.Warning("For " + key + " it should be " + devicename + " but it is " + autoDev.Name); } } } cm.CalcRepo.Logfile.Dispose(); db.Cleanup(); } wd.CleanUp(); } }