Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #2552 Export of Expression profile to PKML - include initial co… #2554

Merged
merged 1 commit into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions src/PKSim.Core/Mappers/PathAndValueBuildingBlockMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,23 @@ private TBuilder mapBuilderParameter(IParameter parameter)
{
var builderParameter = _objectBaseFactory.Create<TBuilder>();

if (parameter.Formula != null && parameter.Formula.IsCachable())
// Add the formula to the building block formula cache if the formula can be cached
if (isFormulaCachable(parameter))
{
if (!_formulaCache.Contains(parameter.Formula.Name))
_formulaCache.Add(parameter.Formula);

builderParameter.Formula = _formulaCache[parameter.Formula.Name];
// If the parameter value is different from the default value, set the value only and not the formula
// If the parameter value is not different from the default, set the formula only and not the value
// Even if the formula is not be used by the builder parameter, the cache will have the formula available
if (parameter.ValueDiffersFromDefault())
builderParameter.Value = getParameterValue(parameter);
else
builderParameter.Formula = _formulaCache[parameter.Formula.Name];
}
else
{
(builderParameter.Value, _) = parameter.TryGetValue();
builderParameter.Value = getParameterValue(parameter);
}

builderParameter.Name = parameter.Name;
Expand All @@ -64,6 +71,16 @@ private TBuilder mapBuilderParameter(IParameter parameter)
return builderParameter;
}

private static bool isFormulaCachable(IParameter parameter)
{
return parameter.Formula != null && parameter.Formula.IsCachable();
}

private static double getParameterValue(IParameter parameter)
{
return parameter.TryGetValue().value;
}

protected void MapAllParameters(T sourcePKSimBuildingBlock, TBuildingBlock buildingBlock)
{
var allParameters = AllParametersFor(sourcePKSimBuildingBlock);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FakeItEasy;
using System.Linq;
using FakeItEasy;
using OSPSuite.BDDHelper;
using OSPSuite.BDDHelper.Extensions;
using OSPSuite.Core;
Expand Down Expand Up @@ -27,7 +28,7 @@ protected override void Context()
_objectPathFactory = new EntityPathResolverForSpecs();
_lazyLoadTask = A.Fake<ILazyLoadTask>();
A.CallTo(() => _objectBaseFactory.Create<ExpressionProfileBuildingBlock>()).Returns(new ExpressionProfileBuildingBlock());
A.CallTo(() => _objectBaseFactory.Create<ExpressionParameter>()).Returns(new ExpressionParameter());
A.CallTo(() => _objectBaseFactory.Create<ExpressionParameter>()).ReturnsLazily(() => new ExpressionParameter());

sut = new ExpressionProfileToExpressionProfileBuildingBlockMapper(_objectBaseFactory, _objectPathFactory, _applicationConfiguration, _lazyLoadTask);
}
Expand Down Expand Up @@ -84,13 +85,25 @@ protected override void Context()
Category = "TestCategory",
Description = "TestDescription"
};

_expressionProfile.GetAllChildren<IParameter>().First().Value = 99;
var parameter = _expressionProfile.GetAllChildren<IParameter>().Last();
parameter.Value = 99;
parameter.Formula = null;
}

protected override void Because()
{
_result = sut.MapFrom(_expressionProfile);
}

[Observation]
public void resulting_expression_parameter_should_have_formula_or_value()
{
_result.Count(x => x.Formula == null).ShouldBeEqualTo(2);
_result.Count(x => x.Formula != null).ShouldBeEqualTo(1);
}

[Observation]
public void resulting_building_block_should_have_the_correct_values()
{
Expand All @@ -100,7 +113,7 @@ public void resulting_building_block_should_have_the_correct_values()
_result.MoleculeName.ShouldBeEqualTo("TestEnzyme");
_result.Type.DisplayName.ShouldBeEqualTo("Enzyme");
_result.Type.IconName.ShouldBeEqualTo("Enzyme");
_result.FormulaCache.Count.ShouldBeEqualTo(3);
_result.FormulaCache.Count.ShouldBeEqualTo(2);
}
}
}