Skip to content

Commit

Permalink
#2179 observed data reload with same settings
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaperez1983 committed Jan 22, 2025
1 parent 9ef6d63 commit 3009a9b
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 21 deletions.
24 changes: 24 additions & 0 deletions src/OSPSuite.Assets/UIConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,30 @@ public class ToolTips
}

public static readonly string ImportFileFilter = "Excel Files (*.xls, *.xlsx)|*.xls;*.xlsx|Comma Separated Value Files (*.csv)|*.csv|NonMem Files (*.NMdat)|*.NMdat|All Files (*.*)|*.*";

public static string UpdatedMappingsMessage(IEnumerable<(string ParameterName, string OutputPath)> updatedMappingsInfo)
{
var sb = new StringBuilder();
sb.AppendLine("The following parameter identifications and their output mappings were modified:");
sb.AppendLine();

var groupedMappings = updatedMappingsInfo
.GroupBy(mapping => mapping.ParameterName)
.OrderBy(group => group.Key);

foreach (var group in groupedMappings)
{
sb.AppendLine($"- {group.Key}");
foreach (var mapping in group)
{
sb.AppendLine($" - Output Path: {mapping.OutputPath}");
}
sb.AppendLine();
}

return sb.ToString();
}

}

public static class Diff
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,11 @@ public interface IParameterIdentificationTask
/// Returns a clone of the <paramref name="parameterIdentification"/> or null if the user cancels the clone action
/// </summary>
ParameterIdentification Clone(ParameterIdentification parameterIdentification);

/// <summary>
/// Updates the <see cref="ParameterIdentification"/>s using the <paramref name="observedData"/>
/// Returns an Ienumerable of <see cref="OutputMapping"/> that have been updated
/// </summary>
void UpdateParameterIdentificationsUsing(IEnumerable<DataRepository> observedData);
}
}
3 changes: 1 addition & 2 deletions src/OSPSuite.Core/Events/ObservedDataEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ public ObservedDataTableChangedEvent(DataRepository observedData)
{
}
}

public class ObservedDataMetaDataAddedEvent : ObservedDataEvent
{
public ObservedDataMetaDataAddedEvent(DataRepository observedData)
: base(observedData)
{

}
}

Expand All @@ -41,7 +41,6 @@ public class ObservedDataMetaDataRemovedEvent : ObservedDataEvent
public ObservedDataMetaDataRemovedEvent(DataRepository observedData)
: base(observedData)
{

}
}

Expand Down
18 changes: 18 additions & 0 deletions src/OSPSuite.Core/Events/WeightObservedDataChangedEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using OSPSuite.Core.Domain;
using OSPSuite.Core.Domain.Data;
using System;
using System.Collections.Generic;
using System.Text;

namespace OSPSuite.Core.Events
{
public class WeightObservedDataChangedEvent
{
public OutputMapping OutputMapping { get; private set; }

public WeightObservedDataChangedEvent(OutputMapping outputMapping)
{
OutputMapping = outputMapping;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Linq;
using OSPSuite.Core.Domain;
using OSPSuite.Core.Domain.ParameterIdentifications;
using OSPSuite.Core.Events;
Expand All @@ -12,7 +13,8 @@ public interface IParameterIdentificationDataSelectionPresenter : IParameterIden
IListener<ObservedDataRemovedFromAnalysableEvent>,
IListener<RenamedEvent>,
IListener<SimulationRemovedEvent>,
IListener<SimulationReplacedInParameterAnalyzableEvent>
IListener<SimulationReplacedInParameterAnalyzableEvent>,
IListener<WeightObservedDataChangedEvent>
{
event EventHandler<SimulationEventArgs> SimulationAdded;
event EventHandler<SimulationEventArgs> SimulationRemoved;
Expand Down Expand Up @@ -127,5 +129,16 @@ public void Handle(SimulationReplacedInParameterAnalyzableEvent eventToHandle)
}

private bool canHandle(SimulationReplacedInParameterAnalyzableEvent eventToHandle) => Equals(eventToHandle.ParameterAnalysable, _parameterIdentification);

public void Handle(WeightObservedDataChangedEvent eventToHandle)
{
var existingMapping = _outputMappingPresenter.OutputMappings.Where(x => x.OutputPath == eventToHandle.OutputMapping.OutputPath).FirstOrDefault();

if (existingMapping == null)
return;

_weightedObservedDataPresenter.Edit(eventToHandle.OutputMapping.WeightedObservedData);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
using OSPSuite.Utility;
using OSPSuite.Utility.Collections;
using OSPSuite.Utility.Extensions;
using static OSPSuite.Assets.Captions;
using ParameterIdentification = OSPSuite.Core.Domain.ParameterIdentifications.ParameterIdentification;

namespace OSPSuite.Presentation.Presenters.ParameterIdentifications
{
Expand All @@ -31,6 +33,7 @@ public ObservedDataEventArgs(WeightedObservedData weightedObservedData)
public interface IParameterIdentificationOutputMappingPresenter : IPresenter<IParameterIdentificationOutputMappingView>, IParameterIdentificationPresenter, ILatchable
{
void AddOutputMapping();
IEnumerable<OutputMapping> OutputMappings { get; }
IEnumerable<SimulationQuantitySelectionDTO> AllAvailableOutputs { get; }
IEnumerable<DataRepository> AllObservedDataFor(OutputMappingDTO dto);
void ObservedDataSelectionChanged(OutputMappingDTO dto, DataRepository newObservedData, DataRepository oldObservedData);
Expand Down Expand Up @@ -111,6 +114,14 @@ public void AddOutputMapping()
OnStatusChanged();
}

public IEnumerable<OutputMapping> OutputMappings
{
get
{
return _parameterIdentification.AllOutputMappings;
}
}

private void updateOutputMappingList()
{
_allOutputMappingDTOs.Clear();
Expand Down
28 changes: 28 additions & 0 deletions src/OSPSuite.Presentation/Services/ParameterIdentificationTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,34 @@ public bool SimulationCanBeUsedForIdentification(ISimulation simulation)
return _simulationSelector.SimulationCanBeUsedForIdentification(simulation);
}

public void UpdateParameterIdentificationsUsing(IEnumerable<DataRepository> observedData)
{
var updatedMappingsInfo = new List<(string ParameterName, string OutputPath)>();
observedData.Each(data =>
{
ParameterIdentificationsUsingObservedData(data).Each(parameterIdentification =>
{
parameterIdentification.OutputMappingsUsingDataRepository(data).Each(outputMapping =>
{
var existingDataCount = outputMapping.WeightedObservedData?.Count ?? 0;
var newDataCount = data.BaseGrid.Count;
if (existingDataCount != newDataCount)
{
outputMapping.WeightedObservedData = new WeightedObservedData(data);
updatedMappingsInfo.Add((parameterIdentification.Name, outputMapping.FullOutputPath));
_executionContext.PublishEvent(new WeightObservedDataChangedEvent(outputMapping));
}
});
});
});

if (updatedMappingsInfo.Any())
{
var strPaths = Captions.Importer.UpdatedMappingsMessage(updatedMappingsInfo);
_dialogCreator.MessageBoxInfo(strPaths);
}
}

public ParameterIdentification Clone(ParameterIdentification parameterIdentification)
{
loadParameterIdentification(parameterIdentification);
Expand Down
Loading

0 comments on commit 3009a9b

Please sign in to comment.