public void MakePlotTest() { CleanTestBase.RunAutomatically(false); var start = DateTime.Now; //ChartLocalizer.ShouldTranslate = true; var cs = new OxyCalculationSetup(Utili.GetCurrentMethodAndClass()); cs.StartHousehold(2, GlobalConsts.CSVCharacter, configSetter: x => { x.Enable(CalcOption.TotalsPerDevice); x.Enable(CalcOption.HouseholdContents); }); var simend = DateTime.Now; using (FileFactoryAndTracker fft = new FileFactoryAndTracker(cs.DstDir, "1", cs.Wd.InputDataLogger)) { CalculationProfiler cp = new CalculationProfiler(); ChartCreationParameters ccps = new ChartCreationParameters(300, 4000, 2500, false, GlobalConsts.CSVCharacter, new DirectoryInfo(cs.DstDir)); var aeupp = new DeviceTaggingSet(ccps, fft, cp); Logger.Info("Making picture"); var di = new DirectoryInfo(cs.DstDir); var rfe = cs.GetRfeByFilename("DeviceTaggingSet.Electricity.General.csv"); aeupp.MakePlot(rfe); Logger.Info("finished picture"); //OxyCalculationSetup.CopyImage(resultFileEntries[0].FullFileName); Logger.Info("Simulation Time:" + (simend - start)); Logger.Info("Chart Time:" + (DateTime.Now - simend)); var imagefiles = FileFinder.GetRecursiveFiles(di, "DeviceTaggingSet.*.png"); imagefiles.Count.Should().BeGreaterOrEqualTo(1); } cs.CleanUp(); CleanTestBase.RunAutomatically(true); }
public void MakePlotTest() { CleanTestBase.RunAutomatically(false); var cs = new OxyCalculationSetup(Utili.GetCurrentMethodAndClass()); cs.StartHousehold(1, GlobalConsts.CSVCharacter, configSetter: x => x.Enable(CalcOption.ActivationFrequencies)); using (FileFactoryAndTracker fft = new FileFactoryAndTracker(cs.DstDir, "1", cs.Wd.InputDataLogger)) { fft.ReadExistingFilesFromSql(); CalculationProfiler cp = new CalculationProfiler(); ChartCreationParameters ccps = new ChartCreationParameters(300, 4000, 2500, false, GlobalConsts.CSVCharacter, new DirectoryInfo(cs.DstDir)); var afpm = new ActivityPercentage(ccps, fft, cp); Logger.Info("Making picture"); var di = new DirectoryInfo(cs.DstDir); var rfe = cs.GetRfeByFilename("ActivityPercentage.HH1.csv"); afpm.MakePlot(rfe); Logger.Info("finished picture"); //OxyCalculationSetup.CopyImage(resultFileEntries[0].FullFileName); var imagefiles = FileFinder.GetRecursiveFiles(di, "ActivityPercentage.*.png"); imagefiles.Count.Should().BeGreaterOrEqualTo(2); } Logger.Warning("Leftover connections: " + Connection.ConnectionCount); cs.CleanUp(); //CleanTestBase.Run(true); }
public void TestImport() { const string importPath = @"e:\Haushalt3.db3"; var fi = new FileInfo(importPath); if (!File.Exists(importPath)) { throw new LPGException("Missing file: " + fi.FullName); } using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { var mainSim = new Simulator(db.ConnectionString); var hhNames = mainSim.ModularHouseholds.It.Select(x => x.Name).ToList(); var dbm = new DatabaseMerger(mainSim); dbm.RunFindItems(importPath, null); dbm.RunImport(null); var newHHs = mainSim.ModularHouseholds.It.Where(x => !hhNames.Contains(x.Name)).ToList(); foreach (var newHH in newHHs) { if (newHH.Persons.Count == 0) { throw new LPGException("No persons were imported."); } Logger.Info(newHH.Name); foreach (var hhPerson in newHH.Persons) { Logger.Info("\t" + hhPerson.Name); } } db.Cleanup(); } CleanTestBase.RunAutomatically(true); }
public void MainHouseholdPlanTest() { CleanTestBase.RunAutomatically(false); var cs = new OxyCalculationSetup(Utili.GetCurrentMethodAndClass()); cs.StartHousehold(1, GlobalConsts.CSVCharacter, configSetter: x => { x.ApplyOptionDefault(OutputFileDefault.OnlyDeviceProfiles); //x.Enable(CalcOption.MakeGraphics); x.Enable(CalcOption.HouseholdPlan); } ); using (FileFactoryAndTracker fft = new FileFactoryAndTracker(cs.DstDir, "1", cs.Wd.InputDataLogger)) { CalculationProfiler cp = new CalculationProfiler(); ChartCreationParameters ccps = new ChartCreationParameters(300, 4000, 2500, false, GlobalConsts.CSVCharacter, new DirectoryInfo(cs.DstDir)); var hp = new HouseholdPlan(ccps, fft, cp); Logger.Info("Making picture"); var di = new DirectoryInfo(cs.DstDir); var rfe = cs.GetRfeByFilename("HouseholdPlan.Times.CHR02 Couple Both working, over 30.HH1.csv"); hp.MakePlot(rfe); Logger.Info("finished picture"); //OxyCalculationSetup.CopyImage(resultFileEntries[0].FullFileName); var imagefiles = FileFinder.GetRecursiveFiles(di, "HouseholdPlan.*.png"); imagefiles.Count.Should().BeGreaterOrEqualTo(1); } cs.CleanUp(); CleanTestBase.RunAutomatically(true); }
public void RunChartGeneratorTests() { Config.ReallyMakeAllFilesIncludingBothSums = true; CleanTestBase.RunAutomatically(false); var cs = new OxyCalculationSetup(Utili.GetCurrentMethodAndClass()); cs.StartHousehold(1, GlobalConsts.CSVCharacter, configSetter: x => { x.ApplyOptionDefault(OutputFileDefault.All); x.Disable(CalcOption.MakeGraphics); x.Disable(CalcOption.MakePDF); }); CalculationProfiler cp = new CalculationProfiler(); ChartCreationParameters ccp = new ChartCreationParameters(144, 2000, 1000, false, GlobalConsts.CSVCharacter, new DirectoryInfo(cs.DstDir)); using (var fft = cs.GetFileTracker()) { ChartGeneratorManager cgm = new ChartGeneratorManager(cp, fft, ccp); Logger.Info("Making picture"); cgm.Run(cs.DstDir); } Logger.Info("finished picture"); cs.CleanUp(); CleanTestBase.RunAutomatically(true); }
public void TryCleaningEachTable() { CleanTestBase.RunAutomatically(false); using (var db1 = new DatabaseSetup("TryCleaningEach")) { var alltables = LongtermTests.GetTableList(db1); db1.Cleanup(); for (var index = 0; index < alltables.Count; index++) { Logger.Info("processing table " + index + " out of " + alltables.Count); var table = alltables[index]; if (table == "tblLPGVersion") { continue; } using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { DBBase.HideDeleteMessages(); Command.HideDeleteMessages(); db.ClearTable(table); var oldSim = new Simulator(db.ConnectionString); // need to load it for testing Logger.Info(oldSim.ModularHouseholds.It.Count.ToString(CultureInfo.InvariantCulture)); db.Cleanup(); } } } CleanTestBase.RunAutomatically(true); }
public void MakePlotMonthlyTest() { CleanTestBase.RunAutomatically(false); var cs = new OxyCalculationSetup(Utili.GetCurrentMethodAndClass()); cs.StartHousehold(1, GlobalConsts.CSVCharacter, enddate: new DateTime(2012, 3, 31), configSetter: x => x.Enable(CalcOption.TotalsPerDevice)); using (FileFactoryAndTracker fft = new FileFactoryAndTracker(cs.DstDir, "1", cs.Wd.InputDataLogger)) { CalculationProfiler cp = new CalculationProfiler(); ChartCreationParameters ccps = new ChartCreationParameters(300, 4000, 2500, false, GlobalConsts.CSVCharacter, new DirectoryInfo(cs.DstDir)); var aeupp = new DeviceSums(ccps, fft, cp); Logger.Info("Making picture"); var di = new DirectoryInfo(cs.DstDir); var rfe = cs.GetRfeByFilename("DeviceSums_Monthly.Electricity.csv"); aeupp.MakePlotMonthly(rfe, "monthly sums", di); Logger.Info("finished picture"); var imagefiles = FileFinder.GetRecursiveFiles(di, "DeviceSums_Monthly.*.png"); imagefiles.Count.Should().BeGreaterOrEqualTo(1); } cs.CleanUp(); CleanTestBase.RunAutomatically(true); }
public void MakePlotTest() { CleanTestBase.RunAutomatically(false); var cs = new OxyCalculationSetup(Utili.GetCurrentMethodAndClass()); cs.StartHousehold(2, GlobalConsts.CSVCharacter, LoadTypePriority.Mandatory, configSetter: x => { x.CSVCharacter = ";"; x.ApplyOptionDefault(OutputFileDefault.NoFiles); x.Enable(CalcOption.DeviceProfileExternalEntireHouse); x.Enable(CalcOption.HouseholdContents); x.ExternalTimeResolution = "01:00:00"; x.SelectedEnergyIntensity = EnergyIntensityType.EnergySavingPreferMeasured; x.EndDateString = "31.01.2012"; }, energyIntensity: EnergyIntensityType.EnergySavingPreferMeasured); using (FileFactoryAndTracker fft = new FileFactoryAndTracker(cs.DstDir, "1", cs.Wd.InputDataLogger)) { CalculationProfiler cp = new CalculationProfiler(); ChartCreationParameters ccps = new ChartCreationParameters(300, 4000, 2500, false, GlobalConsts.CSVCharacter, new DirectoryInfo(cs.DstDir)); var aeupp = new DeviceProfilesExternal(ccps, fft, cp); Logger.Info("Making picture"); var di = new DirectoryInfo(cs.DstDir); var rfe = cs.GetRfeByFilename("DeviceProfiles_3600s.Electricity.csv"); aeupp.MakePlot(rfe); Logger.Info("finished picture"); var imagefiles = FileFinder.GetRecursiveFiles(di, "DeviceProfiles*.png"); imagefiles.Count.Should().BeGreaterOrEqualTo(1); } cs.CleanUp(); CleanTestBase.RunAutomatically(true); }
public void CheckSimIntegrityCheckerBenchmark() { CleanTestBase.RunAutomatically(false); const int runcount = 1; using (DatabaseSetup db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { Simulator sim = new Simulator(db.ConnectionString) { MyGeneralConfig = { PerformCleanUpChecks = "True" } }; sim.Should().NotBeNull(); DateTime start = DateTime.Now; for (int i = 0; i < runcount; i++) { SimIntegrityChecker.Run(sim); } DateTime end = DateTime.Now; var duration = end - start; Logger.Info("Duration was:" + duration.TotalMilliseconds / runcount + " milliseconds"); db.Cleanup(); } CleanTestBase.RunAutomatically(true); }
public void MakePlotTest() { CleanTestBase.RunAutomatically(false); var cs = new OxyCalculationSetup(Utili.GetCurrentMethodAndClass()); cs.StartHousehold(1, GlobalConsts.CSVCharacter, configSetter: x => x.Enable(CalcOption.LocationsFile)); //cs.Wd.InputDataLogger.AddSaver(new HouseholdKeyLogger(cs.Wd.SqlResultLoggingService)); using (FileFactoryAndTracker fft = new FileFactoryAndTracker(cs.DstDir, "1", cs.Wd.InputDataLogger)) { fft.ReadExistingFilesFromSql(); Logger.Info("Making picture"); var di = new DirectoryInfo(cs.DstDir); var files = FileFinder.GetRecursiveFiles(di, "LocationStatistics.HH1.csv"); files.Count.Should().BeGreaterOrEqualTo(1); CalculationProfiler cp = new CalculationProfiler(); ChartCreationParameters ccps = new ChartCreationParameters(300, 4000, 2500, false, GlobalConsts.CSVCharacter, new DirectoryInfo(cs.DstDir)); var locationStatistics = new LocationStatistics(ccps, fft, cp); var rfe = cs.GetRfeByFilename("LocationStatistics.HH1.csv"); locationStatistics.MakePlot(rfe); Logger.Info("finished picture"); // OxyCalculationSetup.CopyImage(resultFileEntries[0].FullFileName); var imagefiles = FileFinder.GetRecursiveFiles(di, "LocationStatistics.*.png"); imagefiles.Count.Should().BeGreaterOrEqualTo(1); } cs.CleanUp(); CleanTestBase.RunAutomatically(true); }
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);
public void MakePlotTestForHouse() { CleanTestBase.RunAutomatically(false); var cs = new OxyCalculationSetup(Utili.GetCurrentMethodAndClass()); cs.StartHousehold(1, GlobalConsts.CSVCharacter, LoadTypePriority.RecommendedForHouses, configSetter: x => { x.Enable(CalcOption.DeviceProfileExternalEntireHouse); x.ExternalTimeResolution = "00:30:00"; x.CSVCharacter = ";"; }, useHouse: true); using (FileFactoryAndTracker fft = new FileFactoryAndTracker(cs.DstDir, "1", cs.Wd.InputDataLogger)) { CalculationProfiler cp = new CalculationProfiler(); ChartCreationParameters ccps = new ChartCreationParameters(300, 4000, 2500, false, GlobalConsts.CSVCharacter, new DirectoryInfo(cs.DstDir)); var aeupp = new DeviceProfilesExternal(ccps, fft, cp); Logger.Info("Making picture"); var di = new DirectoryInfo(cs.DstDir); var rfe = cs.GetRfeByFilename("DeviceProfiles_1800s.Electricity.csv"); aeupp.MakePlot(rfe); Logger.Info("finished picture"); var imagefiles = FileFinder.GetRecursiveFiles(di, "DeviceProfiles*.png"); imagefiles.Count.Should().BeGreaterOrEqualTo(1); } cs.CleanUp(); CleanTestBase.RunAutomatically(true); }
public void MakePlotTest() { CleanTestBase.RunAutomatically(false); var cs = new OxyCalculationSetup(Utili.GetCurrentMethodAndClass()); cs.StartHousehold(2, GlobalConsts.CSVCharacter, LoadTypePriority.Mandatory, configSetter: x => { x.Enable(CalcOption.DeviceProfilesIndividualHouseholds); x.Enable(CalcOption.HouseholdContents); x.SelectedEnergyIntensity = EnergyIntensityType.EnergySavingPreferMeasured; x.EndDateDateTime = new DateTime(2012, 12, 31); }, energyIntensity: EnergyIntensityType.EnergySavingPreferMeasured); using (FileFactoryAndTracker fft = new FileFactoryAndTracker(cs.DstDir, "1", cs.Wd.InputDataLogger)) { fft.ReadExistingFilesFromSql(); DeviceProfiles.DaysToMake = 365; CalculationProfiler cp = new CalculationProfiler(); ChartCreationParameters ccps = new ChartCreationParameters(300, 4000, 2500, false, GlobalConsts.CSVCharacter, new DirectoryInfo(cs.DstDir)); var calcParameters = new CalcParameterLogger(cs.Wd.SqlResultLoggingService).Load(); var aeupp = new DeviceProfiles(ccps, fft, cp, cs.Wd.SqlResultLoggingService, calcParameters); Logger.Info("Making picture"); var di = new DirectoryInfo(cs.DstDir); var rfe = cs.GetRfeByFilename("DeviceProfiles.Electricity.csv"); aeupp.MakePlot(rfe); Logger.Info("finished picture"); var imagefiles = FileFinder.GetRecursiveFiles(di, "DeviceProfiles.*.png"); imagefiles.Count.Should().BeGreaterOrEqualTo(1); } cs.CleanUp(); CleanTestBase.RunAutomatically(true); }
public void MakePlotTest() { CleanTestBase.RunAutomatically(false); var cs = new OxyCalculationSetup(Utili.GetCurrentMethodAndClass()); cs.StartHousehold(1, GlobalConsts.CSVCharacter, LoadTypePriority.Mandatory, configSetter: x => x.Enable(CalcOption.TimeOfUsePlot)); using (FileFactoryAndTracker fft = new FileFactoryAndTracker(cs.DstDir, "1", cs.Wd.InputDataLogger)) { fft.ReadExistingFilesFromSql(); CalculationProfiler cp = new CalculationProfiler(); ChartCreationParameters ccps = new ChartCreationParameters(300, 4000, 2500, false, GlobalConsts.CSVCharacter, new DirectoryInfo(cs.DstDir)); var tou = new TimeOfUse(ccps, fft, cp); Logger.Info("Making picture"); var di = new DirectoryInfo(cs.DstDir); var rfe = cs.GetRfeByFilename("TimeOfUseProfiles.Electricity.csv"); tou.MakePlot(rfe); //OxyCalculationSetup.CopyImage(resultFileEntries[0].FullFileName); var imagefiles = FileFinder.GetRecursiveFiles(di, "TimeOfUseProfiles.*.png"); imagefiles.Count.Should().BeGreaterOrEqualTo(1); } cs.CleanUp(); CleanTestBase.RunAutomatically(true); }
public void MakePlotTest() { CleanTestBase.RunAutomatically(false); var cs = new OxyCalculationSetup(Utili.GetCurrentMethodAndClass()); cs.StartHousehold(1, GlobalConsts.CSVCharacter, LoadTypePriority.Mandatory, null, x => x.Enable(CalcOption.VariableLogFile)); using (FileFactoryAndTracker fft = new FileFactoryAndTracker(cs.DstDir, "1", cs.Wd.InputDataLogger)) { CalculationProfiler cp = new CalculationProfiler(); ChartCreationParameters ccps = new ChartCreationParameters(300, 4000, 2500, false, GlobalConsts.CSVCharacter, new DirectoryInfo(cs.DstDir)); var aeupp = new VariableLogFileChart(ccps, fft, cp); Logger.Info("Making picture"); var di = new DirectoryInfo(cs.DstDir); var rfe = cs.GetRfeByFilename("Variablelogfile.HH1.csv"); aeupp.MakePlot(rfe); Logger.Info("finished picture"); //OxyCalculationSetup.CopyImage(ffe); var imagefiles = FileFinder.GetRecursiveFiles(di, "Variablelogfile.*.png"); imagefiles.Count.Should().BeGreaterOrEqualTo(1); } cs.CleanUp(); CleanTestBase.RunAutomatically(true); }
public void MakePlotTest() { CleanTestBase.RunAutomatically(false); //ChartLocalizer.ShouldTranslate = true; var cs = new OxyCalculationSetup(Utili.GetCurrentMethodAndClass()); cs.StartHousehold(2, GlobalConsts.CSVCharacter, configSetter: x => x.Enable(CalcOption.ActivationFrequencies)); using (FileFactoryAndTracker fft = new FileFactoryAndTracker(cs.DstDir, "1", cs.Wd.InputDataLogger)) { fft.ReadExistingFilesFromSql(); CalculationProfiler cp = new CalculationProfiler(); ChartCreationParameters ccps = new ChartCreationParameters(300, 4000, 2500, false, GlobalConsts.CSVCharacter, new DirectoryInfo(cs.DstDir)); var aeupp = new AffordanceTaggingSet(ccps, fft, cp); Logger.Debug("Making picture"); var di = new DirectoryInfo(cs.DstDir); ResultFileEntry rfe = cs.GetRfeByFilename("AffordanceTaggingSet.Wo bleibt die Zeit.HH1.csv"); aeupp.MakePlot(rfe); Logger.Debug("finished picture"); //OxyCalculationSetup.CopyImage(resultFileEntries[0].FullFileName); var imagefiles = FileFinder.GetRecursiveFiles(di, "AffordanceTaggingSet.*.png"); imagefiles.Count.Should().BeGreaterOrEqualTo(1); } Logger.Warning("Open threads for database: " + Connection.ConnectionCount); Command.PrintOpenConnections(); cs.CleanUp(); CleanTestBase.RunAutomatically(true); }
public void Version520TimeLimitImport() { string sourcefilepath = DatabaseSetup.GetImportFileFullPath("profilegenerator520_simon.db3"); CleanTestBase.RunAutomatically(false); using (var wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { var fi = new FileInfo(sourcefilepath); if (!File.Exists(sourcefilepath)) { throw new LPGException("Missing file: " + fi.FullName); } using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { var mainSim = new Simulator(db.ConnectionString); var dbm = new DatabaseMerger(mainSim); Logger.Info("Full Source: " + fi.FullName); dbm.RunFindItems(sourcefilepath, null); dbm.RunImport(null); var timelimits = dbm.ItemsToImport.Count(x => x.Entry.GetType() == typeof(TimeLimit)); timelimits.Should().BeGreaterThan(0); // ReSharper disable once UnusedVariable #pragma warning disable S1481 // Unused local variables should be removed var mainSim2 = new Simulator(db.ConnectionString); } #pragma warning restore S1481 // Unused local variables should be removed /*mainSim2.MyGeneralConfig.PerformCleanUpChecks = "false"; * var toDelete = new List<DeviceActionGroup>(); * foreach (DeviceActionGroup deviceActionGroup in mainSim2.DeviceActionGroups.It) { * var actions = deviceActionGroup.GetDeviceActions(mainSim2.DeviceActions.It); * if(actions.Count == 0) * toDelete.Add(deviceActionGroup); * } * foreach (DeviceActionGroup deviceActionGroup in toDelete) { * mainSim2.DeviceActionGroups.DeleteItem(deviceActionGroup); * } * var dsttag = mainSim2.TraitTags.It.First(x => x.Name.StartsWith("Living ")); * foreach (ModularHousehold modularHousehold in mainSim2.ModularHouseholds.It) { * var toSet = new List<ModularHouseholdPerson>(); * foreach (ModularHouseholdPerson modularHouseholdPerson in modularHousehold.Persons) { * if (modularHouseholdPerson.TraitTag == null) { * toSet.Add(modularHouseholdPerson); * } * } * foreach (ModularHouseholdPerson person in toSet) { * modularHousehold.SwapPersons(person, person.Person, dsttag); * } * modularHousehold.SaveToDB(); * } * SimIntegrityChecker.Run(mainSim2);*/ wd.CleanUp(); } CleanTestBase.RunAutomatically(true); }
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 MakeNRWChartTest() { CleanTestBase.RunAutomatically(false); using (var wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { var sim = new Simulator(db.ConnectionString); var versions = sim.CalculationOutcomes.It.Select(x => x.LPGVersion).Distinct().ToList(); versions.Sort(); var dstversion = versions.Last(); //ChartLocalizer.ShouldTranslate = false; var se1 = new MakeNRWChart.SeriesEntry(0.1, "EnergyIntensivePreferMeasured", "Energieintensive Gerätewahl", dstversion); var se2 = new MakeNRWChart.SeriesEntry(-0.1, "EnergySavingPreferMeasured", "Energiesparende Gerätewahl", dstversion); //MakeNRWChart.SeriesEntry se3 = new MakeNRWChart.SeriesEntry(-0.1, "EnergyIntensive","EnergyIntensive Gerätewahl", dstversion); //MakeNRWChart.SeriesEntry se4 = new MakeNRWChart.SeriesEntry(-0.1, "EnergySaving", "EnergySaving Gerätewahl", dstversion); var seriesEntries = new List <MakeNRWChart.SeriesEntry> { se1, se2 }; // seriesEntries.Add(se3); // seriesEntries.Add(se4); CalculationProfiler cp = new CalculationProfiler(); foreach (var version in versions) { var v = version; var versionEntries = sim.CalculationOutcomes.It.Where(x => x.LPGVersion == v).ToList(); if (versionEntries.Count == 0) { throw new LPGException("No Entries Found"); } var mnc = new MakeNRWChart(150, 1000, 1600, cp); var pngname = Path.Combine(wd.WorkingDirectory, "testchart." + version + ".png"); // string pdfname = Path.Combine(wd.WorkingDirectory, "testchart." + version + ".pdf"); mnc.MakeScatterChart(versionEntries, pngname, seriesEntries); } var imagefiles = FileFinder.GetRecursiveFiles(new DirectoryInfo(wd.WorkingDirectory), "testchart.*.png"); imagefiles.Count.Should().BeGreaterOrEqualTo(1); db.Cleanup(); } wd.CleanUp(); } CleanTestBase.RunAutomatically(true); }
public void SimHouseIntegiryChecker() { CleanTestBase.RunAutomatically(false); using (DatabaseSetup db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { Simulator sim = new Simulator(db.ConnectionString); sim.Should().NotBeNull(); foreach (var house in sim.Houses.MyItems) { HouseIntegrityChecker.Run(house, sim); } db.Cleanup(); } CleanTestBase.RunAutomatically(true); }
public void CheckSimIntegrityCheckerTest() { CleanTestBase.RunAutomatically(false); using (DatabaseSetup db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { Simulator sim = new Simulator(db.ConnectionString); sim.Should().NotBeNull(); Vacation vac = sim.Vacations.CreateNewItem(sim.ConnectionString); vac.AddVacationTime(new DateTime(2017, 1, 1), new DateTime(2017, 2, 1), VacationType.GoAway); vac.AddVacationTime(new DateTime(2017, 2, 1), new DateTime(2017, 2, 15), VacationType.GoAway); SimIntegrityChecker.Run(sim); db.Cleanup(); } CleanTestBase.RunAutomatically(true); }
public void LoadEmptyDatabase() { CleanTestBase.RunAutomatically(false); using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { ClearAllTables(db); #pragma warning disable S1854 // Dead stores should be removed #pragma warning disable S1481 // Unused local variables should be removed #pragma warning disable IDE0059 // Value assigned to symbol is never used var oldSim = new Simulator(db.ConnectionString); // need to load it for testing #pragma warning restore IDE0059 // Value assigned to symbol is never used #pragma warning restore S1481 // Unused local variables should be removed #pragma warning restore S1854 // Dead stores should be removed db.Cleanup(); } CleanTestBase.RunAutomatically(true); }
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 DeviceTaggingSetTest() { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { db.ClearTable(DeviceTaggingSet.TableName); db.ClearTable(DeviceTaggingEntry.TableName); db.ClearTable(DeviceTag.TableName); db.ClearTable(DeviceTaggingReference.TableName); db.ClearTable(DeviceTaggingSetLoadType.TableName); var profiles = db.LoadTimeBasedProfiles(); var realDevices = db.LoadRealDevices(out _, out var loadTypes, profiles); var ats = new ObservableCollection <DeviceTaggingSet>(); DeviceTaggingSet.LoadFromDatabase(ats, db.ConnectionString, false, realDevices, loadTypes); var ats1 = new DeviceTaggingSet("test", "desc", db.ConnectionString, System.Guid.NewGuid().ToStrGuid()); ats1.SaveToDB(); var tag = ats1.AddNewTag("newtag"); ats1.SaveToDB(); if (tag == null) { throw new LPGException("Tag was null"); } ats1.AddTaggingEntry(tag, realDevices[0]); ats1.SaveToDB(); ats1.AddReferenceEntry(tag, 1, 10, loadTypes[0]); ats.Clear(); DeviceTaggingSet.LoadFromDatabase(ats, db.ConnectionString, false, realDevices, loadTypes); ats[0].References.Count.Should().Be(1); ats[0].References[0].PersonCount.Should().Be(1); ats[0].References[0].ReferenceValue.Should().Be(10); ats1 = ats[0]; ats1.DeleteTag(ats1.Tags[0]); ats1.DeleteFromDB(); ats.Clear(); DeviceTaggingSet.LoadFromDatabase(ats, db.ConnectionString, false, realDevices, loadTypes); ats.Count.Should().Be(0); db.Cleanup(); } CleanTestBase.RunAutomatically(true); }
public void MakePlotTest() { CleanTestBase.RunAutomatically(false); Config.MakePDFCharts = false; //ChartLocalizer.ShouldTranslate = false; var cs = new OxyCalculationSetup(Utili.GetCurrentMethodAndClass()); var rep = cs.StartHousehold(2, GlobalConsts.CSVCharacter, configSetter: x => { x.Enable(CalcOption.AffordanceEnergyUse); x.Enable(CalcOption.HouseSumProfilesFromDetailedDats); x.Enable(CalcOption.DeviceProfilesIndividualHouseholds); }); if (rep == null) { throw new LPGException("Failed to simulate"); } using (FileFactoryAndTracker fft = new FileFactoryAndTracker(cs.DstDir, "1", cs.Wd.InputDataLogger)) { fft.ReadExistingFilesFromSql(); ChartCreationParameters ccps = new ChartCreationParameters(144, 4000, 2500, false, GlobalConsts.CSVCharacter, new DirectoryInfo(cs.DstDir)); CalculationProfiler cp = new CalculationProfiler(); var affordanceEnergyUsePerPerson = new AffordanceEnergyUsePerPerson(ccps, fft, cp, rep); Logger.Info("Making picture"); var di = new DirectoryInfo(cs.DstDir); //var rfe = cs.GetRfeByFilename("AffordanceEnergyUsePerPerson.HH1.Electricity.csv"); var keys = rep.HouseholdKeys; rep.FindTableByKey(ResultTableID.AffordanceEnergyUse, keys[1].HHKey); affordanceEnergyUsePerPerson.MakePlot(keys[1]); Logger.Info("finished picture"); //OxyCalculationSetup.CopyImage(resultFileEntries[0].FullFileName); var imagefiles = FileFinder.GetRecursiveFiles(di, "AffordanceEnergyUsePerPerson.*.png"); imagefiles.Count.Should().BeGreaterOrEqualTo(1); } cs.CleanUp(); //CleanTestBase.Run(true); }
private static void TestImport([JetBrains.Annotations.NotNull] string srcfilename, [JetBrains.Annotations.NotNull] out Simulator mainsim, [JetBrains.Annotations.NotNull] out DatabaseMerger dbm, ClearMode clearTablesMode, bool checkrowcounts, [JetBrains.Annotations.NotNull] out DatabaseSetup db, bool clearDstFolder) { var acceptedUneven = new List <string> { "tblSettings", "tblOptions", "tblHHTTraits", // this is messed up since it would need a sorting of the householdtraits by subtraits "tblLPGVersion", // settings are not imported "tblHouseholdPlanEntries" //nobody cares about the household plans anymore }; if (clearDstFolder) { CleanTestBase.RunAutomatically(false); } DirectoryInfo di = new DirectoryInfo("."); Logger.Info("Current directory:" + di.FullName); var fis = di.GetFiles(); Logger.Info("Files in this directory:"); foreach (var fileInfo in fis) { Logger.Info(fileInfo.Name); } var fi = FindImportFile(srcfilename); db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()); var oldSim = new Simulator(db.ConnectionString); Dictionary <string, int> srctablerowcounts = null; switch (clearTablesMode) { case ClearMode.ClearTable: { var connectionstrOld = "Data Source=" + fi.FullName; srctablerowcounts = GetTableRowCounts(connectionstrOld); ClearAllTables(db); } break; case ClearMode.DeleteOnlyOneRow: { var connectionstrOld = "Data Source=" + fi.FullName; srctablerowcounts = GetTableRowCounts(connectionstrOld); DeleteOneElementFromAllTables(db); } break; case ClearMode.NoClearing: break; default: throw new ArgumentOutOfRangeException(nameof(clearTablesMode), clearTablesMode, null); } var mainSim = new Simulator(db.ConnectionString); dbm = new DatabaseMerger(mainSim); dbm.RunFindItems(fi.FullName, null); dbm.RunImport(null); foreach (var oldAff in oldSim.Affordances.MyItems) { foreach (var newAff in mainSim.Affordances.MyItems) { if (newAff.Name == oldAff.Name) { foreach (var oldDes in oldAff.AffordanceDesires) { var foundDesire = false; foreach (var newDes in newAff.AffordanceDesires) { if (oldDes.Desire.Name == newDes.Desire.Name) { foundDesire = true; } } if (!foundDesire) { Logger.Info("Missing affordance Desire in " + oldAff.Name + " " + oldDes.Desire.Name); } } } } } foreach (var hhg in oldSim.HouseholdTemplates.It) { Logger.Info("HHG 1:" + hhg.Name + " " + hhg.Entries.Count); } foreach (var hhg in mainSim.HouseholdTemplates.It) { Logger.Info("HHG 2:" + hhg.Name + " " + hhg.Entries.Count); } if (checkrowcounts && srctablerowcounts != null) { var dsttablerowcounts = GetTableRowCounts(db.ConnectionString); var errors = new List <string>(); foreach (var srctablerowcount in srctablerowcounts) { if (!acceptedUneven.Contains(srctablerowcount.Key)) { if (!dsttablerowcounts.ContainsKey(srctablerowcount.Key)) { errors.Add(srctablerowcount.Key + " is missing in the dst"); } if (dsttablerowcounts[srctablerowcount.Key] != srctablerowcount.Value) { errors.Add(srctablerowcount.Key + " is missing rows: dst = " + dsttablerowcounts[srctablerowcount.Key] + " src = " + srctablerowcount.Value); } } } var s = string.Empty; foreach (var error in errors) { Logger.Error(error); s += error + Environment.NewLine; } if (s.Length > 0) { throw new LPGException("Errors happened in " + s); } } mainsim = mainSim; // load again to see if anything gets deleted on loading Logger.Threshold = Severity.Debug; var oldSim2 = new Simulator(db.ConnectionString); foreach (var hhg in oldSim2.HouseholdTemplates.It) { Logger.Info("HHG 3:" + hhg.Name + " " + hhg.Entries.Count); } foreach (var hhg in mainSim.HouseholdTemplates.It) { Logger.Info("HHG 4:" + hhg.Name + " " + hhg.Entries.Count); } if (checkrowcounts) { var dsttablerowcounts = GetTableRowCounts(db.ConnectionString); var errors = new List <string>(); if (srctablerowcounts == null) { throw new LPGException("srctablerowcounts was null"); } foreach (var srctablerowcount in srctablerowcounts) { if (!acceptedUneven.Contains(srctablerowcount.Key)) { if (!dsttablerowcounts.ContainsKey(srctablerowcount.Key)) { errors.Add(srctablerowcount.Key + " is missing in the dst"); } if (dsttablerowcounts[srctablerowcount.Key] != srctablerowcount.Value) { errors.Add(srctablerowcount.Key + " is missing rows: dst = " + dsttablerowcounts[srctablerowcount.Key] + " src = " + srctablerowcount.Value); } } } var s = string.Empty; foreach (var error in errors) { Logger.Error(error); #pragma warning disable CC0039 // Don't concatenate strings in loops s += error + Environment.NewLine; #pragma warning restore CC0039 // Don't concatenate strings in loops } if (s.Length > 0) { throw new LPGException("Errors happened in " + s); } } db.Cleanup(); if (clearDstFolder) { CleanTestBase.RunAutomatically(true); } }