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 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 static CalcParameters MakeGoodDefaults() { CalcParameters cp = CalcParameters.GetNew(); cp.SetStartDate(2018, 1, 1).SetEndDate(2018, 12, 31); cp.SetInternalTimeResolution(new TimeSpan(0, 1, 0)).SetExternalTimeResolution(new TimeSpan(0, 1, 0)); cp.SetCsvCharacter(";"); cp.SetLoadTypePriority(LoadTypePriority.RecommendedForHouses); cp.DisableShowSettlingPeriod(); cp.SetSettlingDays(3); cp.SetRandomSeed(17,false); cp.SetWriteExcelColumn(false); cp.SetAffordanceRepetitionCount(3); cp.CheckSettings(); return cp; }
public CalcParameters MakeCalculationParametersFromConfig([NotNull] CalcStartParameterSet csps, bool forceRandom) { CalcParameters cp = CalcParameters.GetNew(); cp.LoadtypesToPostprocess = csps.LoadTypesToProcess; cp.SetDeleteDatFiles(csps.DeleteDatFiles); cp.SetWriteExcelColumn (csps.WriteExcelColumn); cp.SetManyOptionsWithClear(csps.CalcOptions); FileFactoryAndTrackerDummy fftd = new FileFactoryAndTrackerDummy(); var container =PostProcessingManager.RegisterEverything(csps.ResultPath,csps.CalculationProfiler, fftd); using (var scope = container.BeginLifetimeScope()) { var odm = scope.Resolve<OptionDependencyManager>(); odm.EnableRequiredOptions(cp.Options); } cp.SetShowSettlingPeriod(csps.ShowSettlingPeriod); cp.SetRandomSeed(csps.SelectedRandomSeed, forceRandom); cp.SetCsvCharacter(csps.CsvCharacter); cp.SetStartDate(csps.OfficialSimulationStartTime); cp.SetEndDate(csps.OfficialSimulationEndTime.AddDays(1)); cp.SetInternalTimeResolution(csps.InternalTimeResolution); cp.SetExternalTimeResolution(csps.ExternalTimeResolution); cp.SetLoadTypePriority(csps.LoadTypePriority); cp.SetSettlingDays(csps.SettlingDays); cp.SetAffordanceRepetitionCount(csps.AffordanceRepetitionCount); cp.DeviceProfileHeaderMode = csps.DeviceProfileHeaderMode; cp.IgnorePreviousActivitesWhenNeeded = csps.IgnorePreviousActivitiesWhenNeeded; cp.TransportationEnabled = csps.TransportationEnabled; if (cp.TransportationEnabled && csps.CalcTarget.CalcObjectType == CalcObjectType.House) { if (csps.ChargingStationSet != null) { throw new LPGException("trying to set transportation options on a house. that won't work."); } if (csps.TransportationDeviceSet != null) { throw new LPGException("trying to set transportation options on a house. that won't work."); } if (csps.TravelRouteSet != null) { throw new LPGException("trying to set transportation options on a house. that won't work."); } } if (cp.TransportationEnabled && csps.CalcTarget.CalcObjectType == CalcObjectType.ModularHousehold) { if (csps.ChargingStationSet == null) { throw new LPGException("Trying to set transportation options on a household without charging station set. That won't work."); } if (csps.TransportationDeviceSet == null) { throw new LPGException("Trying to set transportation options on a household without transportation device set. That won't work."); } if (csps.TravelRouteSet != null) { throw new LPGException("trying to set transportation options on a house. that won't work."); } } cp.CheckSettings(); //transport mode /*if (csps.TransportationDeviceSet != null || csps.TravelRouteSet != null) { cp.SetTransportMode(true); if (csps.TransportationDeviceSet == null ) { throw new DataIntegrityException("Only a transportation device set was defined, but not a travel route set. This can't work."); } if (csps.TravelRouteSet == null) { throw new DataIntegrityException("Only a travel route set was defined, but not a transportation device set. This can't work."); } }*/ return cp; }