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); } }
private void MakeAllTransformationDevices([NotNull] CalcHouseDto house, [NotNull] CalcHouse calchouse, [NotNull] HouseholdKey householdKey) //List<CalcDeviceTaggingSet> taggingSets, { var ctds = new List <CalcTransformationDevice>(); var devcategoryGuid = Guid.NewGuid().ToStrGuid(); var trafolocGuid = Guid.NewGuid().ToStrGuid(); foreach (var trafo in house.TransformationDevices) { foreach (var set in _calcDeviceTaggingSets.AllCalcDeviceTaggingSets) { set.AddTag(trafo.Name, "House Device"); } CalcDeviceDto cdd = new CalcDeviceDto(trafo.Name, devcategoryGuid, householdKey, OefcDeviceType.Transformation, "Transformation Devices", "", trafo.Guid, trafolocGuid, "Transformation Devices"); var ctd = new CalcTransformationDevice(_calcRepo.Odap, trafo.MinValue, trafo.MaxValue, trafo.MinPower, trafo.MaxPower, cdd, _ltDict.GetLoadtypeByGuid(trafo.InputLoadType.Guid)); foreach (var outlt in trafo.OutputLoadTypes) { ctd.AddOutputLoadType(_ltDict.GetLoadtypeByGuid(outlt.LoadType.Guid), outlt.ValueScalingFactor, outlt.FactorType); } if (ctd.OutputLoadTypes.Count > 0) { if (trafo.Datapoints != null) { foreach (var datapoint in trafo.Datapoints) { ctd.AddDatapoint(datapoint.Ref, datapoint.Val); } } foreach (var condition in trafo.Conditions) { var variable = _variableRepository.GetVariableByGuid(condition.CalcVariableDto.Guid); ctd.AddCondition(condition.Name, variable, condition.MinValue, condition.MaxValue, condition.Guid); } ctds.Add(ctd); } } calchouse.SetTransformationDevices(ctds); }