public void HolidayProbabilitesCalculateTest() { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { // test the normal loading var holidays = new ObservableCollection <Holiday>(); Holiday.LoadFromDatabase(holidays, db.ConnectionString, false); // delete everything and check holidays.Clear(); db.ClearTable(Holiday.TableName); db.ClearTable(HolidayDate.TableName); db.ClearTable(HolidayProbabilities.TableName); Holiday.LoadFromDatabase(holidays, db.ConnectionString, false); (holidays.Count).Should().Be(0); // add one and load again var hd = new Holiday("my holiday", "blub", db.ConnectionString, Guid.NewGuid().ToStrGuid()); hd.SaveToDB(); hd.ProbMonday.Tuesday = 100; hd.ProbMonday.Wednesday = 0; var holiday = new DateTime(2014, 2, 17); hd.AddNewDate(holiday); hd.SaveToDB(); var r = new Random(1); var dts = hd.GetListOfWorkFreeDates(r, "test"); (dts.Count).Should().Be(2); Assert.True(dts.ContainsKey(holiday)); Assert.True(dts.ContainsKey(holiday.AddDays(1))); db.Cleanup(); } }
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, 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 HouseDeviceOrphanCreatingTest() { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { db.ClearTable(HouseType.TableName); db.ClearTable(HouseTypeDevice.TableName); var loadTypes = db.LoadLoadTypes(); var devices = new ObservableCollection <RealDevice>(); var deviceCategories = new ObservableCollection <DeviceCategory>(); var timeBasedProfiles = new ObservableCollection <TimeBasedProfile>(); var timeLimits = new ObservableCollection <TimeLimit>(); var variables = db.LoadVariables(); var deviceActionGroups = db.LoadDeviceActionGroups(); var deviceActions = db.LoadDeviceActions(timeBasedProfiles, devices, loadTypes, deviceActionGroups); var energyStorages = db.LoadEnergyStorages(loadTypes, variables); var trafoDevices = db.LoadTransformationDevices(loadTypes, variables); var dateprofiles = db.LoadDateBasedProfiles(); var generators = db.LoadGenerators(loadTypes, dateprofiles); var houseTypes = new ObservableCollection <HouseType>(); var locations = db.LoadLocations(devices, deviceCategories, loadTypes); HouseType.LoadFromDatabase(houseTypes, db.ConnectionString, devices, deviceCategories, timeBasedProfiles, timeLimits, loadTypes, trafoDevices, energyStorages, generators, false, locations, deviceActions, deviceActionGroups, variables); (houseTypes.Count).Should().Be(0); var housetype = new HouseType("haus1", "blub", 1000, 5, 10, loadTypes[0], db.ConnectionString, 1, 1, loadTypes[1], false, 0, false, 0, 1, 100, Guid.NewGuid().ToStrGuid()); housetype.SaveToDB(); var rd = new RealDevice("test", 1, "bla", null, "name", true, false, db.ConnectionString, Guid.NewGuid().ToStrGuid()); rd.SaveToDB(); devices.Add(rd); var dt = new TimeLimit("blub", db.ConnectionString, Guid.NewGuid().ToStrGuid()); timeLimits.Add(dt); dt.SaveToDB(); var tp = new TimeBasedProfile("blub", null, db.ConnectionString, TimeProfileType.Relative, "fake", Guid.NewGuid().ToStrGuid()); timeBasedProfiles.Add(tp); tp.SaveToDB(); housetype.AddHouseTypeDevice(rd, dt, tp, 1, loadTypes[0], locations[0], 0, VariableCondition.Equal, variables[0]); houseTypes.Clear(); HouseType.LoadFromDatabase(houseTypes, db.ConnectionString, devices, deviceCategories, timeBasedProfiles, timeLimits, loadTypes, trafoDevices, energyStorages, generators, false, locations, deviceActions, deviceActionGroups, variables); (houseTypes.Count).Should().Be(1); var house3 = houseTypes[0]; (house3.HouseDevices.Count).Should().Be(1); db.ClearTable(HouseType.TableName); houseTypes.Clear(); HouseType.LoadFromDatabase(houseTypes, db.ConnectionString, devices, deviceCategories, timeBasedProfiles, timeLimits, loadTypes, trafoDevices, energyStorages, generators, false, locations, deviceActions, deviceActionGroups, variables); (houseTypes.Count).Should().Be(0); db.Cleanup(); } }
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); }
public void HouseholdTemplateTest() { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { db.ClearTable(HouseholdTemplate.TableName); db.ClearTable(HHTemplateEntry.TableName); db.ClearTable(HHTemplateVacation.TableName); db.ClearTable(HHTemplateEntryPerson.TableName); db.ClearTable(HHTemplateTag.TableName); var sim = new Simulator(db.ConnectionString); var hhtemplate = sim.HouseholdTemplates.CreateNewItem(db.ConnectionString); hhtemplate.SaveToDB(); hhtemplate.AddEntry(sim.TraitTags[0], 1, 100); hhtemplate.AddPerson(sim.Persons[0], sim.TraitTags[0]); sim.HouseholdTags.CreateNewItem(sim.ConnectionString); hhtemplate.AddTemplateTag(sim.HouseholdTags[0]); (sim.HouseholdTemplates.It.Count).Should().Be(1); (hhtemplate.Entries.Count).Should().Be(1); var sim2 = new Simulator(db.ConnectionString); (sim2.HouseholdTemplates.It.Count).Should().Be(1); (sim2.HouseholdTemplates[0].Entries.Count).Should().Be(1); (sim2.HouseholdTemplates[0].Persons.Count).Should().Be(1); (sim2.HouseholdTemplates[0].TemplateTags.Count).Should().Be(1); db.Cleanup(); } }
public void ImportExistingModularTest() { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { var sim = new Simulator(db.ConnectionString); var newHouseholdTemplate = sim.HouseholdTemplates.CreateNewItem(db.ConnectionString); newHouseholdTemplate.NewHHName = "hh"; var existingHouseholdTemplate = sim.ModularHouseholds.It.FirstOrDefault(x => x.Name.StartsWith("CHS01", StringComparison.Ordinal)); if (existingHouseholdTemplate == null) { throw new LPGException("Could not find chs01"); } newHouseholdTemplate.ImportExistingModularHouseholds(existingHouseholdTemplate); newHouseholdTemplate.SaveToDB(); newHouseholdTemplate.GenerateHouseholds(sim, true, new List <STTraitLimit>()); var total = 0; foreach (var entry in newHouseholdTemplate.Entries) { Logger.Info(entry.PrettyString); total += entry.TraitCountMax; } total.Should().BeGreaterOrEqualTo(existingHouseholdTemplate.Traits.Count); db.Cleanup(); } }
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 RunTestCurrentVersionIdentical() { // tests with the current database without any changes. this should find nothing to import HouseholdPlan.FailOnIncorrectImport = true; using (var wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { var path = Path.Combine(wd.WorkingDirectory, "profilegeneratorNothingImportTest.db3"); if (File.Exists(path)) { File.Delete(path); Thread.Sleep(3000); } File.Copy(DatabaseSetup.GetSourcepath(null), path); using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { var mainSim = new Simulator(db.ConnectionString); var dbm = new DatabaseMerger(mainSim); dbm.RunFindItems(path, null); Logger.Info("Found " + dbm.ItemsToImport.Count + " items."); if (dbm.ItemsToImport.Count != 0) { throw new LPGException("This should not import anything, since its the same database."); } db.Cleanup(); } wd.CleanUp(); } }
public void RunTest() { using (WorkingDir wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { ActionEntryLogger ael = new ActionEntryLogger(wd.SqlResultLoggingService); HouseholdKey key = new HouseholdKey("hhkey"); List <IDataSaverBase> savers = new List <IDataSaverBase> { ael }; InputDataLogger idl = new InputDataLogger(savers.ToArray()); TimeStep ts = new TimeStep(1, 0, true); ActionEntry ae1 = new ActionEntry("blub", key, ts, DateTime.Now, "123".ToStrGuid(), "name", false, "affname", "affguid".ToStrGuid(), 0, BodilyActivityLevel.Low); List <IHouseholdKey> aes = new List <IHouseholdKey> { ae1 }; idl.SaveList(aes); var res = ael.Read(key); var s1 = JsonConvert.SerializeObject(aes, Formatting.Indented); var s2 = JsonConvert.SerializeObject(res, Formatting.Indented); s1.Should().Be(s2); wd.CleanUp(); } }
public void LoadFromDatabaseTest() { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { var profiles = db.LoadTimeBasedProfiles(); var realDevices = db.LoadRealDevices(out var deviceCategories, out var loadTypes, profiles); var timeBasedProfiles = db.LoadTimeBasedProfiles(); var desires = db.LoadDesires(); var affordances = new ObservableCollection <Affordance>(); var subaffordances = new ObservableCollection <SubAffordance>(); var dateBasedProfiles = db.LoadDateBasedProfiles(); var timeLimits = db.LoadTimeLimits(dateBasedProfiles); var deviceActionGroups = db.LoadDeviceActionGroups(); var deviceActions = db.LoadDeviceActions(timeBasedProfiles, realDevices, loadTypes, deviceActionGroups); var locations = db.LoadLocations(realDevices, deviceCategories, loadTypes); var variables = db.LoadVariables(); SubAffordance.LoadFromDatabase(subaffordances, db.ConnectionString, desires, false, locations, variables); Affordance.LoadFromDatabase(affordances, db.ConnectionString, timeBasedProfiles, deviceCategories, realDevices, desires, subaffordances, loadTypes, timeLimits, deviceActions, deviceActionGroups, locations, false, variables); db.Cleanup(); } }
public void MakeDegreeDaysTest3Years() { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { var temperaturProfiles = db.LoadTemperatureProfiles(); var startTime = new DateTime(2012, 1, 1); var endTime = new DateTime(2014, 12, 31); var ldd = DbCalcDegreeHour.GetCalcDegreeHours(temperaturProfiles[0], startTime, endTime, 19, 10000, false, 0); double sumHeating = 0; double sumPercentages = 0; var temperatures = temperaturProfiles[0].GetTemperatureArray(startTime, endTime, new TimeSpan(1, 0, 0)); for (var i = 0; i < temperatures.Length; i++) { Math.Abs(ldd[i].AverageTemperature - temperatures[i]).Should().BeLessThan(0.001); } foreach (var day in ldd) { sumHeating += day.CoolingAmount; sumPercentages += day.Percentage; } Math.Abs(30000 - sumHeating).Should().BeLessThan(0.001); Math.Abs(3 - sumPercentages).Should().BeLessThan(0.001); db.Cleanup(); } }
public void LoadFromDatabaseTest() { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { db.ClearTable(TemperatureProfile.TableName); db.ClearTable(TemperatureValue.TableName); var profiles = new ObservableCollection <TemperatureProfile>(); TemperatureProfile.LoadFromDatabase(profiles, db.ConnectionString, false); foreach (var temperaturProfile in profiles) { temperaturProfile.DeleteFromDB(); } var tp = new TemperatureProfile("tempprofil1", null, "desc1", db.ConnectionString, Guid.NewGuid().ToStrGuid()); tp.SaveToDB(); tp.AddTemperature(new DateTime(2011, 1, 1), 20); tp.AddTemperature(new DateTime(2011, 2, 1), 15); tp.SaveToDB(); TemperatureProfile.LoadFromDatabase(profiles, db.ConnectionString, false); (profiles.Count).Should().Be(1); (profiles[0].TemperatureValues.Count).Should().Be(2); profiles[0].DeleteOneTemperatur(profiles[0].TemperatureValues[0]); (profiles[0].TemperatureValues.Count).Should().Be(1); db.Cleanup(); } }
public void HolidayProbabilitesSaveTest() { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { // test the normal loading var holidays = new ObservableCollection <Holiday>(); Holiday.LoadFromDatabase(holidays, db.ConnectionString, false); // delete everything and check holidays.Clear(); db.ClearTable(Holiday.TableName); db.ClearTable(HolidayDate.TableName); db.ClearTable(HolidayProbabilities.TableName); Holiday.LoadFromDatabase(holidays, db.ConnectionString, false); (holidays.Count).Should().Be(0); // add one and load again var hd = new Holiday("my holiday", "blub", db.ConnectionString, Guid.NewGuid().ToStrGuid()); hd.SaveToDB(); hd.ProbMonday.Monday = 5; hd.SaveToDB(); Holiday.LoadFromDatabase(holidays, db.ConnectionString, false); (holidays.Count).Should().Be(1); (holidays[0].ProbMonday.Monday).Should().Be(5); // delete the loaded one holidays[0].DeleteFromDB(); holidays.Clear(); Holiday.LoadFromDatabase(holidays, db.ConnectionString, false); (holidays.Count).Should().Be(0); db.Cleanup(); } }
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 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 HouseholdTemplateGenerationTest() { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { var sim = new Simulator(db.ConnectionString); var gen = sim.HouseholdTemplates.CreateNewItem(db.ConnectionString); gen.NewHHName = "hh"; var entry = gen.AddEntry(sim.TraitTags[0], 5, 10); TraitTag tt = sim.TraitTags[0]; gen.AddPerson(sim.Persons[0], tt); entry.AddPerson(sim.Persons[0]); gen.SaveToDB(); gen.GenerateHouseholds(sim, true, new List <STTraitLimit>()); foreach (var household in gen.GeneratedHouseholds) { Logger.Info(household.Name); foreach (var trait in household.Traits) { Logger.Info("\t" + trait.HouseholdTrait.Name); } } db.Cleanup(); } }
public void RunTest() { using (WorkingDir wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { HouseholdKeyLogger ael = new HouseholdKeyLogger(wd.SqlResultLoggingService); HouseholdKey key = new HouseholdKey("hhkey"); List <IDataSaverBase> savers = new List <IDataSaverBase> { ael }; InputDataLogger idl = new InputDataLogger(savers.ToArray()); HouseholdKeyEntry ae1 = new HouseholdKeyEntry(key, "hhname", HouseholdKeyType.House, "desc", null, null); idl.Save(ae1); List <HouseholdKeyEntry> aes = new List <HouseholdKeyEntry> { ae1 }; var res = ael.Load(); var s1 = JsonConvert.SerializeObject(aes, Formatting.Indented); var s2 = JsonConvert.SerializeObject(res, Formatting.Indented); s1.Should().Be(s2); wd.CleanUp(); } }
public void HouseholdTemplateJsonTestWithFluentAssertion() { // WorkingDir wd = new WorkingDir(Utili.GetCurrentMethodAndClass()); using (var db1 = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { var sim1 = new Simulator(db1.ConnectionString); using (var db2 = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { var sim2 = new Simulator(db2.ConnectionString); //check if the basic thing is identical sim1.HouseholdTemplates[0].Should().BeEquivalentTo(sim2.HouseholdTemplates[0], o => o.Excluding( x => x.SelectedMemberPath.EndsWith("ConnectionString", StringComparison.OrdinalIgnoreCase))); //check import List <HouseholdTemplate.JsonDto> dto1 = new List <HouseholdTemplate.JsonDto>(); foreach (var template in sim1.HouseholdTemplates.It) { dto1.Add(template.GetJson()); } sim2.HouseholdTemplates.DeleteItem(sim2.HouseholdTemplates[0]); HouseholdTemplate.ImportObjectFromJson(sim2, dto1); sim2.HouseholdTemplates.It.Sort(); sim1.HouseholdTemplates[0].Should().BeEquivalentTo(sim2.HouseholdTemplates[0], o => o .Using <IRelevantGuidProvider>(x => x.Subject.RelevantGuid.Should().BeEquivalentTo(x.Expectation.RelevantGuid)).WhenTypeIs <IRelevantGuidProvider>() .Excluding(x => x.SelectedMemberPath.EndsWith("ConnectionString", StringComparison.OrdinalIgnoreCase) || x.SelectedMemberPath.EndsWith("ID", StringComparison.OrdinalIgnoreCase))); } } // ||regex2.IsMatch(x.SelectedMemberPath)) }
public void CalcParameterLoggerTest() { CalcParameters cp = CalcParameters.GetNew(); cp.SetStartDate(2017, 1, 1); cp.SetEndDate(2018, 1, 1); cp.Enable(CalcOption.ActivationsPerHour); using (WorkingDir wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { SqlResultLoggingService srls = new SqlResultLoggingService(wd.WorkingDirectory); CalcParameterLogger cpl = new CalcParameterLogger(srls); cpl.Run(Constants.GeneralHouseholdKey, cp); GC.Collect(); GC.WaitForPendingFinalizers(); CalcParameters cp2 = cpl.Load(); GC.Collect(); GC.WaitForPendingFinalizers(); string s1 = JsonConvert.SerializeObject(cp, Formatting.Indented); string s2 = JsonConvert.SerializeObject(cp2, Formatting.Indented); s1.Should().Be(s2); cp2.IsSet(CalcOption.ActivationsPerHour).Should().BeTrue(); Assert.NotNull(cp2); wd.CleanUp(); } }
public void LoadFromDatabaseTest() { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { var desires = new ObservableCollection <Desire>(); Desire.LoadFromDatabase(desires, db.ConnectionString, false); var subAffordances = new ObservableCollection <SubAffordance>(); var locations = new ObservableCollection <Location>(); var variables = new ObservableCollection <Variable>(); SubAffordance.LoadFromDatabase(subAffordances, db.ConnectionString, desires, false, locations, variables); var affordances = new ObservableCollection <Affordance>(); var affordanceSubAffordances = new ObservableCollection <AffordanceSubAffordance>(); var tbp = new ObservableCollection <TimeBasedProfile>(); var dateBasedProfiles = db.LoadDateBasedProfiles(); var timeLimits = db.LoadTimeLimits(dateBasedProfiles); var aic = new AllItemCollections(timeProfiles: tbp, timeLimits: timeLimits); DBBase.LoadAllFromDatabase(affordances, db.ConnectionString, Affordance.TableName, Affordance.AssignFields, aic, false, true); AffordanceSubAffordance.LoadFromDatabase(affordanceSubAffordances, db.ConnectionString, affordances, subAffordances, false); affordanceSubAffordances.Count.Should().BeGreaterThan(1); db.ClearTable(AffordanceSubAffordance.TableName); affordanceSubAffordances.Clear(); AffordanceSubAffordance.LoadFromDatabase(affordanceSubAffordances, db.ConnectionString, affordances, subAffordances, false); affordanceSubAffordances.Count.Should().Be(0); db.Cleanup(); } }
public void TestMultiplePickingShouldAlwaysGiveSameResult() { using (DatabaseSetup db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { Simulator sim = new Simulator(db.ConnectionString); for (int i = 0; i < 100; i++) { Random r = new Random(5); DeviceCategoryPicker dcp = new DeviceCategoryPicker(r, null); Location loc = new Location("bla", -1, string.Empty, Guid.NewGuid().ToStrGuid()); List <IAssignableDevice> devices = new List <IAssignableDevice>(); devices.Add(sim.RealDevices[0]); dcp.GetOrPickDevice(sim.DeviceActionGroups[1], loc, EnergyIntensityType.Random, devices, sim.DeviceActions.It); } } //ObservableCollection<RealDevice> allDevices = new ObservableCollection<RealDevice>(); //DeviceCategory dc = new DeviceCategory("dc", -1, "bla", false, allDevices, Guid.NewGuid().ToStrGuid()); //RealDevice rd = new RealDevice("bla", 0, string.Empty, dc, "desc", false, true, string.Empty, Guid.NewGuid().ToStrGuid(), -1); //allDevices.Add(rd); //List<IAssignableDevice> devices = new List<IAssignableDevice> //{ // rd //}; //ObservableCollection<DeviceAction> deviceActions = new ObservableCollection<DeviceAction>(); //Logger.Info("put in a rd, get back the same rd"); //RealDevice result = dcp.GetOrPickDevice(rd, loc, EnergyIntensityType.EnergyIntensive, devices, deviceActions); //(result).Should().Be(rd); //// put in an dc with one rd, get the rd 1 //Logger.Info("put in a rd, get back null, since the rd is already there as hhdevloc"); //RealDevice result2 = dcp.GetOrPickDevice(dc, loc, EnergyIntensityType.EnergyIntensive, devices, // deviceActions); //(result2).Should().Be(null); }
public void HouseTypeLoadCreationAndSave2Test() { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { db.ClearTable(House.TableName); db.ClearTable(HouseTypeDevice.TableName); db.ClearTable(HouseHousehold.TableName); var houses = new CategoryDBBase <House>("blub"); houses.CreateNewItem(db.ConnectionString); var devices = new ObservableCollection <RealDevice>(); var deviceCategories = new ObservableCollection <DeviceCategory>(); var timeBasedProfiles = new ObservableCollection <TimeBasedProfile>(); var timeLimits = new ObservableCollection <TimeLimit>(); var loadTypes = db.LoadLoadTypes(); var variables = db.LoadVariables(); var energyStorages = db.LoadEnergyStorages(loadTypes, variables); var trafoDevices = db.LoadTransformationDevices(loadTypes, variables); var dateprofiles = db.LoadDateBasedProfiles(); var generators = db.LoadGenerators(loadTypes, dateprofiles); var houseTypes = new ObservableCollection <HouseType>(); var locations = db.LoadLocations(devices, deviceCategories, loadTypes); var deviceActionGroups = db.LoadDeviceActionGroups(); var deviceActions = db.LoadDeviceActions(timeBasedProfiles, devices, loadTypes, deviceActionGroups); HouseType.LoadFromDatabase(houseTypes, db.ConnectionString, devices, deviceCategories, timeBasedProfiles, timeLimits, loadTypes, trafoDevices, energyStorages, generators, false, locations, deviceActions, deviceActionGroups, variables); houseTypes.Count.Should().BeGreaterOrEqualTo(1); db.Cleanup(); } }
/* * private static void CopyAll([NotNull] DirectoryInfo source, [NotNull] DirectoryInfo target) * { * Directory.CreateDirectory(target.FullName); * * // Copy each file into the new directory. * foreach (var fi in source.GetFiles()) * { * Logger.Info(string.Format(CultureInfo.CurrentCulture, @"Copying {0}\{1}", target.FullName, fi.Name)); * fi.CopyTo(Path.Combine(target.FullName, fi.Name), true); * } * * // Copy each subdirectory using recursion. * foreach (var diSourceSubDir in source.GetDirectories()) * { * var nextTargetSubDir = target.CreateSubdirectory(diSourceSubDir.Name); * CopyAll(diSourceSubDir, nextTargetSubDir); * } * }*/ public void RunDirectHouseholds() { using (DatabaseSetup db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { using (WorkingDir wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { Simulator sim = new Simulator(db.ConnectionString); string dir = wd.Combine("DirectHouseJobs"); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } foreach (var mhh in sim.ModularHouseholds.It) { HouseCreationAndCalculationJob hj = new HouseCreationAndCalculationJob("Households", "2019", "TK", HouseDefinitionType.HouseData); hj.House = new HouseData(Guid.NewGuid().ToStrGuid(), "HT01", 10000, 10000, "House for " + mhh.Name); hj.House.Households.Add(new HouseholdData(Guid.NewGuid().ToString(), mhh.Name, null, null, null, null, HouseholdDataSpecificationType.ByHouseholdName)); hj.House.Households[0].HouseholdNameSpec = new HouseholdNameSpecification(mhh.GetJsonReference()); SetCalcSpec(hj, sim); string fn = Path.Combine(dir, AutomationUtili.CleanFileName(mhh.Name) + ".json"); File.WriteAllText(fn, JsonConvert.SerializeObject(hj, Formatting.Indented)); } //CopyAll(new DirectoryInfo(dir), new DirectoryInfo(@"X:\HouseJobs\Blockstrom\DirectHouseholds")); } } }
public void LoadFromDatabaseTest() { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { var persons = db.LoadPersons(); db.ClearTable(HouseholdTrait.TableName); var affordances = db.LoadAffordances(out var timeBasedProfiles, out _, out var deviceCategories, out var realDevices, out var desires, out var loadTypes, out var timeLimits, out ObservableCollection <DeviceAction> deviceActions, out ObservableCollection <DeviceActionGroup> deviceActionGroups, out var locations, out var variables, out _); var tags = db.LoadTraitTags(); var householdTraits = db.LoadHouseholdTraits(locations, affordances, realDevices, deviceCategories, timeBasedProfiles, loadTypes, timeLimits, desires, deviceActions, deviceActionGroups, tags, variables); var hht = new HouseholdTrait("bla", null, "blub", db.ConnectionString, "none", 1, 100, 10, 1, 1, TimeType.Day, 1, 1, TimeType.Day, 1, 0, EstimateType.Theoretical, "", Guid.NewGuid().ToStrGuid()); hht.SaveToDB(); householdTraits.Add(hht); var chht = new ModularHouseholdTrait(null, null, "hallo", db.ConnectionString, householdTraits[0], null, ModularHouseholdTrait.ModularHouseholdTraitAssignType.Age, Guid.NewGuid().ToStrGuid()); chht.DeleteFromDB(); chht.SaveToDB(); var chht1 = new ModularHouseholdTrait(null, null, "hallo2", db.ConnectionString, householdTraits[0], persons[0], ModularHouseholdTrait.ModularHouseholdTraitAssignType.Name, Guid.NewGuid().ToStrGuid()); chht1.SaveToDB(); chht1.DeleteFromDB(); db.Cleanup(); } }
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(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(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 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); }