From 1a3d853d999b954882e3358e57d7032b3b79fe93 Mon Sep 17 00:00:00 2001 From: Michael Sevestre Date: Tue, 14 Mar 2023 19:36:54 -0400 Subject: [PATCH] Fixes #2536 loading project from snapshot observed data --- src/PKSim.Core/Services/IChartTask.cs | 36 +++++++++++++++++++ .../Snapshots/Mappers/SimulationMapper.cs | 6 +++- .../Services/ChartTask.cs | 17 +++++---- .../Services/ChartTemplatingTask.cs | 1 + src/PKSim.Presentation/Services/IChartTask.cs | 22 ------------ .../Views/Charts/PKSimChartFactory.cs | 1 + .../PKSim.Tests/Core/SimulationMapperSpecs.cs | 16 ++++++--- .../ChartTemplatingTaskSpecs.cs | 3 +- .../SimulationChartsLoaderSpecs.cs | 2 +- .../Presentation/ChartTaskSpecs.cs | 1 + ...idualSimulationComparisonPresenterSpecs.cs | 1 + .../Presentation/PKSimChartFactorySpecs.cs | 1 + ...imulationTimeProfileChartPresenterSpecs.cs | 1 + 13 files changed, 70 insertions(+), 38 deletions(-) create mode 100644 src/PKSim.Core/Services/IChartTask.cs delete mode 100644 src/PKSim.Presentation/Services/IChartTask.cs diff --git a/src/PKSim.Core/Services/IChartTask.cs b/src/PKSim.Core/Services/IChartTask.cs new file mode 100644 index 000000000..6157c96fa --- /dev/null +++ b/src/PKSim.Core/Services/IChartTask.cs @@ -0,0 +1,36 @@ +using OSPSuite.Core.Chart; +using OSPSuite.Core.Domain; +using OSPSuite.Core.Domain.Data; +using PKSim.Core.Model; + +namespace PKSim.Core.Services +{ + public interface IChartTask + { + /// + /// updates all observed data defined in the simulation to the underlying charts of this simulation + /// + /// Simulation used to retrieve the charts to update + /// Optional project. If undefined, it will be retrieved from the project retriever + void UpdateObservedDataInChartsFor(Simulation simulation, IProject project = null); + + /// + /// adds all observed data defined in the simulation to + /// + /// Simulation used to retrieve the charts to update>> + /// Chart where observed data should be updated + /// Optional project. If undefined, it will be retrieved from the project retriever + void UpdateObservedDataInChartFor(Simulation simulation, ChartWithObservedData chartWithObservedData, IProject project = null); + + /// + /// Returns if the column should be displayed or not + /// + bool IsColumnVisibleInDataBrowser(DataColumn dataColumn); + + /// + /// Sets origin data for the to indicate project name , and + /// current date/time + /// + void SetOriginTextFor(string simulationName, IChart chart); + } +} \ No newline at end of file diff --git a/src/PKSim.Core/Snapshots/Mappers/SimulationMapper.cs b/src/PKSim.Core/Snapshots/Mappers/SimulationMapper.cs index 513f75473..9338189c4 100644 --- a/src/PKSim.Core/Snapshots/Mappers/SimulationMapper.cs +++ b/src/PKSim.Core/Snapshots/Mappers/SimulationMapper.cs @@ -54,6 +54,7 @@ public class SimulationMapper : ObjectBaseSnapshotMapperBase MapToSnapshot(ModelSimulation simulation, PKSimProject project) @@ -305,6 +308,7 @@ public override async Task MapToModel(SnapshotSimulation snapsh simulation.AddAnalyses(await populationAnalysesFrom(simulation, snapshot.PopulationAnalyses, snapshotContext)); _simulationParameterOriginIdUpdater.UpdateSimulationId(simulation); + _chartTask.UpdateObservedDataInChartsFor(simulation, snapshotContext.Project); return simulation; } diff --git a/src/PKSim.Infrastructure/Services/ChartTask.cs b/src/PKSim.Infrastructure/Services/ChartTask.cs index 11a846d19..09d62a361 100644 --- a/src/PKSim.Infrastructure/Services/ChartTask.cs +++ b/src/PKSim.Infrastructure/Services/ChartTask.cs @@ -1,9 +1,10 @@ using OSPSuite.Core.Chart; +using OSPSuite.Core.Domain; using OSPSuite.Core.Domain.Data; using OSPSuite.Core.Domain.Services; -using OSPSuite.Utility.Container; using OSPSuite.Utility.Extensions; using PKSim.Core.Model; +using PKSim.Core.Services; using PKSim.Presentation.Services; namespace PKSim.Infrastructure.Services @@ -22,22 +23,20 @@ public void SetOriginTextFor(string simulationName, IChart chart) chart.SetOriginTextFor(_projectRetriever.CurrentProject.Name, simulationName); } - public void UpdateObservedDataInChartsFor(Simulation simulation) + public void UpdateObservedDataInChartsFor(Simulation simulation, IProject project = null) { - simulation.ChartWithObservedData.Each(c => UpdateObservedDataInChartFor(simulation, c)); + simulation.ChartWithObservedData.Each(c => UpdateObservedDataInChartFor(simulation, c, project)); } - public void UpdateObservedDataInChartFor(Simulation simulation, ChartWithObservedData chartWithObservedData) + public void UpdateObservedDataInChartFor(Simulation simulation, ChartWithObservedData chartWithObservedData, IProject project = null) { + var projectToUse = project ?? _projectRetriever.CurrentProject; foreach (var usedObservedData in simulation.UsedObservedData) { - chartWithObservedData.AddObservedData(_projectRetriever.CurrentProject.ObservedDataBy(usedObservedData.Id)); + chartWithObservedData.AddObservedData(projectToUse.ObservedDataBy(usedObservedData.Id)); } } - public bool IsColumnVisibleInDataBrowser(DataColumn dataColumn) - { - return !dataColumn.IsBaseGrid(); - } + public bool IsColumnVisibleInDataBrowser(DataColumn dataColumn) => !dataColumn.IsBaseGrid(); } } \ No newline at end of file diff --git a/src/PKSim.Infrastructure/Services/ChartTemplatingTask.cs b/src/PKSim.Infrastructure/Services/ChartTemplatingTask.cs index a9ac6859e..02445bfcf 100644 --- a/src/PKSim.Infrastructure/Services/ChartTemplatingTask.cs +++ b/src/PKSim.Infrastructure/Services/ChartTemplatingTask.cs @@ -17,6 +17,7 @@ using PKSim.Core.Chart; using PKSim.Core.Commands; using PKSim.Core.Model; +using PKSim.Core.Services; using PKSim.Presentation.Services; namespace PKSim.Infrastructure.Services diff --git a/src/PKSim.Presentation/Services/IChartTask.cs b/src/PKSim.Presentation/Services/IChartTask.cs deleted file mode 100644 index fbe9752ec..000000000 --- a/src/PKSim.Presentation/Services/IChartTask.cs +++ /dev/null @@ -1,22 +0,0 @@ -using PKSim.Core.Model; -using OSPSuite.Core.Chart; -using OSPSuite.Core.Domain.Data; - -namespace PKSim.Presentation.Services -{ - public interface IChartTask - { - void UpdateObservedDataInChartsFor(Simulation simulation); - void UpdateObservedDataInChartFor(Simulation simulation, ChartWithObservedData chartWithObservedData); - - /// - /// Returns if the column should be displayed or not - /// - bool IsColumnVisibleInDataBrowser(DataColumn dataColumn); - - /// - /// Sets origin data for the to indicate project name , and current date/time - /// - void SetOriginTextFor(string simulationName, IChart chart); - } -} \ No newline at end of file diff --git a/src/PKSim.Presentation/Views/Charts/PKSimChartFactory.cs b/src/PKSim.Presentation/Views/Charts/PKSimChartFactory.cs index 837d46d2e..ee563f449 100644 --- a/src/PKSim.Presentation/Views/Charts/PKSimChartFactory.cs +++ b/src/PKSim.Presentation/Views/Charts/PKSimChartFactory.cs @@ -10,6 +10,7 @@ using OSPSuite.Utility.Extensions; using PKSim.Core.Chart; using PKSim.Core.Model; +using PKSim.Core.Services; using PKSim.Presentation.Services; namespace PKSim.Presentation.Views.Charts diff --git a/tests/PKSim.Tests/Core/SimulationMapperSpecs.cs b/tests/PKSim.Tests/Core/SimulationMapperSpecs.cs index 83d5de6b3..44f531dd8 100644 --- a/tests/PKSim.Tests/Core/SimulationMapperSpecs.cs +++ b/tests/PKSim.Tests/Core/SimulationMapperSpecs.cs @@ -5,7 +5,6 @@ using OSPSuite.BDDHelper.Extensions; using OSPSuite.Core.Domain; using OSPSuite.Core.Domain.Builder; -using OSPSuite.Core.Domain.ParameterIdentifications; using OSPSuite.Core.Domain.Services; using OSPSuite.Core.Extensions; using OSPSuite.Core.Services; @@ -17,11 +16,13 @@ using PKSim.Core.Services; using PKSim.Core.Snapshots; using PKSim.Core.Snapshots.Mappers; +using PKSim.Infrastructure.Services; using AdvancedParameter = PKSim.Core.Snapshots.AdvancedParameter; using Compound = PKSim.Core.Model.Compound; using CompoundProperties = PKSim.Core.Model.CompoundProperties; using DataRepository = OSPSuite.Core.Domain.Data.DataRepository; using Individual = PKSim.Core.Model.Individual; +using ModelOutputMapping = OSPSuite.Core.Domain.OutputMapping; using ObserverSet = PKSim.Core.Model.ObserverSet; using OutputSchema = OSPSuite.Core.Domain.OutputSchema; using OutputSelections = PKSim.Core.Snapshots.OutputSelections; @@ -29,9 +30,8 @@ using Protocol = PKSim.Core.Model.Protocol; using Simulation = PKSim.Core.Snapshots.Simulation; using SimulationRunOptions = PKSim.Core.Services.SimulationRunOptions; -using SolverSettings = OSPSuite.Core.Domain.SolverSettings; -using ModelOutputMapping = OSPSuite.Core.Domain.OutputMapping; using SnapshotOutputMapping = PKSim.Core.Snapshots.OutputMapping; +using SolverSettings = OSPSuite.Core.Domain.SolverSettings; namespace PKSim.Core { @@ -93,6 +93,7 @@ public abstract class concern_for_SimulationMapper : ContextSpecificationAsync(); _containerTask = A.Fake(); _entityPathResolver = A.Fake(); + _chartTask = A.Fake(); sut = new SimulationMapper(_solverSettingsMapper, _outputSchemaMapper, _outputSelectionMapper, _compoundPropertiesMapper, _parameterMapper, @@ -126,7 +128,7 @@ protected override Task Context() _simulationFactory, _executionContext, _simulationModelCreator, _simulationBuildingBlockUpdater, _modelPropertiesTask, _simulationRunner, _simulationParameterOriginIdUpdater, - _logger, _containerTask, _entityPathResolver + _logger, _containerTask, _entityPathResolver, _chartTask ); _project = new PKSimProject(); @@ -654,6 +656,12 @@ public void should_update_the_altered_flag_for_each_altered_building_block() { _simulation.UsedBuildingBlockInSimulation().Altered.ShouldBeTrue(); } + + [Observation] + public void should_have_updated_the_reference_to_observed_data_in_all_charts() + { + A.CallTo(() => _chartTask.UpdateObservedDataInChartsFor(_simulation, _project)).MustHaveHappened(); + } } public class when_mapping_a_population_simulation_snapshot_to_simulation : concern_for_SimulationMapper diff --git a/tests/PKSim.Tests/Infrastructure/ChartTemplatingTaskSpecs.cs b/tests/PKSim.Tests/Infrastructure/ChartTemplatingTaskSpecs.cs index fd21977c2..5d2c997ef 100644 --- a/tests/PKSim.Tests/Infrastructure/ChartTemplatingTaskSpecs.cs +++ b/tests/PKSim.Tests/Infrastructure/ChartTemplatingTaskSpecs.cs @@ -19,6 +19,7 @@ using PKSim.Core; using PKSim.Core.Chart; using PKSim.Core.Model; +using PKSim.Core.Services; using PKSim.Infrastructure.Serialization.Xml.Serializers; using PKSim.Infrastructure.Services; using PKSim.Presentation.Services; @@ -88,7 +89,7 @@ protected override void Because() [Observation] public void the_chart_task_should_update_observed_data() { - A.CallTo(() => _chartTask.UpdateObservedDataInChartFor(A._, _chartWithObservedData)).MustHaveHappened(); + A.CallTo(() => _chartTask.UpdateObservedDataInChartFor(A._, _chartWithObservedData, null)).MustHaveHappened(); } } diff --git a/tests/PKSim.Tests/Infrastructure/SimulationChartsLoaderSpecs.cs b/tests/PKSim.Tests/Infrastructure/SimulationChartsLoaderSpecs.cs index e71addb2e..d492bcdb3 100644 --- a/tests/PKSim.Tests/Infrastructure/SimulationChartsLoaderSpecs.cs +++ b/tests/PKSim.Tests/Infrastructure/SimulationChartsLoaderSpecs.cs @@ -71,7 +71,7 @@ public void should_add_the_charts_to_the_simulation() [Observation] public void should_add_all_observed_data_defined_in_the_simulation() { - A.CallTo(() => _chartTask.UpdateObservedDataInChartsFor(_simulation)).MustHaveHappened(); + A.CallTo(() => _chartTask.UpdateObservedDataInChartsFor(_simulation, null)).MustHaveHappened(); } } } \ No newline at end of file diff --git a/tests/PKSim.Tests/Presentation/ChartTaskSpecs.cs b/tests/PKSim.Tests/Presentation/ChartTaskSpecs.cs index 3cdd80764..c75fabc46 100644 --- a/tests/PKSim.Tests/Presentation/ChartTaskSpecs.cs +++ b/tests/PKSim.Tests/Presentation/ChartTaskSpecs.cs @@ -5,6 +5,7 @@ using OSPSuite.Core.Domain.Services; using OSPSuite.Utility.Events; using PKSim.Core; +using PKSim.Core.Services; using PKSim.Infrastructure.Services; using PKSim.Presentation.Services; diff --git a/tests/PKSim.Tests/Presentation/IndividualSimulationComparisonPresenterSpecs.cs b/tests/PKSim.Tests/Presentation/IndividualSimulationComparisonPresenterSpecs.cs index 51650fc1e..46b5191dd 100644 --- a/tests/PKSim.Tests/Presentation/IndividualSimulationComparisonPresenterSpecs.cs +++ b/tests/PKSim.Tests/Presentation/IndividualSimulationComparisonPresenterSpecs.cs @@ -17,6 +17,7 @@ using PKSim.Core; using PKSim.Core.Chart; using PKSim.Core.Model; +using PKSim.Core.Services; using PKSim.Presentation.Nodes; using PKSim.Presentation.Presenters.Charts; using PKSim.Presentation.Presenters.Simulations; diff --git a/tests/PKSim.Tests/Presentation/PKSimChartFactorySpecs.cs b/tests/PKSim.Tests/Presentation/PKSimChartFactorySpecs.cs index 5b7e0e063..b02c462b5 100644 --- a/tests/PKSim.Tests/Presentation/PKSimChartFactorySpecs.cs +++ b/tests/PKSim.Tests/Presentation/PKSimChartFactorySpecs.cs @@ -8,6 +8,7 @@ using OSPSuite.Presentation; using OSPSuite.Utility.Container; using PKSim.Core.Chart; +using PKSim.Core.Services; using PKSim.Presentation.Services; using PKSim.Presentation.Views.Charts; diff --git a/tests/PKSim.Tests/Presentation/SimulationTimeProfileChartPresenterSpecs.cs b/tests/PKSim.Tests/Presentation/SimulationTimeProfileChartPresenterSpecs.cs index 4613931ee..f7a7337c3 100644 --- a/tests/PKSim.Tests/Presentation/SimulationTimeProfileChartPresenterSpecs.cs +++ b/tests/PKSim.Tests/Presentation/SimulationTimeProfileChartPresenterSpecs.cs @@ -25,6 +25,7 @@ using PKSim.Core; using PKSim.Core.Chart; using PKSim.Core.Model; +using PKSim.Core.Services; using PKSim.Presentation.Presenters.Charts; using PKSim.Presentation.Presenters.Simulations; using PKSim.Presentation.Services;