Skip to content

Commit

Permalink
More work on #2569 to make test pass again:
Browse files Browse the repository at this point in the history
  • Loading branch information
msevestre committed Mar 21, 2023
1 parent f381c8d commit a561ed1
Show file tree
Hide file tree
Showing 31 changed files with 179 additions and 129 deletions.
4 changes: 2 additions & 2 deletions src/PKSim.Assets.Images/PKSim.Assets.Images.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OSPSuite.Assets" Version="12.0.0-USVFq" />
<PackageReference Include="OSPSuite.Assets.Images" Version="12.0.0-USVFq" />
<PackageReference Include="OSPSuite.Assets" Version="12.0.140" />
<PackageReference Include="OSPSuite.Assets.Images" Version="12.0.140" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/PKSim.Assets/PKSim.Assets.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OSPSuite.Assets" Version="12.0.0-USVFq" />
<PackageReference Include="OSPSuite.Assets.Images" Version="12.0.0-USVFq" />
<PackageReference Include="OSPSuite.Assets" Version="12.0.140" />
<PackageReference Include="OSPSuite.Assets.Images" Version="12.0.140" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/PKSim.BatchTool/PKSim.BatchTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OSPSuite.Core" Version="12.0.0-USVFq" />
<PackageReference Include="OSPSuite.Assets" Version="12.0.0-USVFq" />
<PackageReference Include="OSPSuite.Core" Version="12.0.140" />
<PackageReference Include="OSPSuite.Assets" Version="12.0.140" />
<PackageReference Include="OSPSuite.DevExpress" Version="21.2.3" />
<PackageReference Include="OSPSuite.FuncParser" Version="4.0.0.54" GeneratePathProperty="true" />
<PackageReference Include="OSPSuite.SimModel" Version="4.0.0.53" GeneratePathProperty="true" />
Expand Down
4 changes: 2 additions & 2 deletions src/PKSim.CLI.Core/PKSim.CLI.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OSPSuite.Assets" Version="12.0.0-USVFq" />
<PackageReference Include="OSPSuite.Assets" Version="12.0.140" />
<PackageReference Include="OSPSuite.Utility" Version="4.0.0.4" />
<PackageReference Include="OSPSuite.Core" Version="12.0.0-USVFq" />
<PackageReference Include="OSPSuite.Core" Version="12.0.140" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions src/PKSim.CLI/PKSim.CLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.8.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.0" />
<PackageReference Include="OSPSuite.Core" Version="12.0.0-USVFq" />
<PackageReference Include="OSPSuite.Presentation" Version="12.0.0-USVFq" />
<PackageReference Include="OSPSuite.Assets" Version="12.0.0-USVFq" />
<PackageReference Include="OSPSuite.Core" Version="12.0.140" />
<PackageReference Include="OSPSuite.Presentation" Version="12.0.140" />
<PackageReference Include="OSPSuite.Assets" Version="12.0.140" />
<PackageReference Include="OSPSuite.Utility" Version="4.0.0.4" />
<PackageReference Include="OSPSuite.FuncParser" Version="4.0.0.54" GeneratePathProperty="true" />
<PackageReference Include="OSPSuite.SimModel" Version="4.0.0.53" GeneratePathProperty="true" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using OSPSuite.Core.Domain.Services;
using PKSim.Assets;
using PKSim.Core.Model;
using PKSim.Core.Services;
using ILazyLoadTask = OSPSuite.Core.Domain.Services.ILazyLoadTask;

