public void OnlineDeviceActivationProcessorArrayTest() { var rnd = new Random(1); var nr = new NormalRandom(0, 1, rnd); 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)); var calcParameters = CalcParametersFactory.MakeGoodDefaults().EnableShowSettlingPeriod(); //calcParameters.Enable(CalcOption.ActionsLogfile); calcParameters.Enable(CalcOption.DeviceProfilesIndividualHouseholds); calcParameters.Enable(CalcOption.DetailedDatFiles); using (var fft = new FileFactoryAndTracker(wd.WorkingDirectory, "hh1", wd.InputDataLogger)) { //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 hhkey = new HouseholdKey("HH1"); fft.RegisterHousehold(Constants.GeneralHouseholdKey, "generalhousehold", HouseholdKeyType.General, "Description", null, null); fft.RegisterHousehold(hhkey, "hh1", HouseholdKeyType.Household, "Description", null, null); var odap = new OnlineDeviceActivationProcessor(old, calcParameters, fft); var deviceGuid = "devguid".ToStrGuid(); var locationGuid = "locationGuid".ToStrGuid(); var loadtypeGuid = "ltguid".ToStrGuid(); var cdd = new CalcDeviceDto("devicename", "devcatguid".ToStrGuid(), hhkey, OefcDeviceType.Device, "devcatname", "", deviceGuid, locationGuid, "loc"); var key = new OefcKey(cdd, loadtypeGuid); var clt = new CalcLoadType("lt1", "W", "kWh", 1, true, loadtypeGuid); odap.RegisterDevice(clt.ConvertToDto(), cdd); double[] stepValues = { 1.0, 0 }; var valueList = new List <double>(stepValues); var cp = new CalcProfile("myCalcProfile", Guid.NewGuid().ToStrGuid(), valueList, ProfileType.Absolute, "synthetic"); var ts1 = new TimeStep(1, 0, false); var cdl = new CalcDeviceLoad("", 1, clt, 0, 0); var sv = StepValues.MakeStepValues(cp, 10, RandomValueProfile.MakeStepValues(cp.StepValues.Count, nr, 0), cdl); odap.AddNewStateMachine(ts1, clt.ConvertToDto(), "name1", "p1", key, cdd, sv); double[] resultValues = { 0, 10.0, 0, 0, 0, 0, 0, 0, 0, 0 }; for (var i = 0; i < 10; i++) { var ts = new TimeStep(i, 0, true); 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)); resultValues[i].Should().Be(filerows[0].EnergyEntries[0]); foreach (var fileRow in filerows) { fileRow.Save(odap.BinaryOutStreams[fileRow.LoadType]); } } } } Logger.Info(wd.WorkingDirectory); wd.CleanUp(); } }
public void CompressExpandDoubleArrayExpand3ShouldWork() { double[] tmparr = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; //List<double> tmplist = new List<double>(tmparr); //List<double> result = CalcProfile.CompressExpandDoubleArray(tmplist, 1.1); var cp = new CalcProfile("bla", Guid.NewGuid().ToStrGuid(), tmparr.ToList(), ProfileType.Absolute, "bla"); var result = cp.CompressExpandDoubleArray(1.5); foreach (double resultStepValue in result.StepValues) { Logger.Info(resultStepValue.ToString(CultureInfo.InvariantCulture)); } result.StepValues.Count.Should().Be(15); result.StepValues[0].Should().Be(0); result.StepValues[1].Should().Be(1); result.StepValues[2].Should().Be(1); result.StepValues[3].Should().Be(2); result.StepValues[4].Should().Be(3); result.StepValues[5].Should().Be(3); result.StepValues[6].Should().Be(4); result.StepValues[7].Should().Be(5); result.StepValues[8].Should().Be(5); result.StepValues[9].Should().Be(6); result.StepValues[10].Should().Be(7); result.StepValues[11].Should().Be(7); result.StepValues[12].Should().Be(8); result.StepValues[13].Should().Be(9); result.StepValues[14].Should().Be(9); }
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); }
public void PickRandomAffordanceFromEquallyAttractiveOnesTest() { using (var wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { CalcParameters calcParameters = CalcParametersFactory.MakeGoodDefaults(); calcParameters.AffordanceRepetitionCount = 0; wd.InputDataLogger.AddSaver(new HouseholdKeyLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new ResultFileEntryLogger(wd.SqlResultLoggingService)); using (var fft = new FileFactoryAndTracker(wd.WorkingDirectory, "blub", wd.InputDataLogger)) { fft.RegisterHousehold(Constants.GeneralHouseholdKey, "general", HouseholdKeyType.General, "desc", null, null); //SqlResultLoggingService srls = new SqlResultLoggingService(wd.WorkingDirectory); //DateStampCreator dsc = new DateStampCreator(calcParameters); Random rnd = new Random(); //OnlineLoggingData old = new OnlineLoggingData(dsc, wd.InputDataLogger, calcParameters); using (var lf = new LogFile(calcParameters, fft)) { CalcProfile cp = new CalcProfile("cp1", Guid.NewGuid().ToStrGuid(), TimeSpan.FromMinutes(1), ProfileType.Absolute, "bla"); CalcVariableRepository crv = new CalcVariableRepository(); BitArray isBusy = new BitArray(calcParameters.InternalTimesteps, false); using CalcRepo calcRepo = new CalcRepo(lf: lf, calcParameters: calcParameters, rnd: rnd); CalcAffordance aff1 = new CalcAffordance("aff1", cp, null, false, new List <CalcDesire>(), 10, 20, PermittedGender.All, true, 1, LPGColors.AliceBlue, null, false, false, null, null, ActionAfterInterruption.GoBackToOld, "", 900, false, "", Guid.NewGuid().ToStrGuid(), crv, new List <CalcAffordance.DeviceEnergyProfileTuple>(), isBusy, BodilyActivityLevel.Low, calcRepo); CalcAffordance aff2 = new CalcAffordance("aff2", cp, null, false, new List <CalcDesire>(), 10, 20, PermittedGender.All, true, 1, LPGColors.AliceBlue, null, false, false, null, null, ActionAfterInterruption.GoBackToOld, "", 100, false, "", Guid.NewGuid().ToStrGuid(), crv, new List <CalcAffordance.DeviceEnergyProfileTuple>(), isBusy, BodilyActivityLevel.Low, calcRepo); List <ICalcAffordanceBase> affs = new List <ICalcAffordanceBase> { aff1, aff2 }; int aff1C = 0; int aff2C = 0; BitArray isSick = new BitArray(calcParameters.InternalTimesteps); BitArray isOnVacation = new BitArray(calcParameters.InternalTimesteps); CalcPersonDto calcPerson = CalcPersonDto.MakeExamplePerson(); CalcPerson cperson = new CalcPerson(calcPerson, null, isSick, isOnVacation, calcRepo); TimeStep ts = new TimeStep(1, 0, true); for (int i = 0; i < 1000; i++) { ICalcAffordanceBase cab = cperson.PickRandomAffordanceFromEquallyAttractiveOnes(affs, ts, null, new HouseholdKey("bla")); if (cab == aff1) { aff1C++; } if (cab == aff2) { aff2C++; } } aff1C.Should().BeApproximatelyWithinPercent(900, 0.1); Logger.Info("Number of selections for 90%:" + aff1C + ", 10%:" + aff2C); } } wd.CleanUp(); } }
public void SetAllAffordaces([NotNull][ItemNotNull] List <CalcAffordanceDto> affordances, [NotNull] DtoCalcLocationDict locations, [NotNull] CalcVariableRepository variableRepository, [ItemNotNull][NotNull] List <CalcDevice> devices) { if (affordances.Count == 0) { throw new LPGException("No Affordances found."); } foreach (CalcAffordanceDto affordancedto in affordances) { CalcProfile personProfile = CalcDeviceFactory.MakeCalcProfile(affordancedto.PersonProfile, _calcRepo.CalcParameters); CalcLocation calcLocation = locations.GetCalcLocationByGuid(affordancedto.CalcLocationGuid); var calcDesires = MakeCalcDesires(affordancedto.Satisfactionvalues); var color = new ColorRGB(affordancedto.ColorR, affordancedto.ColorG, affordancedto.ColorB); var variableOps = MakeVariableOps(locations, affordancedto.VariableOps, variableRepository); List <VariableRequirement> requirements = new List <VariableRequirement>(); foreach (VariableRequirementDto requirementDto in affordancedto.VariableRequirements) { VariableRequirement vrq = new VariableRequirement(requirementDto.Name, requirementDto.Value, requirementDto.CalcLocationName, requirementDto.LocationGuid, requirementDto.VariableCondition, variableRepository, requirementDto.VariableGuid); requirements.Add(vrq); } var deviceEnergyProfiles = MakeDeviceEnergyProfileTuples(devices, affordancedto); var busyarr = _availabilityDtoRepository.GetByGuid(affordancedto.IsBusyArray.Guid); CalcAffordance caff = new CalcAffordance( affordancedto.Name, personProfile, calcLocation, affordancedto.RandomEffect, calcDesires, affordancedto.MiniumAge, affordancedto.MaximumAge, affordancedto.PermittedGender, affordancedto.NeedsLight, affordancedto.TimeStandardDeviation, color, affordancedto.AffCategory, affordancedto.IsInterruptable, affordancedto.IsInterrupting, variableOps, requirements, affordancedto.ActionAfterInterruption, affordancedto.TimeLimitName, affordancedto.Weight, affordancedto.RequireAllDesires, affordancedto.SrcTrait, affordancedto.Guid, variableRepository, deviceEnergyProfiles, busyarr, affordancedto.BodilyActivityLevel, _calcRepo); MakeSubAffordances(locations, variableRepository, affordancedto, caff); calcLocation.AddAffordance(caff); } }
public void ProcessOneTimestepTestVariableFactor() { var calcParameters = CalcParametersFactory.MakeGoodDefaults(); using var wd = new WorkingDir(Utili.GetCurrentMethodAndClass()); wd.InputDataLogger.AddSaver(new ResultFileEntryLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new HouseholdKeyLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new ColumnEntryLogger(wd.SqlResultLoggingService)); using var fft = new FileFactoryAndTracker(wd.WorkingDirectory, "name", wd.InputDataLogger); fft.RegisterGeneralHouse(); using var old = new OnlineLoggingData(new DateStampCreator(calcParameters), wd.InputDataLogger, calcParameters); var odap = new OnlineDeviceActivationProcessor(old, calcParameters, fft); var clt = new CalcLoadType("clt1", "W", "kWh", 1, true, Guid.NewGuid().ToStrGuid()); var devguid = Guid.NewGuid().ToStrGuid(); var locguid = Guid.NewGuid().ToStrGuid(); var cdd = new CalcDeviceDto("dev1", "devcatguid".ToStrGuid(), new HouseholdKey("HH1"), OefcDeviceType.Device, "devcatname", "", devguid, locguid, "loc"); var key = new OefcKey(cdd, clt.Guid); odap.RegisterDevice(clt.ConvertToDto(), cdd); double[] timestepValues = { 0, 5, 10.0, 20, 30, 40, 0 }; var cp = new CalcProfile("myCalcProfile", Guid.NewGuid().ToStrGuid(), timestepValues.ToList(), ProfileType.Absolute, "synthetic"); var ts1 = new TimeStep(1, 0, true); CalcDeviceLoad cdl = new CalcDeviceLoad("", 1, clt, 0, 0); var sv = StepValues.MakeStepValues(cp, 1, RandomValueProfile.MakeStepValues(cp.StepValues.Count, NormalRandom, 0), cdl); odap.AddNewStateMachine(ts1, clt.ConvertToDto(), "name1", "p1", key, cdd, sv); double[] resultValues = { 0, 0, 5, 10.0, 20, 30, 40, 0 }; //double[] resultValuesRow1 = {0, 0, 5, 10, 200, 3000, 4000, 0}; var ctd = new CalcTransformationDevice(odap, -1, 080, -1000, 1000, cdd, clt); var clt2 = new CalcLoadType("clt2", "W2", "kWh2", 1, true, Guid.NewGuid().ToStrGuid()); ctd.AddOutputLoadType(clt2, 2, TransformationOutputFactorType.Interpolated); ctd.AddDatapoint(10, 1); ctd.AddDatapoint(20, 10); ctd.AddDatapoint(30, 100); for (var i = 0; i < resultValues.Length; i++) { var ts = new TimeStep(i, calcParameters); var filerows = odap.ProcessOneTimestep(ts); filerows.Count.Should().Be(2); filerows[0].EnergyEntries.Count.Should().Be(1); var sb = new StringBuilder("row0 before:"); sb.Append(filerows[0].EnergyEntries[0]); sb.Append(" row1 before:"); sb.Append(filerows[1].EnergyEntries[0]); Assert.Equal(resultValues[i], filerows[0].EnergyEntries[0]); Assert.Equal(0, filerows[1].EnergyEntries[0]); ctd.ProcessOneTimestep(filerows, null); //(filerows[1].EnergyEntries[0]).Should().Be(resultValuesRow1[i]); sb.Append(" row0 after:"); sb.Append(filerows[0].EnergyEntries[0]); sb.Append(" row1 after:"); sb.Append(filerows[1].EnergyEntries[0]); Logger.Info(Utili.GetCurrentMethodAndClass() + " " + sb); } }
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 OnlineDeviceStateMachineTest() { var startdate = new DateTime(2018, 1, 1); var enddate = startdate.AddMinutes(200); CalcParameters calcParameters = CalcParametersFactory.MakeGoodDefaults() .SetStartDate(startdate).SetEndDate(enddate).SetSettlingDays(0).EnableShowSettlingPeriod(); var values = new double[10]; for (var i = 0; i < values.Length; i++) { values[i] = i + 1; Logger.Info(values[i].ToString(CultureInfo.CurrentCulture)); } var valueList = new List <double>(values); var r = new Random(1); var nr = new NormalRandom(0, 1, r); var devGuid = Guid.NewGuid().ToStrGuid(); var locGuid = Guid.NewGuid().ToStrGuid(); var clt = new CalcLoadType("lt", "kWh", "W", 1, true, Guid.NewGuid().ToStrGuid()); var calcDeviceDto = new CalcDeviceDto("device", devGuid, new HouseholdKey("hh1"), OefcDeviceType.Device, "mycategory", "", devGuid, locGuid, "locname"); var key = new OefcKey(calcDeviceDto, locGuid); var cp = new CalcProfile("mycalcprofile", Guid.NewGuid().ToStrGuid(), valueList, ProfileType.Absolute, "bla"); TimeStep ts = new TimeStep(5, 0, false); CalcDeviceLoad cdl = new CalcDeviceLoad("", 1, clt, 0, 0); StepValues sv = StepValues.MakeStepValues(cp, 1, RandomValueProfile.MakeStepValues(cp.StepValues.Count, nr, 0), cdl); var odsm = new OnlineDeviceStateMachine(ts, clt.ConvertToDto(), "device", key, "affordance", calcParameters, sv, 0); calcParameters.SetDummyTimeSteps(0); odsm.CalculateOfficialEnergyUse().Should().Be(55); // all calcParameters.SetDummyTimeSteps(6); odsm.CalculateOfficialEnergyUse().Should().Be(54); // not the first //_calcParameters.InternalTimesteps = 20; calcParameters.SetDummyTimeSteps(15); odsm.CalculateOfficialEnergyUse().Should().Be(0); // none calcParameters.SetDummyTimeSteps(14); odsm.CalculateOfficialEnergyUse().Should().Be(10); // only the last Logger.Info(odsm.CalculateOfficialEnergyUse().ToString(CultureInfo.CurrentCulture)); startdate = new DateTime(2018, 1, 1); enddate = startdate.AddMinutes(10); calcParameters.DisableShowSettlingPeriod(); calcParameters.SetStartDate(startdate).SetEndDate(enddate) .SetDummyTimeSteps(5); odsm.CalculateOfficialEnergyUse().Should().Be(15); // only the first 5 //_calcParameters.InternalTimesteps = 10; // only 5 calcParameters.SetDummyTimeSteps(9); var val = odsm.CalculateOfficialEnergyUse(); val.Should().Be(5); // only #5 Logger.Info(odsm.CalculateOfficialEnergyUse().ToString(CultureInfo.CurrentCulture)); }
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 void SetTimeprofileTest() { DateTime startdate = new DateTime(2018, 1, 1); DateTime enddate = startdate.AddMinutes(10); CalcParameters calcParameters = CalcParametersFactory.MakeGoodDefaults().SetStartDate(startdate).SetEndDate(enddate); CalcLoadType clt = MakeCalcLoadType(); CalcLocation cloc = new CalcLocation("blub", Guid.NewGuid().ToStrGuid()); CalcDeviceLoad cdl = new CalcDeviceLoad("cdl1", 1, clt, 1, 0.1); List <CalcDeviceLoad> cdls = new List <CalcDeviceLoad>(); using (WorkingDir 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)); using (FileFactoryAndTracker fft = new FileFactoryAndTracker(wd.WorkingDirectory, "hh1", wd.InputDataLogger)) { fft.RegisterHousehold(Constants.GeneralHouseholdKey, "General", HouseholdKeyType.General, "desc", null, null); //SqlResultLoggingService srls = new SqlResultLoggingService(wd.WorkingDirectory); DateStampCreator dsc = new DateStampCreator(calcParameters); using (IOnlineLoggingData old = new OnlineLoggingData(dsc, wd.InputDataLogger, calcParameters)) { cdls.Add(cdl); OnlineDeviceActivationProcessor odap = new OnlineDeviceActivationProcessor(old, calcParameters, fft); var deviceCategoryGuid = Guid.NewGuid().ToStrGuid(); CalcDeviceDto cdd = new CalcDeviceDto("bla", deviceCategoryGuid , new HouseholdKey("HH-6"), OefcDeviceType.Device, "category", string.Empty, Guid.NewGuid().ToStrGuid(), cloc.Guid, cloc.Name); using CalcRepo calcRepo = new CalcRepo(odap: odap, calcParameters: calcParameters, normalRandom: NormalRandom); CalcDevice cd = new CalcDevice(cdls, cloc, cdd, calcRepo); CalcProfile cp = MakeCalcProfile5Min100(); TimeStep ts1 = new TimeStep(1, calcParameters); cd.SetAllLoadTypesToTimeprofile(cp, ts1, "test", "name1", 1); TimeStep ts = new TimeStep(0, calcParameters); cd.IsBusyDuringTimespan(ts, 1, 1, clt).Should().BeFalse(); cd.IsBusyDuringTimespan(ts.AddSteps(1), 1, 1, clt).Should().BeTrue(); cd.IsBusyDuringTimespan(ts.AddSteps(2), 1, 1, clt).Should().BeTrue(); cd.IsBusyDuringTimespan(ts.AddSteps(3), 1, 1, clt).Should().BeTrue(); cd.IsBusyDuringTimespan(ts.AddSteps(4), 1, 1, clt).Should().BeTrue(); cd.IsBusyDuringTimespan(ts.AddSteps(5), 1, 1, clt).Should().BeTrue(); cd.IsBusyDuringTimespan(ts.AddSteps(6), 0, 1, clt).Should().BeFalse(); } } wd.CleanUp(); } }
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 CompressExpandDoubleArrayShrink1ShouldWork() { double[] tmparr = { 1, 2, 3, 4 }; var cp = new CalcProfile("bla", Guid.NewGuid().ToStrGuid(), tmparr.ToList(), ProfileType.Absolute, "bla"); var result = cp.CompressExpandDoubleArray(0.5); //List<double> result = CalcProfile.CompressExpandDoubleArray(tmplist, 0.5); result.StepValues.Count.Should().Be(2); result.StepValues[0].Should().Be(2); result.StepValues[1].Should().Be(4); }
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 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 CompressExpandDoubleArrayExpand2ShouldWork() { var tmparr = new List <double>(); tmparr.AddRange(new double[] { 1, 2, 3 }); var cp = new CalcProfile("bla", Guid.NewGuid().ToStrGuid(), tmparr, ProfileType.Absolute, "bla"); var result = cp.CompressExpandDoubleArray(1.5); //List<double> result = CalcProfile.CompressExpandDoubleArray(tmparr, 1.5); result.StepValues.Count.Should().Be(5); result.StepValues[0].Should().Be(1); result.StepValues[1].Should().Be(2); result.StepValues[2].Should().Be(2); result.StepValues[3].Should().Be(3); result.StepValues[4].Should().Be(3); }
public static StepValues MakeStepValues([NotNull] CalcProfile srcProfile, double multiplier, RandomValueProfile rvp, [NotNull] CalcDeviceLoad cdl) { var powerUsage = cdl.Value * multiplier; if (srcProfile.ProfileType == ProfileType.Absolute) { powerUsage = 1 * multiplier; } var values = new List <double>(srcProfile.StepValues); for (var i = 0; i < values.Count; i++) { values[i] = values[i] * powerUsage * rvp.Values[i]; } return(new StepValues(values, srcProfile.Name, srcProfile.DataSource)); }
private List <CalcAffordance.DeviceEnergyProfileTuple> MakeDeviceEnergyProfileTuples([ItemNotNull][NotNull] List <CalcDevice> devices, [NotNull] CalcAffordanceDto affordancedto) { List <CalcAffordance.DeviceEnergyProfileTuple> deviceEnergyProfiles = new List <CalcAffordance.DeviceEnergyProfileTuple>(); foreach (DeviceEnergyProfileTupleDto dto in affordancedto.Energyprofiles) { StrGuid devguid = dto.CalcDeviceGuid; CalcDevice device = devices.Single(x => x.Guid == devguid); CalcProfile cp = CalcDeviceFactory.MakeCalcProfile(dto.TimeProfile, _calcRepo.CalcParameters); CalcLoadType clt = _loadTypeDictionary.GetLoadtypeByGuid(dto.CalcLoadTypeGuid); CalcAffordance.DeviceEnergyProfileTuple dep = new CalcAffordance.DeviceEnergyProfileTuple(device, cp, clt, dto.TimeOffset, _calcRepo.CalcParameters.InternalStepsize, dto.Multiplier, dto.Probability); deviceEnergyProfiles.Add(dep); } return(deviceEnergyProfiles); }
private void SetTimeprofile([NotNull] CalcProfile calcProfile, [NotNull] TimeStep startidx, [NotNull] CalcLoadType loadType, [NotNull] string affordanceName, [NotNull] string activatingPersonName, StrGuid locationGuid) { CalcDeviceLoad cdl = null; foreach (var calcDeviceLoad in _loads) { if (calcDeviceLoad.LoadType == loadType) { cdl = calcDeviceLoad; } } if (cdl == null) { throw new LPGException("It was tried to activate the loadtype " + loadType.Name + " even though that one is not set for the device " + Name); } /* var factor = cdl.Value * multiplier; * if (calcProfile.ProfileType == ProfileType.Absolute) * { * factor = 1 * multiplier; * }*/ if (_calcRepo.Odap == null && !Config.IsInUnitTesting) { throw new LPGException("ODAP was null. Please report"); } // var totalDuration = calcProfile.GetNewLengthAfterCompressExpand(timefactor); //OefcKey key = new OefcKey(_calcDeviceDto.HouseholdKey, OefcDeviceType.Transportation, Guid, "-1", cdl.LoadType.Guid, "Transportation"); var key = _keysByLocGuidAndLoadtype[locationGuid][cdl.LoadType]; var rvp = RandomValueProfile.MakeStepValues(calcProfile.StepValues.Count, _calcRepo.NormalRandom, 0); var sv = StepValues.MakeStepValues(calcProfile, 1, rvp, cdl); _calcRepo.Odap.AddNewStateMachine(startidx, cdl.LoadType.ConvertToDto(), affordanceName, activatingPersonName, key, _calcDeviceDto, sv); //SetBusy(startidx, totalDuration, loadType, activateDespiteBeingBusy); // return totalDuration + startidx; }
public void Activate([NotNull] TimeStep time, DateTime dateTime) { var oneHour = new TimeSpan(1, 0, 0); var numberOfValuesInOneHour = (int)(oneHour.TotalMilliseconds / CalcRepo.CalcParameters.InternalStepsize.TotalMilliseconds); var coolingProfile = new List <double>(new double[numberOfValuesInOneHour]); var cdd = _calcDegreeHours[ new Tuple <int, int, int, int>(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour)]; var timeunitvalue = cdd.CoolingAmount / numberOfValuesInOneHour; for (var i = 0; i < coolingProfile.Count; i++) { coolingProfile[i] = timeunitvalue; } var cp = new CalcProfile("Cooling profile - " + time, System.Guid.NewGuid().ToStrGuid(), coolingProfile, ProfileType.Relative, "Calculated from Cooling Hours"); SetAllLoadTypesToTimeprofile(cp, time, "Air Conditioning", "Air Conditioner", 1); }
public void Activate([NotNull] TimeStep time, DateTime dateTime) { var oneDay = new TimeSpan(24, 0, 0); var numberOfValuesInOneDay = (int)(oneDay.TotalMilliseconds / CalcRepo.CalcParameters.InternalStepsize.TotalMilliseconds); var heatingProfile = new List <double>(new double[numberOfValuesInOneDay]); var cdd = _calcDegreeDays[new Tuple <int, int, int>(dateTime.Year, dateTime.Month, dateTime.Day)]; var timeUnitValue = cdd.HeatingAmount / numberOfValuesInOneDay / Loads[0].LoadType.ConversionFactor; for (var i = 0; i < heatingProfile.Count; i++) { heatingProfile[i] = timeUnitValue; } var cp = new CalcProfile("Heating profile - " + time, System.Guid.NewGuid().ToStrGuid(), heatingProfile, ProfileType.Relative, "Calculated from Heating Degree Days"); SetAllLoadTypesToTimeprofile(cp, time, "Space Heating", "Space Heater", 1); }
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 DriveAndCharge([NotNull] TimeStep currentTimeStep) { AdjustCurrentsiteByTimestep(currentTimeStep); LastChargingPower = 0; //first the undefined state // geräte, die nicht geladen werden müssen, haben eine negative range. //geräte im vehicle depot / in transit müssen nicht geladen werden. if (_fullRangeInMeters < 0) { DisconnectCar(); _calcRepo.OnlineLoggingData.AddTransportationDeviceState(new TransportationDeviceStateEntry( Name, Guid, currentTimeStep, TransportationDeviceState.Undefined, CurrentSoc, _calcDeviceDto.HouseholdKey, _availableRangeInMeters, _currentSite?.Name, _lastUsingPerson, _dsc.MakeDateStringFromTimeStep(currentTimeStep), 0)); return; } //currently driving if (currentTimeStep >= _activationStartTimestep && currentTimeStep < _activationStopTimestep) { DisconnectCar(); if (_currentSite != null) { throw new LPGException("transportation device was assigned to a site, even though it is driving"); } double distancePerTimestep = AverageSpeedInMPerS * _calcRepo.CalcParameters.InternalStepsize.TotalSeconds; _availableRangeInMeters -= distancePerTimestep; if (_availableRangeInMeters <= 0) { _availableRangeInMeters = 0; } _calcRepo.OnlineLoggingData.AddTransportationDeviceState(new TransportationDeviceStateEntry( Name, Guid, currentTimeStep, TransportationDeviceState.Driving, CurrentSoc, _calcDeviceDto.HouseholdKey, _availableRangeInMeters, _currentSite?.Name, _lastUsingPerson, _dsc.MakeDateStringFromTimeStep(currentTimeStep), distancePerTimestep)); return; } //car is fully charged if (_availableRangeInMeters >= _fullRangeInMeters) { _calcRepo.OnlineLoggingData.AddTransportationDeviceState(new TransportationDeviceStateEntry( Name, Guid, currentTimeStep, TransportationDeviceState.ParkingAndFullyCharged, CurrentSoc, _calcDeviceDto.HouseholdKey, _availableRangeInMeters, _currentSite?.Name, null , _dsc.MakeDateStringFromTimeStep(currentTimeStep), 0)); DisconnectCar(); //TODO: different disconnect strategies return; } if (_currentSite != null) { //needs charging && is at charging station var chargingStations = _currentSite.ChargingDevices.Where(x => x.CarChargingLoadType == _chargingCalcLoadType1 && x.DeviceCategory == Category).ToList(); if (chargingStations.Count > 0) { if (chargingStations.All(x => !x.IsAvailable) && _lastChargingStation == null) { _calcRepo.OnlineLoggingData.AddTransportationDeviceState(new TransportationDeviceStateEntry( Name, Guid, currentTimeStep, TransportationDeviceState.ParkingAndWaitingForCharging, CurrentSoc, _calcDeviceDto.HouseholdKey, _availableRangeInMeters, _currentSite.Name, null, _dsc.MakeDateStringFromTimeStep(currentTimeStep), 0)); DisconnectCar(); return; } //use the first one that is available //TODO: recycle the last one used var chargingStation = _lastChargingStation; if (_lastChargingStation == null) { chargingStation = chargingStations.First(x => x.IsAvailable); ConnectCar(chargingStation); } if (_currentSite == null) { throw new LPGException("Current site was null while trying to charge."); } if (chargingStation == null) { throw new LPGException("Charging station for charging was null"); } _calcRepo.OnlineLoggingData.AddTransportationDeviceState(new TransportationDeviceStateEntry( Name, Guid, currentTimeStep, TransportationDeviceState.ParkingAndCharging, CurrentSoc, _calcDeviceDto.HouseholdKey, _availableRangeInMeters, _currentSite.Name, null, _dsc.MakeDateStringFromTimeStep(currentTimeStep), 0)); double maxChargingPower = Math.Min(_maxChargingPower, chargingStation.MaxChargingPower); List <double> chargingProfile = new List <double> { maxChargingPower }; var cp = new CalcProfile("Profile for " + _currentSite.Name + " - Charging - " + Name, System.Guid.NewGuid().ToStrGuid(), chargingProfile, ProfileType.Absolute, "Synthetic Charging for " + Name + " @ " + _currentSite.Name); var dstLoadType = chargingStation.GridChargingLoadType; var key = _keysByLocGuidAndLoadtype[_currentSite.Guid][dstLoadType]; //OefcKey key = new OefcKey(_householdKey, OefcDeviceType.Charging, Guid, _currentSite.Guid, dstLoadType.Guid, "Transportation"); //if (dstLoadType == null) { // throw new Exception("???"); //} CalcDeviceLoad cdl = new CalcDeviceLoad("", 1, dstLoadType, 0, 0); //if (cp.DataSource != "Synthetic") { //throw new LPGException("wrong data source"); //} var rsv = RandomValueProfile.MakeStepValues(cp.StepValues.Count, _calcRepo.NormalRandom, cdl.PowerStandardDeviation); var sv = StepValues.MakeStepValues(cp, 1, rsv, cdl); _calcRepo.Odap.AddNewStateMachine(currentTimeStep, dstLoadType.ConvertToDto(), "Charging for " + Name + " @ " + _currentSite, "(autonomous)", key, _calcDeviceDto, sv); double gainedDistance = maxChargingPower * _energyToDistanceFactor * _calcRepo.CalcParameters.InternalStepsize.TotalSeconds; _availableRangeInMeters += gainedDistance; LastChargingPower = maxChargingPower; if (_availableRangeInMeters > _fullRangeInMeters) { //TODO: do this properly: reduce the max charging power _availableRangeInMeters = _fullRangeInMeters; } return; } } DisconnectCar(); _calcRepo.OnlineLoggingData.AddTransportationDeviceState(new TransportationDeviceStateEntry( Name, Guid, currentTimeStep, TransportationDeviceState.ParkingAndNoChargingAvailableHere, CurrentSoc, _calcDeviceDto.HouseholdKey, _availableRangeInMeters, _currentSite?.Name, null , _dsc.MakeDateStringFromTimeStep(currentTimeStep), 0)); }
public void Activate([NotNull] TimeStep startTimeStep, int durationInTimesteps, [NotNull] CalcSite srcSite, [NotNull] CalcSite dstSite, [NotNull] string travelRouteName, [NotNull] string personName, [NotNull] TimeStep transportationEventStartTimeStep, [NotNull] TimeStep transportationEventEndTimeStep) { if (startTimeStep < transportationEventStartTimeStep || transportationEventEndTimeStep < startTimeStep) { throw new LPGException("Bug in the transportation module. Start time earlier than possible."); } if (durationInTimesteps == 0) { throw new LPGException("Can't activate with a duration of 0 timesteps"); } _lastUsingPerson = personName; if (startTimeStep < _activationStopTimestep && Category.IsLimitedToSingleLocation) { throw new LPGException( "Double activation of a transportation device. This seems to be a bug. Please fix."); } if (_currentSite != srcSite && _currentSite != null) { throw new LPGException("Trying to activate a device that is not at the source location"); } _activationStartTimestep = startTimeStep; _activationStopTimestep = startTimeStep.AddSteps(durationInTimesteps); if (Category.IsLimitedToSingleLocation) { _targetSiteByTimeStep.Add(startTimeStep.InternalStep, null); _targetSiteByTimeStep.Add(_activationStopTimestep.InternalStep, dstSite); } //_currentSite = dstSite; for (int i = transportationEventStartTimeStep.InternalStep; i < transportationEventEndTimeStep.InternalStep && i < _isBusyArray.Length; i++) { _isBusyArray[i] = true; } foreach (CalcDeviceLoad load in _loads) { var transportationDeviceProfile = new List <double>(durationInTimesteps); for (var i = 0; i < durationInTimesteps; i++) { transportationDeviceProfile.Add(load.Value); } var cp = new CalcProfile(srcSite.Name + " - " + dstSite.Name + " - " + Name, System.Guid.NewGuid().ToStrGuid(), transportationDeviceProfile, ProfileType.Relative, "Synthetic for " + Name); SetTimeprofile(cp, startTimeStep, load.LoadType, "Transport via " + Name, personName + " - " + travelRouteName, _calcDeviceDto.LocationGuid); } }
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 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 TestInterruptionTest() { using var wd = new WorkingDir(Utili.GetCurrentMethodAndClass()); DateTime startdate = new DateTime(2018, 1, 1); DateTime enddate = startdate.AddMinutes(100); CalcParameters calcParameters = CalcParametersFactory.MakeGoodDefaults().SetStartDate(startdate).SetEndDate(enddate).SetSettlingDays(0).EnableShowSettlingPeriod().DisableShowSettlingPeriod().SetAffordanceRepetitionCount(1); //var r = new Random(1); //var nr = new NormalRandom(0, 1, r); var desire1 = new CalcDesire("desire1", 1, 0.5m, 4, 1, 1, 60, -1, null, "", ""); var lt = new CalcLoadType("calcLoadtype1", "kwh", "W", 1, true, Guid.NewGuid().ToStrGuid()); //var variableOperator = new VariableOperator(); using var fft = new FileFactoryAndTracker(wd.WorkingDirectory, "blub", wd.InputDataLogger); var key = new HouseholdKey("HH1"); wd.InputDataLogger.AddSaver(new ActionEntryLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new ColumnEntryLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new HouseholdKeyLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new ResultFileEntryLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new LocationEntryLogger(wd.SqlResultLoggingService)); 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(calcParameters); using OnlineLoggingData old = new OnlineLoggingData(dsc, wd.InputDataLogger, calcParameters); using var lf = new LogFile(calcParameters, fft); var cloc = new CalcLocation("loc1", Guid.NewGuid().ToStrGuid()); BitArray isSick = new BitArray(calcParameters.InternalTimesteps); BitArray isOnVacation = new BitArray(calcParameters.InternalTimesteps); CalcPersonDto calcPerson = CalcPersonDto.MakeExamplePerson(); var odap = new OnlineDeviceActivationProcessor(old, calcParameters, fft); Random rnd = new Random(); NormalRandom nr = new NormalRandom(0, 1, rnd); using CalcRepo calcRepo = new CalcRepo(lf: lf, odap: odap, calcParameters: calcParameters, rnd: rnd, normalRandom: nr, onlineLoggingData: old); var cp = new CalcPerson(calcPerson, cloc, isSick, isOnVacation, calcRepo); //"blub", 1, 1, r,20, PermittedGender.Male, lf, "HH1", cloc,"traittag","hhname0", calcParameters,isSick, Guid.NewGuid().ToStrGuid()); cp.PersonDesires.AddDesires(desire1); cp.SicknessDesires.AddDesires(desire1); var deviceLoads = new List <CalcDeviceLoad> { new CalcDeviceLoad("devload1", 1, lt, 100, 1) }; var devCategoryGuid = Guid.NewGuid().ToStrGuid(); CalcDeviceDto cdd1 = new CalcDeviceDto("cdevice1", devCategoryGuid, key, OefcDeviceType.Device, "category", "", Guid.NewGuid().ToStrGuid(), cloc.Guid, cloc.Name); var cdev1 = new CalcDevice(deviceLoads, cloc, cdd1, calcRepo); CalcDeviceDto cdd2 = new CalcDeviceDto("cdevice2", devCategoryGuid, key, OefcDeviceType.Device, "category", "", Guid.NewGuid().ToStrGuid(), cloc.Guid, cloc.Name); var cdev2 = new CalcDevice(deviceLoads, cloc, cdd2, calcRepo); CalcDeviceDto cdd3 = new CalcDeviceDto("cdevice3", devCategoryGuid, key, OefcDeviceType.Device, "category", "", Guid.NewGuid().ToStrGuid(), cloc.Guid, cloc.Name); var cdev3 = new CalcDevice(deviceLoads, cloc, cdd3, calcRepo); cloc.Devices.Add(cdev1); cloc.Devices.Add(cdev2); cloc.Devices.Add(cdev3); var daylight = new BitArray(100); daylight.SetAll(true); DayLightStatus dls = new DayLightStatus(daylight); double[] newValues = { 1, 1, 1.0, 1, 1, 1, 1, 1 }; var newList = new List <double>(newValues); var cprof = new CalcProfile("cp1", Guid.NewGuid().ToStrGuid(), newList, ProfileType.Relative, "bla"); var desires = new List <CalcDesire> { desire1 }; var color = new ColorRGB(255, 0, 0); CalcVariableRepository crv = new CalcVariableRepository(); BitArray isBusy = new BitArray(calcParameters.InternalTimesteps, false); var aff1 = new CalcAffordance("aff1", cprof, cloc, false, desires, 1, 100, PermittedGender.All, false, 0, color, "aff category", true, false, new List <CalcAffordanceVariableOp>(), new List <VariableRequirement>(), ActionAfterInterruption.GoBackToOld, "bla", 100, false, "", Guid.NewGuid().ToStrGuid(), crv , new List <CalcAffordance.DeviceEnergyProfileTuple>(), isBusy, BodilyActivityLevel.Low, calcRepo); aff1.AddDeviceTuple(cdev1, cprof, lt, 0, calcParameters.InternalStepsize, 1, 1); cloc.AddAffordance(aff1); var aff2 = new CalcAffordance("aff2", cprof, cloc, false, desires, 1, 100, PermittedGender.All, false, 0, color, "aff category", 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); aff2.AddDeviceTuple(cdev2, cprof, lt, 0, calcParameters.InternalStepsize, 1, 1); cloc.AddAffordance(aff2); var clocs = new List <CalcLocation> { cloc }; BitArray isBusySub = new BitArray(calcParameters.InternalTimesteps, false); var calcSubAffordance = new CalcSubAffordance("subaffname", cloc, desires, 0, 100, 1, PermittedGender.All, "subaff", false, true, aff1, new List <CalcAffordanceVariableOp>(), 100, "testing", Guid.NewGuid().ToStrGuid(), isBusySub, crv, BodilyActivityLevel.Low, calcRepo); aff2.SubAffordances.Add(calcSubAffordance); calcSubAffordance.SetDurations(2); var persons = new List <CalcPerson> { cp }; for (var i = 0; i < 100; i++) { TimeStep ts = new TimeStep(i, 0, true); cp.NextStep(ts, clocs, dls, new HouseholdKey("hh1"), persons, 1); } //wd.CleanUp(); }
//BitArray ICalcAffordanceBase.IsBusyArray { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } public void Activate(TimeStep startTime, string activatorName, CalcLocation personSourceLocation, out ICalcProfile personTimeProfile) { if (_myLastTimeEntry.TimeOfLastEvalulation != startTime) { throw new LPGException("trying to activate without first checking if the affordance is busy is a bug. Please report."); } CalcTravelRoute route = _myLastTimeEntry.PreviouslySelectedRoutes[personSourceLocation]; int routeduration = route.Activate(startTime, activatorName, out var usedDevices); if (routeduration == 0) { _calcRepo.OnlineLoggingData.AddTransportationStatus( new TransportationStatus(startTime, _householdkey, "\tActivating " + Name + " at " + startTime + " with no transportation and moving from " + personSourceLocation + " to " + _sourceAffordance.ParentLocation.Name + " for affordance " + _sourceAffordance.Name)); } else { _calcRepo.OnlineLoggingData.AddTransportationStatus(new TransportationStatus( startTime, _householdkey, "\tActivating " + Name + " at " + startTime + " with a transportation duration of " + routeduration + " for moving from " + personSourceLocation + " to " + _sourceAffordance.ParentLocation.Name)); } TimeStep affordanceStartTime = startTime.AddSteps(routeduration); if (affordanceStartTime.InternalStep < _calcRepo.CalcParameters.InternalTimesteps) { _sourceAffordance.Activate(affordanceStartTime, activatorName, personSourceLocation, out var sourcePersonProfile); CalcProfile newPersonProfile = new CalcProfile( "Travel Profile for Route " + route.Name + " to affordance " + _sourceAffordance.Name, System.Guid.NewGuid().ToStrGuid(), CalcProfile.MakeListwithValue1AndCustomDuration(routeduration), ProfileType.Absolute, sourcePersonProfile.DataSource); newPersonProfile.AppendProfile(sourcePersonProfile); personTimeProfile = newPersonProfile; string usedDeviceNames = String.Join(", ", usedDevices.Select(x => x.Device.Name + "(" + x.DurationInSteps + ")")); _calcRepo.OnlineLoggingData.AddTransportationEvent(_householdkey, activatorName, startTime, personSourceLocation.CalcSite?.Name ?? "", Site.Name, route.Name, usedDeviceNames, routeduration, sourcePersonProfile.StepValues.Count, _sourceAffordance.Name, usedDevices); } else { //this is if the simulation ends during a transport CalcProfile newPersonProfile = new CalcProfile( "Travel Profile for Route " + route.Name + " to affordance " + _sourceAffordance.Name, System.Guid.NewGuid().ToStrGuid(), CalcProfile.MakeListwithValue1AndCustomDuration(routeduration), ProfileType.Absolute, _sourceAffordance.Name); personTimeProfile = newPersonProfile; string usedDeviceNames = String.Join(", ", usedDevices.Select(x => x.Device.Name + "(" + x.DurationInSteps + ")")); _calcRepo.OnlineLoggingData.AddTransportationEvent(_householdkey, activatorName, startTime, personSourceLocation.CalcSite?.Name ?? "", Site.Name, route.Name, usedDeviceNames, routeduration, newPersonProfile.StepValues.Count, _sourceAffordance.Name, usedDevices); } }
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 ProcessOneEnergyStorageTimestepTest() { 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)); CalcParameters calcParameters = CalcParametersFactory.MakeGoodDefaults(); calcParameters.ShowSettlingPeriodTime = true; using (OnlineLoggingData old = new OnlineLoggingData(new DateStampCreator(calcParameters), wd.InputDataLogger, calcParameters)) { using (FileFactoryAndTracker fft = new FileFactoryAndTracker(wd.WorkingDirectory, "name", wd.InputDataLogger)) { fft.RegisterGeneralHouse(); var odap = new OnlineDeviceActivationProcessor(old, calcParameters, fft); var clt = new CalcLoadType("clt1", "W", "kWh", 1, true, Guid.NewGuid().ToStrGuid()); var deviceGuid = Guid.NewGuid().ToStrGuid(); HouseholdKey hhkey = new HouseholdKey("HH1"); var locationGuid = Guid.NewGuid().ToStrGuid(); CalcDeviceDto cdd = new CalcDeviceDto("dev1", "devcatguid".ToStrGuid(), hhkey, OefcDeviceType.Device, "devcatname", "", deviceGuid, locationGuid, "loc"); var key = new OefcKey(cdd, clt.Guid); odap.RegisterDevice(clt.ConvertToDto(), cdd); double[] timestepValue = { 1.0, 0 }; var timestepValues = new List <double>(timestepValue); var cp = new CalcProfile("myCalcProfile", Guid.NewGuid().ToStrGuid(), timestepValues, ProfileType.Absolute, "synthetic"); CalcDeviceLoad cdl1 = new CalcDeviceLoad("", -10, clt, 0, 0); var rvp = RandomValueProfile.MakeStepValues(cp.StepValues.Count, NormalRandom, 0); StepValues sv1 = StepValues.MakeStepValues(cp, 1, rvp, cdl1); odap.AddNewStateMachine(new TimeStep(1, 0, true), clt.ConvertToDto(), "name1", "p1", key, cdd, sv1); CalcDeviceLoad cdl2 = new CalcDeviceLoad("", -100, clt, 0, 0); StepValues sv2 = StepValues.MakeStepValues(cp, 1, rvp, cdl2); odap.AddNewStateMachine(new TimeStep(3, 0, true), clt.ConvertToDto(), "name2", "syn", key, cdd, sv2); CalcDeviceLoad cdl3 = new CalcDeviceLoad("", -10, clt, 0, 0); StepValues sv3 = StepValues.MakeStepValues(cp, 1, rvp, cdl3); odap.AddNewStateMachine(new TimeStep(5, 0, true), clt.ConvertToDto(), "name3", "syn", key, cdd, sv3); CalcDeviceLoad cdl4 = new CalcDeviceLoad("", 100, clt, 0, 0); StepValues sv4 = StepValues.MakeStepValues(cp, 1, rvp, cdl4); odap.AddNewStateMachine(new TimeStep(7, 0, true), clt.ConvertToDto(), "name4", "syn", key, cdd, sv4); double[] resultValues = { 0, -10.0, 0, -100, 0, 10, 0, 100, 0, 0 }; var ces = new CalcEnergyStorage(odap, clt.ConvertToDto(), 100, 7, 0, 0, 5, 20, null, cdd); List <OnlineEnergyFileRow> rawRows = new List <OnlineEnergyFileRow>(); int keyidx = 0; foreach (var keys in odap.Oefc.ColumnEntriesByLoadTypeByDeviceKey.Values) { foreach (KeyValuePair <OefcKey, ColumnEntry> pair in keys) { Logger.Info("Key " + keyidx + " " + pair.Key.ToString() + " - " + pair.Value); keyidx++; } } for (var i = 0; i < 10; i++) { TimeStep ts = new TimeStep(i, 0, true); var filerows = odap.ProcessOneTimestep(ts); rawRows.Add(filerows[0]); filerows.Count.Should().Be(1); filerows[0].EnergyEntries.Count.Should().Be(1); var sb = new StringBuilder("row0 before:"); sb.Append(filerows[0].EnergyEntries[0]); sb.Append(" : "); //sb.Append(filerows[0].EnergyEntries[1]); //filerows[0].EnergyEntries[0].Should().Be(resultValues[i]); for (var j = 0; j < 5; j++) { ces.ProcessOneTimestep(filerows, ts, null); } sb.Append(" row0 after:"); sb.Append(filerows[0].EnergyEntries[0]); sb.Append(" : "); //sb.Append(filerows[0].EnergyEntries[1]); sb.Append(" :StorageLevel "); sb.Append(ces.PreviousFillLevel); sb.Append(" :Expected "); sb.Append(resultValues[i]); Logger.Info(sb.ToString()); } rawRows.Count.Should().Be(10); } } wd.CleanUp(); } }