public void OnlineDeviceActivationProcessorSetToZeroTest() { var rnd = new Random(1); var nr = new NormalRandom(0, 1, rnd); var startdate = new DateTime(2018, 1, 1); var enddate = startdate.AddMinutes(100); var calcParameters = CalcParametersFactory.MakeGoodDefaults().SetStartDate(startdate).SetEndDate(enddate).EnableShowSettlingPeriod(); using (var wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { wd.InputDataLogger.AddSaver(new ColumnEntryLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new HouseholdKeyLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new ResultFileEntryLogger(wd.SqlResultLoggingService)); //calcParameters.Enable(CalcOption.ActionsLogfile); calcParameters.Enable(CalcOption.DeviceProfilesIndividualHouseholds); Config.ExtraUnitTestChecking = true; // calcProfile var profileWith100 = new CalcProfile("calcProfile", Guid.NewGuid().ToStrGuid(), new TimeSpan(0, 1, 0), ProfileType.Absolute, "blub"); profileWith100.AddNewTimepoint(new TimeSpan(0), 100); profileWith100.AddNewTimepoint(new TimeSpan(0, 5, 0), 100); profileWith100.ConvertToTimesteps(); var profileWith50 = new CalcProfile("calcProfile2", Guid.NewGuid().ToStrGuid(), new TimeSpan(0, 1, 0), ProfileType.Absolute, "blub"); profileWith50.AddNewTimepoint(new TimeSpan(0), 50); profileWith50.AddNewTimepoint(new TimeSpan(0, 3, 0), 50); profileWith50.ConvertToTimesteps(); // Loadtype var clt = new CalcLoadType("lt1", "W", "kWh", 1, true, Guid.NewGuid().ToStrGuid()); // Location var cloc = new CalcLocation("Location", Guid.NewGuid().ToStrGuid()); // devices var cdl = new CalcDeviceLoad("lt1", 100, clt, 100, 0); var loads = new List <CalcDeviceLoad>(); var results = new List <string> { "100;0;", "100;0;", "100;0;", "100;0;", "100;0;", "100;0;", "0;50;", "0;50;", "0;50;", "100;0;", "100;0;", "100;0;", "100;0;", "100;0;", "100;0;" }; loads.Add(cdl); using (var fft = new FileFactoryAndTracker(wd.WorkingDirectory, "hh1", wd.InputDataLogger)) { fft.RegisterHousehold(Constants.GeneralHouseholdKey, "general", HouseholdKeyType.General, "desc", null, null); //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 odap = new OnlineDeviceActivationProcessor(old, calcParameters, fft); using (var calcRepo = new CalcRepo(calcParameters: calcParameters, odap: odap, rnd: rnd, normalRandom: nr)) { var requirements = new List <VariableRequirement>(); var devCatGuid = Guid.NewGuid().ToStrGuid(); var key = new HouseholdKey("HH1"); var cddauto = new CalcDeviceDto("devicename", devCatGuid, key, OefcDeviceType.Device, "device category", " (autonomous)", Guid.NewGuid().ToStrGuid(), cloc.Guid, cloc.Name); var autodev = new CalcAutoDev(profileWith100, clt, loads, 0, 1, cloc, requirements, cddauto, calcRepo); var cdd = new CalcDeviceDto("devicename", devCatGuid, key, OefcDeviceType.Device, "device category", "", Guid.NewGuid().ToStrGuid(), cloc.Guid, cloc.Name); var device = new CalcDevice(loads, cloc, cdd, calcRepo); var autoDevs = new List <CalcAutoDev> { autodev }; var devices = new List <CalcDevice> { device }; CalcHousehold.MatchAutonomousDevicesWithNormalDevices(autoDevs, devices); if (device.MatchingAutoDevs.Count == 0) { throw new LPGException("Matching devices didn't work"); } foreach (var pair in odap.Oefc.ColumnEntriesByLoadTypeByDeviceKey) { Logger.Info(pair.Key.Name); foreach (var entry in pair.Value) { Logger.Info(entry.Key + " - " + entry.Value.Name); } } for (var i = 0; i < 15; i++) { var ts = new TimeStep(i, 0, true); if (!autodev.IsBusyDuringTimespan(ts, 1, 1, clt)) { autodev.Activate(ts); } if (i == 6) { device.SetTimeprofile(profileWith50, ts, clt, "blub", "Person", 1, false); } var filerows = odap.ProcessOneTimestep(ts); filerows.Count.Should().Be(1); filerows[0].EnergyEntries.Count.Should().Be(2); var entries = string.Empty; foreach (var d in filerows[0].EnergyEntries) { entries += d.ToString(CultureInfo.CurrentCulture) + ";"; } Logger.Info(entries); results[i].Should().Be(entries); } } } } } wd.CleanUp(); } }
public void CheckResultingProfile() { using var wd = new WorkingDir(Utili.GetCurrentMethodAndClass()); wd.InputDataLogger.AddSaver(new ColumnEntryLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new ResultFileEntryLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new HouseholdKeyLogger(wd.SqlResultLoggingService)); DateTime startdate = new DateTime(2018, 1, 1); DateTime enddate = startdate.AddMinutes(100); CalcParameters calculationParameters = CalcParametersFactory.MakeGoodDefaults().SetStartDate(startdate).SetEndDate(enddate).EnableShowSettlingPeriod(); var profile = new CalcProfile("profile", Guid.NewGuid().ToStrGuid(), new TimeSpan(0, 1, 0), ProfileType.Relative, "blub"); profile.AddNewTimepoint(new TimeSpan(0), 0.01); profile.AddNewTimepoint(new TimeSpan(1, 0, 0), 0.01); profile.ConvertToTimesteps(); var cloadtype = new CalcLoadType("loadtype", "power", "sum", 1, true, Guid.NewGuid().ToStrGuid()); var loads = new List <CalcDeviceLoad>(); var cdl = new CalcDeviceLoad("cdevload", 100, cloadtype, 100, 0.1); loads.Add(cdl); var r = new Random(5); HouseholdKey key = new HouseholdKey("hh1"); var nr = new NormalRandom(0, 1, r); using var fft = new FileFactoryAndTracker(wd.WorkingDirectory, "householdname", wd.InputDataLogger); fft.RegisterHousehold(key, "hh1", HouseholdKeyType.Household, "desc", null, null); fft.RegisterHousehold(Constants.GeneralHouseholdKey, "general", HouseholdKeyType.General, "desc", null, null); //SqlResultLoggingService srls = new SqlResultLoggingService(wd.WorkingDirectory); DateStampCreator dsc = new DateStampCreator(calculationParameters); using OnlineLoggingData old = new OnlineLoggingData(dsc, wd.InputDataLogger, calculationParameters); var odap = new OnlineDeviceActivationProcessor(old, calculationParameters, fft); using CalcRepo calcRepo = new CalcRepo(odap: odap, normalRandom: nr, calcParameters: calculationParameters); var location = new CalcLocation("calcloc", Guid.NewGuid().ToStrGuid()); CalcVariableRepository crv = new CalcVariableRepository(); var variableGuid = Guid.NewGuid().ToStrGuid(); CalcVariable cv = new CalcVariable("varname", variableGuid, 0, location.Name, location.Guid, key); crv.RegisterVariable(cv); VariableRequirement vreq = new VariableRequirement(cv.Name, 0, location.Name, location.Guid, VariableCondition.Equal, crv, variableGuid); List <VariableRequirement> requirements = new List <VariableRequirement> { vreq }; var deviceCategoryGuid = Guid.NewGuid().ToStrGuid(); CalcDeviceDto cdd = new CalcDeviceDto("autodevnamename", deviceCategoryGuid, key, OefcDeviceType.AutonomousDevice, "device category", "", Guid.NewGuid().ToStrGuid(), location.Guid, location.Name); var cad = new CalcAutoDev(profile, cloadtype, loads, 0.8, 1, location, requirements, cdd, calcRepo); for (var i = 0; i < 100; i++) { TimeStep ts = new TimeStep(i, calculationParameters); if (!cad.IsBusyDuringTimespan(ts, 1, 0.7, cloadtype)) { cad.Activate(ts); } var rows = odap.ProcessOneTimestep(ts); foreach (var energyFileRow in rows) { foreach (var energyEntry in energyFileRow.EnergyEntries) { Logger.Info(energyEntry.ToString(CultureInfo.CurrentCulture)); } } } }