namespace PKSim.Core.Mappers
{
Expand All @@ -14,8 +16,8 @@ public interface IExpressionProfileToExpressionProfileBuildingBlockMapper : IPat

public class ExpressionProfileToExpressionProfileBuildingBlockMapper : PathAndValueBuildingBlockMapper<ExpressionProfile, ExpressionProfileBuildingBlock, ExpressionParameter>, IExpressionProfileToExpressionProfileBuildingBlockMapper
{
public ExpressionProfileToExpressionProfileBuildingBlockMapper(IObjectBaseFactory objectBaseFactory, IEntityPathResolver entityPathResolver, IApplicationConfiguration applicationConfiguration, ILazyLoadTask lazyLoadTask) :
base(objectBaseFactory, entityPathResolver, applicationConfiguration, lazyLoadTask)
public ExpressionProfileToExpressionProfileBuildingBlockMapper(IObjectBaseFactory objectBaseFactory, IEntityPathResolver entityPathResolver, IApplicationConfiguration applicationConfiguration, ILazyLoadTask lazyLoadTask, ICloner cloner) :
base(objectBaseFactory, entityPathResolver, applicationConfiguration, lazyLoadTask, cloner)
{
}

Expand Down
34 changes: 18 additions & 16 deletions src/PKSim.Core/Mappers/IndividualToIndividualBuildingBlockMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using PKSim.Assets;
using PKSim.Core.Model;
using PKSim.Core.Repositories;
using PKSim.Core.Services;
using ILazyLoadTask = OSPSuite.Core.Domain.Services.ILazyLoadTask;

namespace PKSim.Core.Mappers
{
Expand All @@ -21,7 +23,7 @@ public class IndividualToIndividualBuildingBlockMapper : PathAndValueBuildingBlo
private readonly ICalculationMethodCategoryRepository _calculationMethodCategoryRepository;

public IndividualToIndividualBuildingBlockMapper(IObjectBaseFactory objectBaseFactory, IEntityPathResolver entityPathResolver, IApplicationConfiguration applicationConfiguration,
ILazyLoadTask lazyLoadTask, IRepresentationInfoRepository representationInfoRepository, ICalculationMethodCategoryRepository calculationMethodCategoryRepository) : base(objectBaseFactory, entityPathResolver, applicationConfiguration, lazyLoadTask)
ILazyLoadTask lazyLoadTask, IRepresentationInfoRepository representationInfoRepository, ICalculationMethodCategoryRepository calculationMethodCategoryRepository, ICloner cloner) : base(objectBaseFactory, entityPathResolver, applicationConfiguration, lazyLoadTask, cloner)
{
_representationInfoRepository = representationInfoRepository;
_calculationMethodCategoryRepository = calculationMethodCategoryRepository;
Expand All @@ -32,25 +34,25 @@ protected override IReadOnlyList<IParameter> AllParametersFor(Individual individ
return individual.GetAllChildren<IParameter>().Where(x => x.GroupName != CoreConstants.Groups.RELATIVE_EXPRESSION).ToList();
}

public override IndividualBuildingBlock MapFrom(Individual input)
public override IndividualBuildingBlock MapFrom(Individual individual)
{
var buildingBlock = base.MapFrom(input);
buildingBlock.Icon = input.Icon;
var buildingBlock = base.MapFrom(individual);
buildingBlock.Icon = individual.Icon;

addOriginDataToBuildingBlock(buildingBlock, PKSimConstants.UI.DiseaseState, input.OriginData.DiseaseState?.DisplayName);
addOriginDataToBuildingBlock(buildingBlock, PKSimConstants.UI.Species, input.Species?.DisplayName);
addOriginDataToBuildingBlock(buildingBlock, PKSimConstants.UI.Gender, input.OriginData.Gender?.DisplayName);
addOriginDataToBuildingBlock(buildingBlock, PKSimConstants.UI.Age, input.OriginData.Age);
addOriginDataToBuildingBlock(buildingBlock, PKSimConstants.UI.GestationalAge, input.OriginData.GestationalAge);
addOriginDataToBuildingBlock(buildingBlock, PKSimConstants.UI.Height, input.OriginData.Height);
addOriginDataToBuildingBlock(buildingBlock, PKSimConstants.UI.BMI, input.OriginData.BMI);
addOriginDataToBuildingBlock(buildingBlock, PKSimConstants.UI.Weight, input.OriginData.Weight);
addOriginDataToBuildingBlock(buildingBlock, PKSimConstants.UI.Population, input.OriginData.Population?.DisplayName);
addOriginDataToBuildingBlock(buildingBlock, PKSimConstants.UI.DiseaseState, individual.OriginData.DiseaseState?.DisplayName);
addOriginDataToBuildingBlock(buildingBlock, PKSimConstants.UI.Species, individual.Species?.DisplayName);
addOriginDataToBuildingBlock(buildingBlock, PKSimConstants.UI.Gender, individual.OriginData.Gender?.DisplayName);
addOriginDataToBuildingBlock(buildingBlock, PKSimConstants.UI.Age, individual.OriginData.Age);
addOriginDataToBuildingBlock(buildingBlock, PKSimConstants.UI.GestationalAge, individual.OriginData.GestationalAge);
addOriginDataToBuildingBlock(buildingBlock, PKSimConstants.UI.Height, individual.OriginData.Height);
addOriginDataToBuildingBlock(buildingBlock, PKSimConstants.UI.BMI, individual.OriginData.BMI);
addOriginDataToBuildingBlock(buildingBlock, PKSimConstants.UI.Weight, individual.OriginData.Weight);
addOriginDataToBuildingBlock(buildingBlock, PKSimConstants.UI.Population, individual.OriginData.Population?.DisplayName);

input.OriginData.AllCalculationMethods().Where(cm => _calculationMethodCategoryRepository.HasMoreThanOneOption(cm, input.Species))
individual.OriginData.AllCalculationMethods().Where(cm => _calculationMethodCategoryRepository.HasMoreThanOneOption(cm, individual.Species))
.Each(x => addCalculationMethodOriginDataToBuildingBlock(buildingBlock, x));

buildingBlock.OriginData.ValueOrigin = input.OriginData.ValueOrigin.Clone();
buildingBlock.OriginData.ValueOrigin = individual.OriginData.ValueOrigin.Clone();

return buildingBlock;
}
Expand Down Expand Up @@ -79,7 +81,7 @@ private void addOriginDataToBuildingBlock(IndividualBuildingBlock buildingBlock,
if (string.IsNullOrEmpty(value))
return;

buildingBlock.OriginData.AddOriginDataItem(new OriginDataItem { Name = key, Value = value });
buildingBlock.OriginData.AddOriginDataItem(new OriginDataItem {Name = key, Value = value});
}
}
}
68 changes: 41 additions & 27 deletions src/PKSim.Core/Mappers/PathAndValueBuildingBlockMapper.cs
Original file line number Diff line number Diff line change
@@ -1,36 +1,51 @@
using System.Collections.Generic;
using System.Linq;
using OSPSuite.Core;
using OSPSuite.Core.Domain;
using OSPSuite.Core.Domain.Builder;
using OSPSuite.Core.Domain.Formulas;
using OSPSuite.Core.Domain.Services;
using OSPSuite.Utility;
using OSPSuite.Utility.Collections;
using OSPSuite.Utility.Extensions;
using PKSim.Core.Model;
using PKSim.Core.Services;
using ILazyLoadTask = OSPSuite.Core.Domain.Services.ILazyLoadTask;

namespace PKSim.Core.Mappers
{
public interface IPathAndValueBuildingBlockMapper<in T, out TBuildingBlock> : IMapper<T, TBuildingBlock>
public interface IPathAndValueBuildingBlockMapper<in TPKSimBuildingBlock, out TBuildingBlock> : IMapper<TPKSimBuildingBlock, TBuildingBlock>
{
}

public abstract class PathAndValueBuildingBlockMapper<T, TBuildingBlock, TBuilder> : IPathAndValueBuildingBlockMapper<T, TBuildingBlock> where T : PKSimBuildingBlock where TBuildingBlock : PathAndValueEntityBuildingBlockFromPKSim<TBuilder> where TBuilder : PathAndValueEntity
public abstract class PathAndValueBuildingBlockMapper<TPKSimBuildingBlock, TBuildingBlock, TBuilder> : IPathAndValueBuildingBlockMapper<TPKSimBuildingBlock, TBuildingBlock> where TPKSimBuildingBlock : PKSimBuildingBlock where TBuildingBlock : PathAndValueEntityBuildingBlockFromPKSim<TBuilder>
where TBuilder : PathAndValueEntity
{
protected IObjectBaseFactory _objectBaseFactory;
protected IEntityPathResolver _entityPathResolver;
protected IApplicationConfiguration _applicationConfiguration;
private readonly ILazyLoadTask _lazyLoadTask;
private readonly ICloner _cloner;

//Cache used to store all formula that can be cached. This is required to avoid having the same formula defined multiple times in the building block
//note that a clone of the original formula is added to the cache so that it can be modified if required
private readonly Cache<string, IFormula> _formulaCache = new Cache<string, IFormula>(x => x.Name);

protected PathAndValueBuildingBlockMapper(IObjectBaseFactory objectBaseFactory, IEntityPathResolver entityPathResolver, IApplicationConfiguration applicationConfiguration, ILazyLoadTask lazyLoadTask)
protected PathAndValueBuildingBlockMapper(
IObjectBaseFactory objectBaseFactory,
IEntityPathResolver entityPathResolver,
IApplicationConfiguration applicationConfiguration,
ILazyLoadTask lazyLoadTask,
ICloner cloner)
{
_objectBaseFactory = objectBaseFactory;
_entityPathResolver = entityPathResolver;
_applicationConfiguration = applicationConfiguration;
_lazyLoadTask = lazyLoadTask;
_cloner = cloner;
}

protected TBuildingBlock CreateBaseObject(T pkSimBuildingBlock)
protected TBuildingBlock CreateBaseObject(TPKSimBuildingBlock pkSimBuildingBlock)
{
var buildingBlock = _objectBaseFactory.Create<TBuildingBlock>();

Expand All @@ -43,12 +58,16 @@ protected TBuildingBlock CreateBaseObject(T pkSimBuildingBlock)
private TBuilder mapBuilderParameter(IParameter parameter)
{
var builderParameter = _objectBaseFactory.Create<TBuilder>();
builderParameter.Name = parameter.Name;
builderParameter.Path = _entityPathResolver.ObjectPathFor(parameter);
builderParameter.Dimension = parameter.Dimension;
builderParameter.DisplayUnit = parameter.DisplayUnit;

// 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);
_formulaCache.Add(cloneFormulaForExport(parameter));

// 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
Expand All @@ -63,14 +82,16 @@ private TBuilder mapBuilderParameter(IParameter parameter)
builderParameter.Value = getParameterValue(parameter);
}

builderParameter.Name = parameter.Name;

builderParameter.Path = _entityPathResolver.ObjectPathFor(parameter);
builderParameter.Dimension = parameter.Dimension;
builderParameter.DisplayUnit = parameter.DisplayUnit;
return builderParameter;
}

private IFormula cloneFormulaForExport(IParameter parameter)
{
var cloneFormula = _cloner.Clone(parameter.Formula);
cloneFormula.ObjectPaths.Each(x => x.Remove(Constants.ROOT));
return cloneFormula;
}

private static bool isFormulaCachable(IParameter parameter)
{
return parameter.Formula != null && parameter.Formula.IsCachable();
Expand All @@ -81,30 +102,23 @@ private static double getParameterValue(IParameter parameter)
return parameter.TryGetValue().value;
}

protected void MapAllParameters(T sourcePKSimBuildingBlock, TBuildingBlock buildingBlock)
protected void MapAllParameters(TPKSimBuildingBlock sourcePKSimBuildingBlock, TBuildingBlock buildingBlock)
{
var allParameters = AllParametersFor(sourcePKSimBuildingBlock);
var allBuilderParameters = AllParametersFor(sourcePKSimBuildingBlock).Select(mapBuilderParameter);
allBuilderParameters.Each(buildingBlock.Add);

foreach (var parameter in allParameters)
{
var builderParameter = mapBuilderParameter(parameter);
buildingBlock.Add(builderParameter);
}

foreach (var formula in _formulaCache)
{
buildingBlock.FormulaCache.Add(formula);
}
//Formula cache already contains a clone of all formula. We can add as is
_formulaCache.Each(buildingBlock.FormulaCache.Add);
}

protected abstract IReadOnlyList<IParameter> AllParametersFor(T sourcePKSimBuildingBlock);
protected abstract IReadOnlyList<IParameter> AllParametersFor(TPKSimBuildingBlock sourcePKSimBuildingBlock);

public virtual TBuildingBlock MapFrom(T input)
public virtual TBuildingBlock MapFrom(TPKSimBuildingBlock pkSimBuildingBlock)
{
_lazyLoadTask.Load(input);
_lazyLoadTask.Load(pkSimBuildingBlock);

var buildingBlock = CreateBaseObject(input);
MapAllParameters(input, buildingBlock);
var buildingBlock = CreateBaseObject(pkSimBuildingBlock);
MapAllParameters(pkSimBuildingBlock, buildingBlock);
return buildingBlock;
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/PKSim.Core/Model/PKSimSpatialStructureFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,6 @@ private void addModelStructureTo(IContainer container, OriginData originData, Mo
}
}

protected override ISpatialStructure CreateSpatialStructure()
{
return _objectBaseFactory.Create<IPKSimSpatialStructure>();
}
protected override ISpatialStructure CreateSpatialStructure() => _objectBaseFactory.Create<IPKSimSpatialStructure>();
}
}
8 changes: 4 additions & 4 deletions src/PKSim.Core/PKSim.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="OSPSuite.Utility" Version="4.0.0.4" />
<PackageReference Include="OSPSuite.Core" Version="12.0.0-USVFq" />
<PackageReference Include="OSPSuite.Assets" Version="12.0.0-USVFq" />
<PackageReference Include="OSPSuite.Assets.Images" Version="12.0.0-USVFq" />
<PackageReference Include="OSPSuite.Infrastructure.Import" Version="12.0.0-USVFq" />
<PackageReference Include="OSPSuite.Core" Version="12.0.140" />
<PackageReference Include="OSPSuite.Assets" Version="12.0.140" />
<PackageReference Include="OSPSuite.Assets.Images" Version="12.0.140" />
<PackageReference Include="OSPSuite.Infrastructure.Import" Version="12.0.140" />
<PackageReference Include="System.ComponentModel.Annotations" Version="4.7.0" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/PKSim.Core/Services/Cloner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public Cloner(ICloneManagerForModel cloneManagerForModel, ICloneManagerForBuildi

public T Clone<T>(T objectToClone) where T : class, IUpdatable
{
//formula cache are never used in pksim explicitely. And if need, we access CloneManagerForBuildingBlock
//formula cache are never used in pksim explicitly. And if need, we access CloneManagerForBuildingBlock
_cloneManagerForBuildingBlock.FormulaCache = new FormulaCache();
return createClone(objectToClone, _cloneManagerForBuildingBlock);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private void updateAgeParameter(SimulationConfiguration simulationConfiguration)
{
var spatialStructure = simulationConfiguration.SpatialStructure;
//We have only one in PK-Sim
var parameterStartValueBuildingBlock = simulationConfiguration.ParameterStartValuesCollection.First();
var parameterStartValueBuildingBlock = simulationConfiguration.ParameterStartValues;
var organism = spatialStructure.TopContainers.FindByName(Constants.ORGANISM);
var ageParameter = organism.Parameter(CoreConstants.Parameters.AGE);
var minToYearFactor = _timeDimension.BaseUnitValueToUnitValue(_yearUnit, 1);
Expand Down Expand Up @@ -199,7 +199,7 @@ private void createSpatialStructureTableParameters(SimulationConfiguration simul
private void createOntogenyTableParameters(SimulationConfiguration simulationConfiguration)
{
var simulationPopulation = _simulation as PopulationSimulation;
var parameterStartValueBuildingBlock = simulationConfiguration.ParameterStartValuesCollection.First();
var parameterStartValueBuildingBlock = simulationConfiguration.ParameterStartValues;
foreach (var molecule in _baseIndividual.AllMolecules().Where(m => m.Ontogeny.IsDefined()))
{
var ontogenyFactorPath = _entityPathResolver.ObjectPathFor(molecule.OntogenyFactorParameter);
Expand Down
Loading

0 comments on commit a561ed1

Please sign in to comment.