Skip to content

Commit

Permalink
Fixes improve codre resilience (#1800)
Browse files Browse the repository at this point in the history
  • Loading branch information
msevestre authored Nov 18, 2022
1 parent 7d172e5 commit bd86066
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 45 deletions.
9 changes: 6 additions & 3 deletions src/OSPSuite.Core/Domain/OutputMappings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,13 @@ public virtual IEnumerable<OutputMapping> OutputMappingsUsingDataRepository(Data
return All.Where(x => x.UsesObservedData(dataRepository));
}

///fullOutputPath: Full path of the output including simulation name
public virtual IEnumerable<DataRepository> AllDataRepositoryMappedTo(string fullOutputPath)
/// <summary>
/// Returns all observed data mapped to the output with path <paramref name="fullOutputPath" />
/// </summary>
/// <param name="fullOutputPath">Full path of the output including simulation name</param>
public virtual IEnumerable<DataRepository> AllDataRepositoryMappedTo(string fullOutputPath)
{
return All.Where(x => x.FullOutputPath == fullOutputPath).Select(x => x.WeightedObservedData.ObservedData);
return All.Where(x => string.Equals(x.FullOutputPath, fullOutputPath)).Select(x => x.WeightedObservedData.ObservedData);
}

public virtual IEnumerable<DataRepository> AllDataRepositoryMappedFor(ISimulation simulation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,7 @@ public interface IChartEditorPresenter : IPresenter<IChartEditorView>,
void Refresh();

/// <summary>
/// Sets the output mappings of Simulation Outputs and their mapped Observed Data
/// </summary>
void SetOutputMappings(OutputMappings outputMappings);

/// <summary>
/// Adds the output mappings to the existing ones
/// Adds the output mappings to to the underlying data browser presenter (used for linking)
/// </summary>
void AddOutputMappings(OutputMappings outputMappings);

Expand Down Expand Up @@ -423,10 +418,7 @@ public void ApplyColumnSettings(GridColumnSettings columnSettings) =>

public void AddOutputMappings(OutputMappings outputMappings)
{
foreach (var outputMapping in outputMappings)
{
_dataBrowserPresenter.AllOutputMappings.Add(outputMapping);
}
_dataBrowserPresenter.AddOutputMappings(outputMappings);
}

public void AddLinkSimDataMenuItem() => _view.AddLinkSimulationObservedMenuItemCheckBox();
Expand Down Expand Up @@ -704,11 +696,6 @@ public void Refresh()
updateUsedColumns();
}

public void SetOutputMappings(OutputMappings outputMappings)
{
_dataBrowserPresenter.AllOutputMappings = outputMappings;
}

private bool canHandle(ChartEvent chartEvent)
{
return Equals(chartEvent.Chart, Chart);
Expand Down
46 changes: 23 additions & 23 deletions src/OSPSuite.Presentation/Presenters/Charts/DataBrowserPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using OSPSuite.Presentation.Views.Charts;
using OSPSuite.Utility.Collections;
using OSPSuite.Utility.Extensions;
using static OSPSuite.Assets.Captions.Chart.DataBrowser;

namespace OSPSuite.Presentation.Presenters.Charts
{
Expand Down Expand Up @@ -43,7 +44,7 @@ public interface IDataBrowserPresenter : IPresenter<IDataBrowserView>, IPresente
/// <summary>
/// For the column Id given, this returns whether or not the data is being used
/// </summary>
/// <param name="dataColumn">The data colum</param>
/// <param name="dataColumn">The data column</param>
/// <returns>true if the data is used in the chart otherwise false</returns>
bool IsUsed(DataColumn dataColumn);

Expand Down Expand Up @@ -77,19 +78,19 @@ public interface IDataBrowserPresenter : IPresenter<IDataBrowserView>, IPresente

/// <summary>
/// Is called from the view when the column selection is changed by the user
/// </summary>
/// </summary>s
void SelectedDataColumnsChanged();

/// <summary>
/// Returns all the DataColumns for the curves that are visible in the chart
/// Adds the output mappings (reference used to link observed data to output)
/// </summary>
IReadOnlyList<DataColumn> GetAllUsedDataColumns();
void AddOutputMappings(OutputMappings outputMappings);

/// <summary>
/// List of all the mappings of Simulation Outputs and their corresponding Observed Data
/// Returns all the DataColumns for the curves that are visible in the chart
/// </summary>
OutputMappings AllOutputMappings { get; set; }

IReadOnlyList<DataColumn> GetAllUsedDataColumns();
/// <summary>
/// Changes the bool that defines whether the corresponding observed data used state
/// should be updated when their linked output used state is updated
Expand All @@ -108,12 +109,12 @@ public class DataBrowserPresenter : PresenterWithColumnSettings<IDataBrowserView
private readonly List<DataColumn> _allDataColumns = new List<DataColumn>();
private Func<DataColumn, PathElements> _displayQuantityPathDefinition;
private bool _isLinkedMappedOutputs;
private readonly HashSet<OutputMappings> _allOutputMappings = new HashSet<OutputMappings>();
public event EventHandler<ColumnsEventArgs> SelectionChanged = delegate { };
public event EventHandler<UsedColumnsEventArgs> UsedChanged = delegate { };

public DataBrowserPresenter(IDataBrowserView view) : base(view)
{
AllOutputMappings = new OutputMappings();
}

public void SetDisplayQuantityPathDefinition(Func<DataColumn, PathElements> displayQuantityPathDefinition)
Expand Down Expand Up @@ -181,16 +182,17 @@ private void updateLinkedObservedData(DataColumn dataColumn, bool used)

private IReadOnlyList<DataColumnDTO> getLinkedObservedDataFromOutputPath(string outputPath)
{
var linkedObservedDataRepositories = AllOutputMappings.AllDataRepositoryMappedTo(outputPath);
var linkedObservedDataRepositories = _allOutputMappings.SelectMany(x=>x.AllDataRepositoryMappedTo(outputPath));
return getDataColumnDTOsFromDataRepositories(linkedObservedDataRepositories);
}

private IReadOnlyList<DataColumnDTO> getDataColumnDTOsFromDataRepositories(IEnumerable<DataRepository> linkedObservedDataRepositories)
{
return _dataColumnDTOCache.Where(x => linkedObservedDataRepositories.Contains(x.DataColumn.Repository)).ToList();

}

public void AddOutputMappings(OutputMappings outputMappings) => _allOutputMappings.Add(outputMappings);

public void UpdateUsedStateForSelection(bool used)
{
SetUsedState(_view.SelectedDescendantColumns, used);
Expand All @@ -206,8 +208,6 @@ public IReadOnlyList<DataColumn> GetAllUsedDataColumns()
return _dataColumnDTOCache.Where(x => x.Used).Select(x => x.DataColumn).ToList();
}

public OutputMappings AllOutputMappings { get; set; }

public void OutputObservedDataLinkingChanged(bool isLinkedMappedOutputs)
{
_isLinkedMappedOutputs = isLinkedMappedOutputs;
Expand Down Expand Up @@ -272,25 +272,25 @@ private void updateDataSelection(IReadOnlyList<DataColumnDTO> selectedDataColumn
protected override void SetDefaultColumnSettings()
{
//-1 actively removes the grouping for this column if there was one till now - specifying none leaves everything as is.
AddColumnSettings(BrowserColumns.RepositoryName).WithCaption(Captions.Chart.DataBrowser.RepositoryName).GroupIndex = -1;
AddColumnSettings(BrowserColumns.RepositoryName).WithCaption(RepositoryName).GroupIndex = -1;
AddColumnSettings(BrowserColumns.Simulation).WithCaption(Captions.SimulationPath);
AddColumnSettings(BrowserColumns.TopContainer).WithCaption(Captions.TopContainerPath);
AddColumnSettings(BrowserColumns.Container).WithCaption(Captions.ContainerPath);
AddColumnSettings(BrowserColumns.BottomCompartment).WithCaption(Captions.BottomCompartmentPath);
AddColumnSettings(BrowserColumns.Molecule).WithCaption(Captions.MoleculePath);
AddColumnSettings(BrowserColumns.Name).WithCaption(Captions.NamePath);
AddColumnSettings(BrowserColumns.BaseGridName).WithCaption(Captions.Chart.DataBrowser.BaseGridName).WithVisible(false);
AddColumnSettings(BrowserColumns.ColumnId).WithCaption(Captions.Chart.DataBrowser.ColumnId).WithVisible(false);
AddColumnSettings(BrowserColumns.OrderIndex).WithCaption(Captions.Chart.DataBrowser.OrderIndex).WithVisible(false);
AddColumnSettings(BrowserColumns.DimensionName).WithCaption(Captions.Chart.DataBrowser.DimensionName);
AddColumnSettings(BrowserColumns.BaseGridName).WithCaption(BaseGridName).WithVisible(false);
AddColumnSettings(BrowserColumns.ColumnId).WithCaption(ColumnId).WithVisible(false);
AddColumnSettings(BrowserColumns.OrderIndex).WithCaption(OrderIndex).WithVisible(false);
AddColumnSettings(BrowserColumns.DimensionName).WithCaption(DimensionName);
AddColumnSettings(BrowserColumns.QuantityType).WithCaption(Captions.Chart.DataBrowser.QuantityType).WithVisible(false);
AddColumnSettings(BrowserColumns.QuantityName).WithCaption(Captions.Chart.DataBrowser.QuantityName);
AddColumnSettings(BrowserColumns.HasRelatedColumns).WithCaption(Captions.Chart.DataBrowser.HasRelatedColumns).WithVisible(false);
AddColumnSettings(BrowserColumns.QuantityName).WithCaption(QuantityName);
AddColumnSettings(BrowserColumns.HasRelatedColumns).WithCaption(HasRelatedColumns).WithVisible(false);
AddColumnSettings(BrowserColumns.Origin).WithCaption(Captions.Chart.DataBrowser.Origin).WithVisible(false);
AddColumnSettings(BrowserColumns.Date).WithCaption(Captions.Chart.DataBrowser.Date).WithVisible(false);
AddColumnSettings(BrowserColumns.Category).WithCaption(Captions.Chart.DataBrowser.Category).WithVisible(false);
AddColumnSettings(BrowserColumns.Source).WithCaption(Captions.Chart.DataBrowser.Source).WithVisible(false);
AddColumnSettings(BrowserColumns.Used).WithCaption(Captions.Chart.DataBrowser.Used).WithVisible(true);
AddColumnSettings(BrowserColumns.Date).WithCaption(Date).WithVisible(false);
AddColumnSettings(BrowserColumns.Category).WithCaption(Category).WithVisible(false);
AddColumnSettings(BrowserColumns.Source).WithCaption(Source).WithVisible(false);
AddColumnSettings(BrowserColumns.Used).WithCaption(Used).WithVisible(true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public override void UpdateAnalysisBasedOn(IAnalysable analysable)
{
_isMultipleRun = _parameterIdentification.Results.Count > 1;
UpdateAnalysisBasedOn(_parameterIdentification.Results);
ChartEditorPresenter.SetOutputMappings(_parameterIdentification.OutputMappings);
ChartEditorPresenter.AddOutputMappings(_parameterIdentification.OutputMappings);
}

Refresh();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public override void UpdateAnalysisBasedOn(IAnalysable analysable)
if (!_simulation.ResultsDataRepository.IsNull())
{
UpdateAnalysis();
ChartEditorPresenter.SetOutputMappings(_simulation.OutputMappings);
ChartEditorPresenter.AddOutputMappings(_simulation.OutputMappings);
AddRunResultToChart();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ protected override void Context()
A.CallTo(() => _fakeOutputMappings.AllDataRepositoryMappedTo(_column1.PathAsString)).Returns(_linkedDataRepositories);
_allDataColumnDTOs[0].Used = true;
_allDataColumnDTOs[1].Used = false;
sut.AllOutputMappings = _fakeOutputMappings;
sut.AddOutputMappings(_fakeOutputMappings);
}

protected override void Because()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ protected override void Because()
[Observation]
public void the_chart_editor_presenter_should_be_updated()
{
A.CallTo(() => _chartEditorPresenter.SetOutputMappings(A<OutputMappings>._)).MustHaveHappened(2, Times.Exactly);
A.CallTo(() => _chartEditorPresenter.AddOutputMappings(A<OutputMappings>._)).MustHaveHappened(2, Times.Exactly);
}
}
}

0 comments on commit bd86066

Please sign in to comment.