public void PostProcessingTestTwoActivation() { var startdate = new DateTime(2018, 1, 1); var enddate = startdate.AddMinutes(100); var calcParameters = CalcParametersFactory.MakeGoodDefaults().SetStartDate(startdate).SetEndDate(enddate).EnableShowSettlingPeriod(); //CalculationProfiler calculationProfiler = new CalculationProfiler(); var rnd = new Random(1); var nr = new NormalRandom(0, 1, rnd); using (var wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { calcParameters.Enable(CalcOption.HouseSumProfilesFromDetailedDats); calcParameters.Enable(CalcOption.DeviceProfilesIndividualHouseholds); calcParameters.Enable(CalcOption.TotalsPerDevice); calcParameters.Enable(CalcOption.TotalsPerLoadtype); calcParameters.Enable(CalcOption.DeviceActivations); calcParameters.Enable(CalcOption.DetailedDatFiles); Config.IsInUnitTesting = true; wd.InputDataLogger.AddSaver(new ResultFileEntryLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new HouseholdKeyLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new CalcParameterLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new CalcLoadTypeDtoLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new ColumnEntryLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new CalcObjectInformationLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new DeviceActivationEntryLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new CalcPersonDtoLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new DeviceTaggingSetLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.Save(calcParameters); using (var fft = new FileFactoryAndTracker(wd.WorkingDirectory, "hh1", wd.InputDataLogger)) { fft.RegisterHousehold(Constants.GeneralHouseholdKey, "general", HouseholdKeyType.General, "desc", null, null); //fft.RegisterHousehold(Constants.GeneralHouseholdKey, "general", HouseholdKeyType.General,"desc"); //SqlResultLoggingService srls =new SqlResultLoggingService(Path.Combine(wd.WorkingDirectory, "results.sqlite")); var dsc = new DateStampCreator(calcParameters); using (IOnlineLoggingData old = new OnlineLoggingData(dsc, wd.InputDataLogger, calcParameters)) { var coi = new CalcObjectInformation(CalcObjectType.ModularHousehold, "objname", wd.WorkingDirectory); wd.InputDataLogger.Save(coi); using (var lf = new LogFile(calcParameters, fft)) { var key = new HouseholdKey("hh1"); fft.RegisterHousehold(key, "hh1 key", HouseholdKeyType.Household, "Description", null, null); var odap = new OnlineDeviceActivationProcessor(old, calcParameters, fft); var clt = new CalcLoadType("lt1", "W", "kWh", 3, true, Guid.NewGuid().ToStrGuid()); var loadTypes = new List <CalcLoadTypeDto> { clt.ConvertToDto() }; wd.InputDataLogger.Save(loadTypes); var cdl = new CalcDeviceLoad("devload1", 10, clt, 666, 0); var deviceLoads = new List <CalcDeviceLoad> { cdl }; var cloc = new CalcLocation("locname", Guid.NewGuid().ToStrGuid()); var devguid = Guid.NewGuid().ToStrGuid(); var devcategoryguid = Guid.NewGuid().ToStrGuid(); var cdto = new CalcDeviceDto("devicename", devcategoryguid, key, OefcDeviceType.Device, "category", "", devguid, cloc.Guid, cloc.Name); var devices = new List <IHouseholdKey> { cdto }; wd.InputDataLogger.SaveList(devices); using (var calcRepo = new CalcRepo(odap, calcParameters: calcParameters, rnd: rnd, normalRandom: nr)) { var device = new CalcDevice(deviceLoads, cloc, cdto, calcRepo); //var devices = new List<CalcDevice> {device}; var cp = new CalcProfile("profile1", Guid.NewGuid().ToStrGuid(), new TimeSpan(0, 1, 0), ProfileType.Absolute, "custom"); cp.AddNewTimepoint(new TimeSpan(0), 0); cp.AddNewTimepoint(new TimeSpan(0, 1, 0), 10); cp.AddNewTimepoint(new TimeSpan(0, 2, 0), 0); cp.ConvertToTimesteps(); //var locations = new List<CalcLocation> {cloc}; var ts = new TimeStep(0, calcParameters); device.SetTimeprofile(cp, ts, clt, "affordanceName", "activatorName", 1, false); device.SetTimeprofile(cp, ts.AddSteps(5), clt, "affordanceName", "activatorName", 1, false); device.SetTimeprofile(cp.CompressExpandDoubleArray(0.5), ts.AddSteps(8), clt, "affordanceName", "activatorName", 1, false); device.SetTimeprofile(cp.CompressExpandDoubleArray(2), ts.AddSteps(10), clt, "affordanceName", "activatorName", 1, false); } for (var i = 0; i < 30; i++) { var ts1 = new TimeStep(i, calcParameters); var filerows = odap.ProcessOneTimestep(ts1); filerows.Count.Should().Be(1); filerows[0].EnergyEntries.Count.Should().Be(1); Logger.Info(filerows[0].EnergyEntries[0].ToString(CultureInfo.CurrentCulture)); foreach (var fileRow in filerows) { fileRow.Save(odap.BinaryOutStreams[fileRow.LoadType]); } } //var autoDevs = new List<CalcAutoDev>(); //var ps = new Postprocessor(lf.FileFactoryAndTracker, calculationProfiler,calcParameters); //var householdKeys = new HashSet<string> {"1"}; //var calcAffordanceTaggingSets = new List<CalcAffordanceTaggingSet>(); var deviceTaggingSetInformation = new DeviceTaggingSetInformation("name"); var taggingsets = new List <DeviceTaggingSetInformation> { deviceTaggingSetInformation }; wd.InputDataLogger.Save(taggingsets); //var householdPlans = new List<CalcHouseholdPlan>(); //var householdNamesByNumber = new Dictionary<string, string> {["HH1"] = "household"}; //var affordanceEnergyUseFile = new AffordanceEnergyUseFile(lf.FileFactoryAndTracker,calcParameters); //lf.Close(null); // needed to free file access //var results = new Dictionary<string, double>(); var persons = new List <CalcPersonDto>(); var dto = new CalcPersonDto("name", Guid.NewGuid().ToStrGuid(), 18, PermittedGender.Female, key, new List <DateSpan>(), new List <DateSpan>(), 1, "tag", "hhname"); persons.Add(dto); wd.InputDataLogger.SaveList(persons.ConvertAll(x => (IHouseholdKey)x)); //var deviceNamesToCategory = new Dictionary<string, string>(); old.FinalSaveToDatabase(); lf.Dispose(); fft.Dispose(); var cprof = new CalculationProfiler(); var ppm = new PostProcessingManager(cprof, fft); ppm.Run(wd.WorkingDirectory); var tel = new TotalsPerLoadtypeEntryLogger(wd.SqlResultLoggingService); var results = tel.Read(key); results[0].Value.Should().Be(150); } } } Logger.Info(wd.WorkingDirectory); wd.CleanUp(); } }
public void HouseJobForHouseTypes() { //setup Logger.Get().StartCollectingAllMessages(); using (DatabaseSetup db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { Simulator sim = new Simulator(db.ConnectionString); using (WorkingDir wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { var count = 0; foreach (var houseType in sim.HouseTypes.It) { count++; if (count < 22) { continue; } Logger.Info("================================================"); Logger.Info("================================================"); Logger.Info("================================================"); Logger.Info("Starting " + houseType.Name); Logger.Info("================================================"); Logger.Info("================================================"); Logger.Info("================================================"); Logger.Get().StartCollectingAllMessages(); string htcode = houseType.Name.Substring(0, 4); //housedata const int targetheatdemand = 10000; HouseData houseData = new HouseData(Guid.NewGuid().ToStrGuid(), htcode, targetheatdemand, 1000, "HouseGeneratorJobHouse"); HouseCreationAndCalculationJob houseJob = new HouseCreationAndCalculationJob("present", "2019", "trafokreis", HouseDefinitionType.HouseData); houseJob.House = houseData; houseJob.CalcSpec = new JsonCalcSpecification { DefaultForOutputFiles = OutputFileDefault.Reasonable, StartDate = new DateTime(2017, 1, 1), EndDate = new DateTime(2017, 12, 31), GeographicLocation = sim.GeographicLocations.FindFirstByName("Berlin", FindMode.Partial) ?.GetJsonReference() ?? throw new LPGException("No Berlin in the DB"), TemperatureProfile = sim.TemperatureProfiles[0].GetJsonReference(), OutputDirectory = wd.Combine("Results." + htcode), SkipExisting = false, CalcOptions = new List <CalcOption> { CalcOption.HouseSumProfilesFromDetailedDats, CalcOption.DeviceProfilesIndividualHouseholds, CalcOption.EnergyStorageFile, CalcOption.EnergyCarpetPlot, CalcOption.HouseholdContents, CalcOption.TotalsPerLoadtype }, DeleteDAT = false }; StartHouseJob(houseJob, wd, htcode); SqlResultLoggingService srls = new SqlResultLoggingService(houseJob.CalcSpec.OutputDirectory); HouseholdKeyLogger hhkslogger = new HouseholdKeyLogger(srls); var hhks = hhkslogger.Load(); TotalsPerLoadtypeEntryLogger tel = new TotalsPerLoadtypeEntryLogger(srls); foreach (var entry in hhks) { if (entry.KeyType == HouseholdKeyType.General) { continue; } Logger.Info(entry.HHKey.ToString()); var res = tel.Read(entry.HHKey); foreach (var totalsEntry in res) { Logger.Info(totalsEntry.Loadtype + ": " + totalsEntry.Value); if (totalsEntry.Loadtype.Name == "Space Heating") { if (Math.Abs(totalsEntry.Value - targetheatdemand) > 10) { throw new LPGException("Target heat demand didn't match for " + houseType.Name); } } } } } } } }