public void RunTransportDecoratorTest() { using (var wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { wd.InputDataLogger.AddSaver(new HouseholdKeyLogger(wd.SqlResultLoggingService)); Config.IsInUnitTesting = true; var rnd = new Random(1); CalcParameters calcParameters = CalcParametersFactory.MakeGoodDefaults(); HouseholdKey key = new HouseholdKey("hh1"); using (var calcRepo = SetupFullWorkingTransportationExample(wd, rnd, out _, out var srcloc, out var dstloc, out var dstSite, out var transportationHandler, out var abt, calcParameters, key)) { //make sure there is a travel route const string personName = "activator"; TimeStep ts = new TimeStep(0, 0, false); var travelroute = transportationHandler.GetTravelRouteFromSrcLoc(srcloc, dstSite, ts, personName, calcRepo); Assert.NotNull(travelroute); // find if busy var isbusy = abt.IsBusy(ts, srcloc, "", false); isbusy.Should().BeFalse(); var affs = dstloc.Affordances.ToList(); Logger.Info("Activating affordance for time 0"); travelroute.GetDuration(ts, personName, new List <CalcTransportationDevice>()); affs[0].Activate(ts, "activator", srcloc, out var _); } //should throw exception the second time. Logger.Info("Activating affordance again for time 0"); CalcAffordance.DoubleCheckBusyArray = false; wd.CleanUp(); } }
public TimeStep(int internalstep, [NotNull] CalcParameters parameters) { InternalStep = internalstep; ShowSettling = parameters.ShowSettlingPeriodTime; ExternalStep = internalstep - parameters.DummyCalcSteps; DummyCalcSteps = parameters.DummyCalcSteps; }
public void RunDoubleActivationTest() { var rnd = new Random(1); using (var wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { wd.InputDataLogger.AddSaver(new HouseholdKeyLogger(wd.SqlResultLoggingService)); CalcParameters calcParameters = CalcParametersFactory.MakeGoodDefaults(); HouseholdKey key = new HouseholdKey("hh1"); using (var calcRepo = SetupFullWorkingTransportationExample(wd, rnd, out _, out var srcloc, out var dstloc, out var dstSite, out var transportationHandler, out var abt, calcParameters, key)) { //make sure there is a travel route const string personname = "activator"; TimeStep ts = new TimeStep(0, 0, false); var travelroute = transportationHandler.GetTravelRouteFromSrcLoc(srcloc, dstSite, ts, personname, calcRepo); Assert.NotNull(travelroute); // find if busy var isbusy = abt.IsBusy(ts, srcloc, personname, false); isbusy.Should().BeFalse(); var affs = dstloc.Affordances.ToList(); Logger.Info("Activating affordance for time 0"); affs[0].Activate(ts, personname, srcloc, out _); } //should throw exception the second time. Logger.Info("Activating affordance again for time 0"); //this should throw, since it is already busy //Assert.Throws<LPGException>(() =>affs[0].Activate(0, "activator", null, srcloc, new Dictionary<int, CalcProfile>(), out _)); CalcAffordance.DoubleCheckBusyArray = false; wd.CleanUp(); } }
public CalcRepo( [CanBeNull] IOnlineDeviceActivationProcessor odap = null, [CanBeNull] Random rnd = null, [CanBeNull] CalcParameters calcParameters = null, [CanBeNull] IOnlineLoggingData onlineLoggingData = null, [CanBeNull] NormalRandom normalRandom = null, [CanBeNull] ILogFile lf = null, [CanBeNull] SqlResultLoggingService srls = null, [CanBeNull] IInputDataLogger inputDataLogger = null, [CanBeNull] CalculationProfiler calculationProfiler = null, [CanBeNull] FileFactoryAndTracker fft = null, [CanBeNull] DateStampCreator dsc = null) { _dateStampCreator = dsc; _fft = fft; _odap = odap; _rnd = rnd; _calcParameters = calcParameters; _onlineLoggingData = onlineLoggingData; _normalRandom = normalRandom; _lf = lf; _srls = srls; _inputDataLogger = inputDataLogger; _calculationProfiler = calculationProfiler; }
public void CalcAffordanceActivateTest0Percent() { Logger.Info("hi"); var calcParameters = CalcParameters.GetNew(); const int stepcount = 150; SetupProbabilityTest(out var aff, out var lt, out var cd, out var loc, stepcount, 0); var trueCount = 0; TimeStep ts1 = new TimeStep(0, 0, true); var result = aff.IsBusy(ts1, loc, "name"); result.Should().BeFalse(); const int resultcount = stepcount - 20; for (var i = 0; i < resultcount; i++) { for (var j = 0; j < stepcount; j++) { TimeStep ts = new TimeStep(j, calcParameters); cd.SetIsBusyForTesting(ts, false, lt); cd.IsBusyForLoadType[lt][ts.InternalStep] = false; } TimeStep ts2 = new TimeStep(i, calcParameters); aff.IsBusy(ts2, loc, "name"); //var variableOperator = new VariableOperator(); aff.Activate(ts2, "blub", loc, out var _); if (cd.GetIsBusyForTesting(ts2, lt)) { trueCount++; } } Logger.Info("Truecount: " + trueCount); trueCount.Should().BeApproximately(0, 0.1); }
public LogFile([NotNull] CalcParameters calcParameters, FileFactoryAndTracker fft, bool writeToConsole = false ) { if (calcParameters.IsSet(CalcOption.ThoughtsLogfile)) { if (writeToConsole) { _thoughtsLogFile = new ConsoleThoughts(); } else { _thoughtsLogFile = new ThoughtsLogFile(fft, calcParameters); } } if (calcParameters.IsSet(CalcOption.DesiresLogfile)) { _desiresLogfile = new DesiresLogFile(fft, calcParameters); } if (calcParameters.IsSet(CalcOption.EnergyStorageFile)) { _energyStorageLogfile = new EnergyStorageLogfile(calcParameters, fft); } //_transportationLogFile = new TransportationLogFile(_fft,_calcParameters); }
public void EnergyStorageSignalTests2() { CalcParameters cp = CalcParameters.GetNew(); cp.DummyCalcSteps = 0; //CalcLoadType clt = new CalcLoadType("clt", "power", "sum", 1, true, Guid.NewGuid().ToStrGuid()); CalcVariable cv = new CalcVariable("myvariable", Guid.NewGuid().ToStrGuid(), 0, "House", Guid.NewGuid().ToStrGuid(), Constants.HouseKey); CalcEnergyStorageSignal cess = new CalcEnergyStorageSignal("blub", 100, 50, 2, cv, Guid.NewGuid().ToStrGuid()); List <double> values = new List <double>(); int i = 0; TestCess(cess, new TimeStep(i++, cp), 100, 100, values); TestCess(cess, new TimeStep(i++, cp), 100, 5, values); TestCess(cess, new TimeStep(i++, cp), 100, 100, values); TestCess(cess, new TimeStep(i++, cp), 100, 5, values); TestCess(cess, new TimeStep(i++, cp), 100, 100, values); TestCess(cess, new TimeStep(i++, cp), 100, 5, values); TestCess(cess, new TimeStep(i++, cp), 100, 100, values); TestCess(cess, new TimeStep(i++, cp), 100, 5, values); TestCess(cess, new TimeStep(i++, cp), 100, 100, values); TestCess(cess, new TimeStep(i++, cp), 100, 5, values); TestCess(cess, new TimeStep(i++, cp), 100, 100, values); TestCess(cess, new TimeStep(i++, cp), 100, 5, values); TestCess(cess, new TimeStep(i++, cp), 100, 100, values); TestCess(cess, new TimeStep(i, cp), 100, 5, values); }
public DaylightTimesLogger([NotNull] SqlResultLoggingService srls, [NotNull] CalcParameters calcParameters) : base(typeof(DayLightStatus), new ResultTableDefinition("DaylightTimes", ResultTableID.DaylightTimes, "Time of daylight each day", CalcOption.DaylightTimesList), srls) { _srls = srls; _calcParameters = calcParameters; _dsc = new DateStampCreator(calcParameters); }
public void CalcPersonDesiresTest() { CalcParameters calcParameters = CalcParametersFactory.MakeGoodDefaults(); var r = new Random(1); using (CalcRepo calcRepo = new CalcRepo(calcParameters: calcParameters, rnd: r)) { var cpd = new CalcPersonDesires(calcRepo); var cd1 = new CalcDesire("blub0", 1, 0.5m, 0.1m, 1, 1, 1, -1, null, "", ""); cpd.AddDesires(cd1); var cd2 = new CalcDesire("blub1", 2, 0.5m, 0.1m, 1, 1, 1, -1, null, "", ""); cpd.AddDesires(cd2); Logger.Info("CalcPersonDesiresTest:" + cd1.Value + " ; " + cd2.Value); // satisfaction var satis1 = new CalcDesire("blub", 1, 0.5m, 12, 1, 1, 60, -1, null, "", "") { Value = 1 }; var satisfactionValues = new List <CalcDesire> { satis1 }; Logger.Info(cd1.Value + " ; " + cd2.Value); for (var i = 0; i < 20; i++) { TimeStep ts = new TimeStep(i, 0, false); cpd.ApplyDecay(ts); cpd.ApplyAffordanceEffect(satisfactionValues, true, "blub"); Logger.Info(cd1.Value + " ; " + cd2.Value); } } }
public OnlineLoggingData([NotNull] DateStampCreator dsc, [NotNull] IInputDataLogger idl, [NotNull] CalcParameters calcParameters) { _dsc = dsc; _idl = idl; _calcParameters = calcParameters; _columnEntries = new List <ColumnEntry>(); _lists.Add(_columnEntries); _affordanceActivationEntries = new List <DeviceActivationEntry>(); _lists.Add(_affordanceActivationEntries); _transportationStatuses = new List <TransportationStatus>(); _lists.Add(_transportationStatuses); _transportationDeviceState = new List <TransportationDeviceStateEntry>(); _lists.Add(_transportationDeviceState); _transportationEvents = new List <TransportationEventEntry>(); _lists.Add(_transportationEvents); _locationEntries = new List <LocationEntry>(); _lists.Add(_locationEntries); _personStatus = new List <PersonStatus>(); _lists.Add(_personStatus); _chargingStationStates = new List <ChargingStationState>(); _lists.Add(_chargingStationStates); _variableEntries = new List <CalcVariableEntry>(); _lists.Add(_variableEntries); }
public void CalcParameterLoggerTest() { CalcParameters cp = CalcParameters.GetNew(); cp.SetStartDate(2017, 1, 1); cp.SetEndDate(2018, 1, 1); cp.Enable(CalcOption.ActivationsPerHour); using (WorkingDir wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { SqlResultLoggingService srls = new SqlResultLoggingService(wd.WorkingDirectory); CalcParameterLogger cpl = new CalcParameterLogger(srls); cpl.Run(Constants.GeneralHouseholdKey, cp); GC.Collect(); GC.WaitForPendingFinalizers(); CalcParameters cp2 = cpl.Load(); GC.Collect(); GC.WaitForPendingFinalizers(); string s1 = JsonConvert.SerializeObject(cp, Formatting.Indented); string s2 = JsonConvert.SerializeObject(cp2, Formatting.Indented); s1.Should().Be(s2); cp2.IsSet(CalcOption.ActivationsPerHour).Should().BeTrue(); Assert.NotNull(cp2); wd.CleanUp(); } }
public CalcPersonDtoFactory([NotNull] CalcParameters calcParameters, [NotNull] Random random, [NotNull] NormalRandom normalRandom, [NotNull] VacationDtoFactory vacationDtoFactory) { _calcParameters = calcParameters; _random = random; _normalRandom = normalRandom; _vacationDtoFactory = vacationDtoFactory; }
public void RegisterDeviceActivationTest() { using (WorkingDir wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { wd.InputDataLogger.AddSaver(new HouseholdKeyLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new DeviceActivationEntryLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new ResultFileEntryLogger(wd.SqlResultLoggingService)); CalcParameters cp = CalcParametersFactory.MakeGoodDefaults().EnableShowSettlingPeriod(); using (var fft = new FileFactoryAndTracker(wd.WorkingDirectory, "hhname", wd.InputDataLogger)) { var key = new HouseholdKey(" hh1"); fft.HouseholdRegistry.RegisterHousehold(key, "hh key", HouseholdKeyType.Household, wd.InputDataLogger, "desc", null, null); fft.HouseholdRegistry.RegisterHousehold(Constants.GeneralHouseholdKey, "general", HouseholdKeyType.General, wd.InputDataLogger, "desc", null, null); DateStampCreator dsc = new DateStampCreator(cp); using OnlineLoggingData old = new OnlineLoggingData(dsc, wd.InputDataLogger, cp); fft.HouseholdRegistry.RegisterHousehold(key, "hh key", HouseholdKeyType.Household, wd.InputDataLogger, "desc", null, null); CalcLoadTypeDto clt = new CalcLoadTypeDto("lt", "unitofpower", "unitofsum", 1, true, "guid".ToStrGuid()); TimeStep ts = new TimeStep(1, 1, true); CalcDeviceDto cdd = new CalcDeviceDto("devname", "".ToStrGuid(), key, OefcDeviceType.Device, "devcatname", "", Guid.NewGuid().ToStrGuid(), "locguid".ToStrGuid(), "locname"); DeviceActivationEntry aeue = new DeviceActivationEntry("affname", clt, 1, "activatorname", 1, ts, cdd); old.RegisterDeviceActivation(aeue); old.FinalSaveToDatabase(); } wd.CleanUp(); } }
public void TestLocationEntryBasics() { Config.IsInUnitTesting = true; using (WorkingDir wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { DateTime startdate = new DateTime(2018, 1, 1); DateTime enddate = startdate.AddMinutes(1000); CalcParameters calcParameters = CalcParametersFactory.MakeGoodDefaults().SetStartDate(startdate).SetEndDate(enddate).SetSettlingDays(0).EnableShowSettlingPeriod(); calcParameters.Options.Add(CalcOption.LocationsEntries); //FileFactoryAndTracker fft = new FileFactoryAndTracker(wd.WorkingDirectory,"blub",wd.InputDataLogger); //CalcLocation cl = new CalcLocation("blub", 1, Guid.NewGuid().ToStrGuid()); //Mock<ILogFile> lf = new Mock<ILogFile>(); //CalcPerson cp = MakeCalcPerson(cl,calcParameters,lf.Object); HouseholdKey key = new HouseholdKey("hh1"); TimeStep ts = new TimeStep(1, 0, false); LocationEntry le = new LocationEntry(key, "personName", "personGuid".ToStrGuid(), ts, "locname", "locguid".ToStrGuid()); DateStampCreator dsc = new DateStampCreator(calcParameters); using (OnlineLoggingData old = new OnlineLoggingData(dsc, wd.InputDataLogger, calcParameters)) { wd.InputDataLogger.AddSaver(new LocationEntryLogger(wd.SqlResultLoggingService)); old.AddLocationEntry(le); old.FinalSaveToDatabase(); } var lel = new LocationEntryLogger(wd.SqlResultLoggingService); var e = lel.Load(key); e.Count.Should().Be(1); wd.CleanUp(); } }
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 EnergyStorageLogfile([NotNull] CalcParameters calcParameters, [NotNull] FileFactoryAndTracker fft) { _fft = fft; _calcParameters = calcParameters; _dsc = new DateStampCreator(calcParameters); _writeHeader = true; //_makeLogFile = _calcParameters.IsSet(CalcOption.EnergyStorageFile) }
public TemperatureDataLogger([NotNull] SqlResultLoggingService srls, [NotNull] CalcParameters calcParameters) : base( typeof(TemperatureProfile), new ResultTableDefinition("Temperatures", ResultTableID.Temperatures, "Used Temperatures", CalcOption.TemperatureFile), srls) { _srls = srls; _calcParameters = calcParameters; }
public DesiresLogFile([NotNull] FileFactoryAndTracker fft, [NotNull] CalcParameters calcParameters) { _fft = fft; _calcParameters = calcParameters; _desireFiles = new Dictionary <string, StreamWriter>(); _writeDesiresHeader = new Dictionary <string, bool>(); _dsc = new DateStampCreator(calcParameters); }
public CalcAffordanceDtoFactory([NotNull] CalcParameters cp, [NotNull] IDeviceCategoryPicker picker, [NotNull] CalcVariableDtoFactory variableRepository, [NotNull] AvailabilityDtoRepository availabilityDtoRepository) { _cp = cp; _picker = picker; _variableRepository = variableRepository; _availabilityDtoRepository = availabilityDtoRepository; }
public ProfileActivationEntry([NotNull] string device, [NotNull] string profile, [NotNull] string profileSource, [NotNull] string loadType, [NotNull] CalcParameters calcParameters) { _calcParameters = calcParameters; Device = device; Profile = profile; ProfileSource = profileSource; LoadType = loadType; ActivationCount = 0; }
//[NotNull] //private readonly CalcStartParameterSet _csps; //[NotNull] //private readonly CalculationResult _results; public DatFileDeletor(//[NotNull] CalculationResult results, [NotNull] CalcParameters parameters, //[NotNull][ItemNotNull] ObservableCollection<CalculationEntry> calculationEntries, [NotNull] string resultPath, [NotNull] string calcObjectName) { CalcObjectName = calcObjectName; //_results = results; //_calculationEntries = calculationEntries; _resultPath = resultPath; _deleteDatFiles = parameters.DeleteDatFiles; }
private static void CheckTimeResolution([NotNull] CalcParameters calcParameters) { int internalseconds = (int)calcParameters.InternalStepsize.TotalSeconds; int externalseconds = (int)calcParameters.ExternalStepsize.TotalSeconds; if (externalseconds % internalseconds != 0) { throw new DataIntegrityException( "The external time resolution needs to be an even multiple of the internal time resolution."); } }
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)); }
//[ItemNotNull] //[NotNull] //private List<OnlineDeviceStateMachine> _statemachines = new List<OnlineDeviceStateMachine>(); public OnlineDeviceActivationProcessor(IOnlineLoggingData old, [NotNull] CalcParameters calcParameters, [NotNull] FileFactoryAndTracker fft) { _old = old; _calcParameters = calcParameters; Oefc = new OnlineEnergyFileColumns(old); _loadTypeDict = new Dictionary <CalcLoadTypeDto, int>(); _fft = fft; _binaryOutStreams = new Dictionary <CalcLoadTypeDto, BinaryWriter>(); _sumBinaryOutStreams = new Dictionary <CalcLoadTypeDto, BinaryWriter>(); Logger.Info("Initializing the online device activation processor..."); }
public DeviceProfiles([JetBrains.Annotations.NotNull] ChartCreationParameters parameters, [JetBrains.Annotations.NotNull] FileFactoryAndTracker fft, [JetBrains.Annotations.NotNull] ICalculationProfiler calculationProfiler, [JetBrains.Annotations.NotNull] SqlResultLoggingService srls, CalcParameters calcParameters) : base(parameters, fft, calculationProfiler, new List <ResultFileID>() { ResultFileID.DeviceProfileCSV }, "Device Profiles", FileProcessingResult.ShouldCreateFiles ) { _srls = srls; _calcParameters = calcParameters; }
public override void Run(HouseholdKey key, object o) { CalcParameters calcParameters = (CalcParameters)o; SaveableEntry se = GetStandardSaveableEntry(key); se.AddRow(RowBuilder.Start("Name", "CalcParameters").Add("Json", JsonConvert.SerializeObject(calcParameters, Formatting.Indented)).ToDictionary()); if (Srls == null) { throw new LPGException("Data Logger was null."); } Srls.SaveResultEntry(se); }
public CalcDeviceDtoFactory([NotNull] IDeviceCategoryPicker picker, [NotNull] CalcParameters calcParameters, [NotNull] Random rnd, [NotNull] CalcLoadTypeDtoDictionary loadTypeDictionary, [NotNull] CalcVariableDtoFactory calcVariableRepositoryDtoFactory, [NotNull] AvailabilityDtoRepository availabilityDtoRepository) { _picker = picker; _calcParameters = calcParameters; _rnd = rnd; _loadTypeDictionary = loadTypeDictionary; _calcVariableRepositoryDtoFactory = calcVariableRepositoryDtoFactory; _availabilityDtoRepository = availabilityDtoRepository; }
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 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(); } }