private List <CalcAutoDev> MakeCalcAutoDevsFromHouse([NotNull] CalcHouseDto house, [NotNull][ItemNotNull] List <CalcLocation> houseLocations) { var autodevs = new List <CalcAutoDev>(house.AutoDevs.Count); // zur kategorien zuordnung foreach (var hhautodev in house.AutoDevs) { CalcProfile calcProfile = CalcDeviceFactory.MakeCalcProfile(hhautodev.CalcProfile, _calcRepo.CalcParameters); CalcLoadType clt = _ltDict.GetLoadtypeByGuid(hhautodev.LoadtypeGuid); List <CalcDeviceLoad> loads = new List <CalcDeviceLoad>(); foreach (CalcDeviceLoadDto loadDto in hhautodev.Loads) { CalcDeviceLoad load = new CalcDeviceLoad(loadDto.Name, loadDto.MaxPower, _ltDict.GetLoadtypeByGuid(loadDto.LoadTypeGuid), loadDto.AverageYearlyConsumption, loadDto.PowerStandardDeviation); loads.Add(load); } List <VariableRequirement> requirements = new List <VariableRequirement>(); foreach (var reqDto in hhautodev.Requirements) { VariableRequirement rq = new VariableRequirement(reqDto.Name, reqDto.Value, reqDto.CalcLocationName, reqDto.LocationGuid, reqDto.VariableCondition, _variableRepository, reqDto.VariableGuid); requirements.Add(rq); } CalcLocation houseLocation = houseLocations.Single(x => x.Guid == hhautodev.CalcLocationGuid); var cautodev = new CalcAutoDev( calcProfile, clt, loads, hhautodev.TimeStandardDeviation, hhautodev.Multiplier, houseLocation, requirements, hhautodev, _calcRepo); var busyarr = _availabilityDtoRepository.GetByGuid(hhautodev.BusyArr.Guid); cautodev.ApplyBitArry(busyarr, _ltDict.GetLoadtypeByGuid(hhautodev.LoadtypeGuid)); autodevs.Add(cautodev); } return(autodevs); }
public List <CalcAutoDev> MakeCalcAutoDevs( [NotNull][ItemNotNull] List <CalcAutoDevDto> autoDevices, [NotNull] DtoCalcLocationDict locationDict) { var autodevs = new List <CalcAutoDev>(autoDevices.Count); foreach (var autoDevDto in autoDevices) { if (_loadTypeDictionary.SimulateLoadtype(autoDevDto.LoadtypeGuid)) { var deviceLoads = MakeCalcDeviceLoads(autoDevDto, _loadTypeDictionary); CalcProfile cp = MakeCalcProfile(autoDevDto.CalcProfile, _calcRepo.CalcParameters); var loadtype = _loadTypeDictionary.GetLoadtypeByGuid(autoDevDto.LoadtypeGuid); CalcLocation calcLocation = locationDict.GetCalcLocationByGuid(autoDevDto.CalcLocationGuid); List <VariableRequirement> requirements = new List <VariableRequirement>(); foreach (var req in autoDevDto.Requirements) { VariableRequirement vreq = new VariableRequirement(req.Name, req.Value, req.CalcLocationName, req.LocationGuid, req.VariableCondition, _calcVariableRepository, req.VariableGuid); requirements.Add(vreq); } autoDevDto.AdditionalName = " (autonomous)"; var cautodev = new CalcAutoDev(cp, loadtype, deviceLoads, autoDevDto.TimeStandardDeviation, 1, calcLocation, requirements, autoDevDto, _calcRepo); var busyarr = _availabilityDtoRepository.GetByGuid(autoDevDto.BusyArr.Guid); cautodev.ApplyBitArry(busyarr, loadtype); autodevs.Add(cautodev); } } return(autodevs); }
public void MatchAutonomousDevicesWithNormalDevicesTest() { // make different devices at different locations // only a single one should be matched. var startdate = new DateTime(2018, 1, 1); var enddate = startdate.AddMinutes(100); var calcParameters = CalcParametersFactory.MakeGoodDefaults().SetStartDate(startdate).SetEndDate(enddate); //_calcParameters.InitializeTimeSteps(startdate, enddate, new TimeSpan(0, 1, 0), 3, false); Config.IsInUnitTesting = true; var cloc1 = new CalcLocation("loc1", Guid.NewGuid().ToStrGuid()); var cloc2 = new CalcLocation("loc1", Guid.NewGuid().ToStrGuid()); var cdevload = new List <CalcDeviceLoad>(); var clt = new CalcLoadType("calcloadtype", "power", "sum", 1, true, Guid.NewGuid().ToStrGuid()); cdevload.Add(new CalcDeviceLoad("load", 100, clt, 0, 0)); var devCategoryGuid = Guid.NewGuid().ToStrGuid(); IMock <IOnlineDeviceActivationProcessor> iodap = new Mock <IOnlineDeviceActivationProcessor>(); using (var calcRepo = new CalcRepo(iodap.Object, calcParameters: calcParameters)) { var cdd1 = new CalcDeviceDto("cdevice1", devCategoryGuid, new HouseholdKey("HH1"), OefcDeviceType.Device, "category", "", Guid.NewGuid().ToStrGuid(), cloc1.Guid, cloc1.Name); var cdLoc1 = new CalcDevice(new List <CalcDeviceLoad>(), cloc1, cdd1, calcRepo); var cdd2 = new CalcDeviceDto("cdevice1", devCategoryGuid, new HouseholdKey("HH1"), OefcDeviceType.Device, "category", "", Guid.NewGuid().ToStrGuid(), cloc1.Guid, cloc1.Name); var cdLoc1B = new CalcDevice(new List <CalcDeviceLoad>(), cloc1, cdd2, calcRepo); var cdd3 = new CalcDeviceDto("cdevice1", devCategoryGuid, new HouseholdKey("HH1"), OefcDeviceType.Device, "category", "", Guid.NewGuid().ToStrGuid(), cloc2.Guid, cloc2.Name); var cdLoc2 = new CalcDevice(new List <CalcDeviceLoad>(), cloc2, cdd3, calcRepo); var cp = new CalcProfile("cp1", Guid.NewGuid().ToStrGuid(), TimeSpan.FromMilliseconds(1), ProfileType.Absolute, "blub"); //CalcVariableRepository crv = new CalcVariableRepository(); //VariableRequirement vr = new VariableRequirement(""); var requirements = new List <VariableRequirement>(); var cdd4 = new CalcDeviceDto("cdevice1", devCategoryGuid, new HouseholdKey("HH1"), OefcDeviceType.Device, "category", "", Guid.NewGuid().ToStrGuid(), cloc1.Guid, cloc1.Name); var cadLoc1 = new CalcAutoDev(cp, clt, cdevload, 0, 1, cloc1, requirements, cdd4, calcRepo); var autodevs = new List <CalcAutoDev> { cadLoc1 }; var normalDevices = new List <CalcDevice> { cdLoc1, cdLoc1B, cdLoc2 }; CalcHousehold.MatchAutonomousDevicesWithNormalDevices(autodevs, normalDevices); //var totalmatchcount = 0; foreach (var device in normalDevices) { Logger.Info(device.Name); foreach (var matchingAutoDev in device.MatchingAutoDevs) { // totalmatchcount++; Logger.Info("\t" + matchingAutoDev.Name); } } cdLoc1.MatchingAutoDevs.Count.Should().Be(1); } //(totalmatchcount).Should().Be(1); }
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)); } } } }