public void CalcAffordanceVariableTestSet() { var deviceCategoryGuid = Guid.NewGuid().ToStrGuid(); //var r = new Random(0); //var nr = new NormalRandom(0, 0.1, r); const int stepcount = 150; Config.IsInUnitTesting = true; DateTime startdate = new DateTime(2018, 1, 1); DateTime enddate = startdate.AddMinutes(stepcount); //_calcParameters.InitializeTimeSteps(startdate, enddate, new TimeSpan(0, 1, 0), 3, false); CalcParameters calcParameters = CalcParametersFactory.MakeGoodDefaults().SetStartDate(startdate).SetEndDate(enddate); var timeStep = new TimeSpan(0, 1, 0); var cp = new CalcProfile("profile", Guid.NewGuid().ToStrGuid(), timeStep, ProfileType.Absolute, "blub"); cp.AddNewTimepoint(new TimeSpan(0), 100); cp.AddNewTimepoint(new TimeSpan(0, 10, 0), 0); cp.ConvertToTimesteps(); var variables = new List <CalcAffordanceVariableOp>(); var variableReqs = new List <VariableRequirement>(); var loc = new CalcLocation("loc", Guid.NewGuid().ToStrGuid()); CalcVariableRepository calcVariableRepository = new CalcVariableRepository(); var variableGuid = Guid.NewGuid().ToStrGuid(); HouseholdKey key = new HouseholdKey("hh1"); CalcVariable cv = new CalcVariable("varname", variableGuid, 0, loc.Name, loc.Guid, key); calcVariableRepository.RegisterVariable(cv); variables.Add(new CalcAffordanceVariableOp(cv.Name, 1, loc, VariableAction.SetTo, VariableExecutionTime.Beginning, variableGuid)); BitArray isBusy = new BitArray(100, false); Random rnd = new Random(); NormalRandom nr = new NormalRandom(0, 1, rnd); using CalcRepo calcRepo = new CalcRepo(calcParameters: calcParameters, odap: new Mock <IOnlineDeviceActivationProcessor>().Object, normalRandom: nr, rnd: rnd); var aff = new CalcAffordance("bla", cp, loc, false, new List <CalcDesire>(), 0, 99, PermittedGender.All, false, 0.1, new ColorRGB(0, 0, 0), "bla", false, false, variables, variableReqs, ActionAfterInterruption.GoBackToOld, "bla", 100, false, "", Guid.NewGuid().ToStrGuid(), calcVariableRepository, new List <CalcAffordance.DeviceEnergyProfileTuple>(), isBusy, BodilyActivityLevel.Low, calcRepo); var lt = new CalcLoadType("load", "unit1", "unit2", 1, true, Guid.NewGuid().ToStrGuid()); var cdl = new CalcDeviceLoad("cdl", 1, lt, 1, 0.1); var devloads = new List <CalcDeviceLoad> { cdl }; CalcDeviceDto cdd = new CalcDeviceDto("device", deviceCategoryGuid, key, OefcDeviceType.Device, "category", string.Empty, Guid.NewGuid().ToStrGuid(), loc.Guid, loc.Name); var cd = new CalcDevice(devloads, loc, cdd, calcRepo); //loc.Variables.Add("Variable1", 0); aff.AddDeviceTuple(cd, cp, lt, 0, timeStep, 10, 1); TimeStep ts = new TimeStep(0, 0, false); aff.IsBusy(ts, loc, "name"); //var variableOperator = new VariableOperator(); aff.Activate(ts, "blub", loc, out var _); calcVariableRepository.GetValueByGuid(variableGuid).Should().Be(1); }
protected static CalcProfile MakeCalcProfile5Min100() { var cp = new CalcProfile("5min100%", Guid.NewGuid().ToStrGuid(), new TimeSpan(0, 1, 0), ProfileType.Relative, "foo"); cp.AddNewTimepoint(new TimeSpan(0, 0, 0), 1); cp.AddNewTimepoint(new TimeSpan(0, 5, 0), 0); cp.ConvertToTimesteps(); return(cp); }
public void CalcProfileTest1MinPro1MinStep() { TimeSpan stepsize = new TimeSpan(0, 1, 0); CalcProfile cp = new CalcProfile("name", Guid.NewGuid().ToStrGuid(), stepsize, ProfileType.Absolute, "made up"); cp.AddNewTimepoint(new TimeSpan(0, 0, 0), 100); cp.AddNewTimepoint(new TimeSpan(0, 1, 0), 100); cp.ConvertToTimesteps(); cp.StepValues[0].Should().Be(100); cp.StepValues.Count.Should().Be(1); }
public static CalcProfile GetCalcProfile([NotNull] TimeBasedProfile timeBasedProfile, TimeSpan ts) { CalcProfile cp = new CalcProfile(timeBasedProfile.Name, Guid.NewGuid().ToStrGuid(), ts, (ProfileType)timeBasedProfile.TimeProfileType, timeBasedProfile.DataSource); foreach (var dp in timeBasedProfile.ObservableDatapoints) { cp.AddNewTimepoint(dp.Time, dp.Value); } cp.ConvertToTimesteps(); return(cp); }
public static CalcProfile MakeCalcProfile([NotNull] CalcProfileDto cpd, [NotNull] CalcParameters calcParameters) { CalcProfile cp = new CalcProfile(cpd.Name, cpd.Guid, calcParameters.InternalStepsize, cpd.ProfileType, cpd.DataSource); foreach (var dp in cpd.Datapoints) { cp.AddNewTimepoint(dp.Time, dp.Value); } cp.ConvertToTimesteps(); return(cp); }
public void CalcProfileTest30SPro1MinStep() { Config.IsInUnitTesting = true; TimeSpan stepsize = new TimeSpan(0, 1, 0); CalcProfile cp = new CalcProfile("name", Guid.NewGuid().ToStrGuid(), stepsize, ProfileType.Absolute, "made up"); cp.AddNewTimepoint(new TimeSpan(0, 0, 0), 100); cp.AddNewTimepoint(new TimeSpan(0, 0, 30), 50); cp.AddNewTimepoint(new TimeSpan(0, 1, 30), 0); cp.ConvertToTimesteps(); cp.StepValues.Count.Should().Be(2); cp.StepValues[0].Should().Be(75); cp.StepValues[1].Should().Be(25); }
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 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 PostProcessingTestSingleActivation() { using (var wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { wd.InputDataLogger.AddSaver(new CalcParameterLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new ColumnEntryLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new ResultFileEntryLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new DeviceActivationEntryLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new HouseholdKeyLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new CalcLoadTypeDtoLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new CalcPersonDtoLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new DeviceTaggingSetLogger(wd.SqlResultLoggingService)); var calculationProfiler = new CalculationProfiler(); var startdate = new DateTime(2018, 1, 1); var enddate = startdate.AddMinutes(1000); var calcParameters = CalcParametersFactory.MakeGoodDefaults().SetStartDate(startdate).SetEndDate(enddate).EnableShowSettlingPeriod(); var rnd = new Random(1); var nr = new NormalRandom(0, 1, rnd); calcParameters.Enable(CalcOption.HouseSumProfilesFromDetailedDats); calcParameters.Enable(CalcOption.DeviceProfilesIndividualHouseholds); calcParameters.Enable(CalcOption.TotalsPerDevice); calcParameters.Enable(CalcOption.TotalsPerLoadtype); calcParameters.Enable(CalcOption.DetailedDatFiles); calcParameters.Enable(CalcOption.DeviceActivations); var key = new HouseholdKey("hh1"); wd.InputDataLogger.Save(calcParameters); using (var fft = new FileFactoryAndTracker(wd.WorkingDirectory, "hhname", wd.InputDataLogger)) { //wd.InputDataLogger.AddSaver(new CalcDeviceDtoLogger(wd.SqlResultLoggingService)); var dsc = new DateStampCreator(calcParameters); using (IOnlineLoggingData old = new OnlineLoggingData(dsc, wd.InputDataLogger, calcParameters)) { var calcPersonDto = new CalcPersonDto("blub", "personguid".ToStrGuid(), 1, PermittedGender.Male, key, new List <DateSpan>(), new List <DateSpan>(), 1, "traittag", "householdname"); var persons = new List <CalcPersonDto> { calcPersonDto }; wd.InputDataLogger.SaveList(persons.ConvertAll(x => (IHouseholdKey)x)); using (var lf = new LogFile(calcParameters, fft)) { fft.RegisterHousehold(key, "test hh", HouseholdKeyType.Household, "Description", null, null); fft.RegisterHousehold(Constants.GeneralHouseholdKey, "General", HouseholdKeyType.General, "Description", null, null); var odap = new OnlineDeviceActivationProcessor(old, calcParameters, fft); var clt = new CalcLoadType("lt1", "W", "kWh", 3, true, Guid.NewGuid().ToStrGuid()); var loadTypeDtos = new List <CalcLoadTypeDto> { clt.ConvertToDto() }; wd.InputDataLogger.Save(loadTypeDtos); //var loadTypes = new List<CalcLoadType> {clt}; var cdl = new CalcDeviceLoad("devload1", 10, clt, 666, 0); var deviceLoads = new List <CalcDeviceLoad> { cdl }; var cloc = new CalcLocation("locname", Guid.NewGuid().ToStrGuid()); var deviceCategoryGuid = Guid.NewGuid().ToStrGuid(); var calcDeviceDto = new CalcDeviceDto("devicename", deviceCategoryGuid, key, OefcDeviceType.Device, "category", string.Empty, Guid.NewGuid().ToStrGuid(), cloc.Guid, cloc.Name); var calcDeviceDtos = new List <CalcDeviceDto> { calcDeviceDto }; wd.InputDataLogger.SaveList(calcDeviceDtos.ConvertAll(x => (IHouseholdKey)x)); //device tagging set for the post processing var cdts = new List <DeviceTaggingSetInformation>(); var dtsi = new DeviceTaggingSetInformation("myset"); dtsi.AddTag(calcDeviceDto.Name, "testTag "); cdts.Add(dtsi); wd.InputDataLogger.Save(cdts); //device using (var calcRepo = new CalcRepo(calcParameters: calcParameters, odap: odap, rnd: rnd, normalRandom: nr)) { var device = new CalcDevice(deviceLoads, cloc, calcDeviceDto, calcRepo); //var devices = new List<CalcDevice> {device}; double[] resultValues = { 0, 100.0, 0, 0, 0, 0, 0, 0, 0, 0 }; 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 ts1 = new TimeStep(0, calcParameters); device.SetTimeprofile(cp, ts1, clt, "affordanceName", "activatorName", 10, false); for (var i = 0; i < 10; i++) { var ts = new TimeStep(i, calcParameters); var filerows = odap.ProcessOneTimestep(ts); filerows.Count.Should().Be(1); filerows[0].EnergyEntries.Count.Should().Be(1); Logger.Info(filerows[0].EnergyEntries[0].ToString(CultureInfo.CurrentCulture)); filerows[0].EnergyEntries[0].Should().Be(resultValues[i]); foreach (var fileRow in filerows) { fileRow.Save(odap.BinaryOutStreams[fileRow.LoadType]); } } } old.FinalSaveToDatabase(); fft.Dispose(); lf.Dispose(); // needed to free the file access //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 calcDeviceTaggingSets = new List<CalcDeviceTaggingSet>(); //var calcDeviceTaggingSets = new List<DeviceTaggingSetInformation>(); //var householdPlans = new List<CalcHouseholdPlan>(); //var householdNamesByNumber = new Dictionary<string, string> {["HH1"] = "household"}; //var affordanceEnergyUseFile = new AffordanceEnergyUseFile(lf.FileFactoryAndTracker,calcParameters); //var results = new Dictionary<string, double>(); //BitArray isSick = new BitArray(calcParameters.InternalTimesteps); //BitArray isOnVacation = new BitArray(calcParameters.InternalTimesteps); //CalcPersonDto cpd = new CalcPersonDto("personname", Guid.NewGuid().ToStrGuid(),18,PermittedGender.Female,key,new List<DateSpan>(),new List<DateSpan>(),1,"traittag","hhname" ); //var persons = new List<CalcPerson> {new CalcPerson(cpd, new Random(), lf,cloc,calcParameters,isSick,isOnVacation)}; //var deviceNamesToCategory = new Dictionary<string, string>(); //CalcDeviceTaggingSets calcDeviceTaggingSets = new CalcDeviceTaggingSets(); var cpp = new PostProcessingManager(calculationProfiler, fft); cpp.Run(wd.WorkingDirectory); /*ps.EndOfSimulationProcessing(devices, locations, autoDevs, loadTypes, odap.Oefc, householdKeys * ,calcAffordanceTaggingSets, calcDeviceTaggingSets, householdPlans, householdNamesByNumber * ,affordanceEnergyUseFile, results, CalcObjectType.ModularHousehold, persons, deviceNamesToCategory,10);*/ //var dstpath = Path.Combine(wd.WorkingDirectory,DirectoryNames.CalculateTargetdirectory(TargetDirectory.Reports),"DeviceSums." + clt.Name + ".csv"); lf.Dispose(); // needed to free the file access var di = new DirectoryInfo(wd.WorkingDirectory); var fis = di.GetFiles("DeviceSums.*", SearchOption.AllDirectories); if (fis.Length == 0) { throw new LPGException("No Sum File was generated"); } fft.Dispose(); using (var sr = new StreamReader(fis[0].FullName)) { sr.ReadLine(); //header var result = sr.ReadLine(); //0 if (result == null) { throw new LPGException("Result was null"); } var arr = result.Split(';'); Assert.Equal("300", arr[1]); } } } } Logger.Info(wd.WorkingDirectory); 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)); } } } }
public void RunDeviceOffsetTest() { //var r = new Random(0); //var nr = new NormalRandom(0, 0.1, r); const int stepcount = 150; var devCategoryGuid = Guid.NewGuid().ToStrGuid(); Config.IsInUnitTesting = true; DateTime startdate = new DateTime(2018, 1, 1); DateTime enddate = startdate.AddMinutes(stepcount); CalcParameters calcParameters = CalcParametersFactory.MakeGoodDefaults().SetStartDate(startdate).SetEndDate(enddate); var timeStep = new TimeSpan(0, 1, 0); var cp = new CalcProfile("profile", Guid.NewGuid().ToStrGuid(), timeStep, ProfileType.Absolute, "blub"); cp.AddNewTimepoint(new TimeSpan(0), 100); cp.AddNewTimepoint(new TimeSpan(0, 10, 0), 0); cp.ConvertToTimesteps(); var loc = new CalcLocation(Utili.GetCurrentMethodAndClass(), Guid.NewGuid().ToStrGuid()); CalcVariableRepository crv = new CalcVariableRepository(); BitArray isBusy = new BitArray(calcParameters.InternalTimesteps, false); Random rnd = new Random(); NormalRandom nr = new NormalRandom(0, 1, rnd); using CalcRepo calcRepo = new CalcRepo(calcParameters: calcParameters, odap: new Mock <IOnlineDeviceActivationProcessor>().Object, rnd: rnd, normalRandom: nr); var aff = new CalcAffordance("bla", cp, loc, false, new List <CalcDesire>(), 0, 99, PermittedGender.All, false, 0, new ColorRGB(0, 0, 0), "bla", false, false, new List <CalcAffordanceVariableOp>(), new List <VariableRequirement>(), ActionAfterInterruption.GoBackToOld, "bla", 100, false, "", Guid.NewGuid().ToStrGuid(), crv, new List <CalcAffordance.DeviceEnergyProfileTuple>(), isBusy, BodilyActivityLevel.Low, calcRepo); var lt = new CalcLoadType("load", "unit1", "unit2", 1, true, Guid.NewGuid().ToStrGuid()); var cdl = new CalcDeviceLoad("cdl", 1, lt, 1, 0.1); //var variableOperator = new VariableOperator(); var devloads = new List <CalcDeviceLoad> { cdl }; HouseholdKey key = new HouseholdKey("HH1"); CalcDeviceDto cdd = new CalcDeviceDto("device", devCategoryGuid, key, OefcDeviceType.Device, "category", string.Empty, Guid.NewGuid().ToStrGuid(), loc.Guid, loc.Name); var cd = new CalcDevice(devloads, loc, cdd, calcRepo); aff.AddDeviceTuple(cd, cp, lt, 20, timeStep, 10, 1); //bool result = aff.IsBusy(0, nr, r, loc); //(result).Should().BeFalse(); CheckForBusyness(loc, aff, cd, lt); TimeStep ts = new TimeStep(0, 0, false); aff.Activate(ts.AddSteps(10), "blub", loc, out var _); CheckForBusyness(loc, aff, cd, lt); aff.IsBusy(ts.AddSteps(1), loc, "name", false).Should().BeTrue(); aff.IsBusy(ts.AddSteps(19), loc, "name", false).Should().BeTrue(); aff.IsBusy(ts, loc, "name", false).Should().BeFalse(); aff.IsBusy(ts.AddSteps(20), loc, "name", false).Should().BeFalse(); }
private static void SetupProbabilityTest([NotNull] out CalcAffordance aff, [NotNull] out CalcLoadType lt, [NotNull] out CalcDevice cd, [NotNull] out CalcLocation loc, int stepcount, double probability) { Config.IsInUnitTesting = true; DateTime startdate = new DateTime(2018, 1, 1); DateTime enddate = startdate.AddMinutes(stepcount); CalcParameters calcParameters = CalcParametersFactory.MakeGoodDefaults().SetStartDate(startdate).SetEndDate(enddate); var timeStep = new TimeSpan(0, 1, 0); var cp = new CalcProfile("profile", Guid.NewGuid().ToStrGuid(), timeStep, ProfileType.Absolute, "blub"); cp.AddNewTimepoint(new TimeSpan(0), 100); cp.AddNewTimepoint(new TimeSpan(0, 10, 0), 0); cp.ConvertToTimesteps(); loc = new CalcLocation(Utili.GetCurrentMethodAndClass(), Guid.NewGuid().ToStrGuid()); CalcVariableRepository cvr = new CalcVariableRepository(); BitArray isBusy = new BitArray(100, false); var r = new Random(0); var nr = new NormalRandom(0, 0.1, r); IMock <IOnlineDeviceActivationProcessor> iodap = new Mock <IOnlineDeviceActivationProcessor>(); using CalcRepo calcRepo = new CalcRepo(calcParameters: calcParameters, normalRandom: nr, rnd: r, odap: iodap.Object); aff = new CalcAffordance("bla", cp, loc, false, new List <CalcDesire>(), 0, 99, PermittedGender.All, false, 0.1, new ColorRGB(0, 0, 0), "bla", false, false, new List <CalcAffordanceVariableOp>(), new List <VariableRequirement>(), ActionAfterInterruption.GoBackToOld, "bla", 100, false, "", Guid.NewGuid().ToStrGuid(), cvr, new List <CalcAffordance.DeviceEnergyProfileTuple>(), isBusy, BodilyActivityLevel.Low, calcRepo); lt = new CalcLoadType("load", "unit1", "unit2", 1, true, Guid.NewGuid().ToStrGuid()); var cdl = new CalcDeviceLoad("cdl", 1, lt, 1, 0.1); var devloads = new List <CalcDeviceLoad> { cdl }; CalcDeviceDto cdd = new CalcDeviceDto("device", "devcategoryguid".ToStrGuid(), new HouseholdKey("HH1"), OefcDeviceType.Device, "category", string.Empty, Guid.NewGuid().ToStrGuid(), loc.Guid, loc.Name); cd = new CalcDevice(devloads, loc, cdd, calcRepo); aff.AddDeviceTuple(cd, cp, lt, 0, timeStep, 10, probability); }