-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #2141 Extract mapper to create parameters from individual param…
…eters (#2142) * Fixes #2141 Extract mapper to create parameters from individual parameters * Add pr checklist * PR feedback
- Loading branch information
1 parent
b5741c5
commit a61c702
Showing
3 changed files
with
80 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
Fixes # | ||
|
||
# Description | ||
|
||
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. | ||
|
||
## Type of change | ||
|
||
Please mark relevant options with an `x` in the brackets. | ||
|
||
- [ ] Bug fix (non-breaking change which fixes an issue) | ||
- [ ] New feature (non-breaking change which adds functionality) | ||
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) | ||
- [ ] This change requires a documentation update | ||
- [ ] Algorithm update - updates algorithm documentation/questions/answers etc. | ||
- [ ] Other (please describe): | ||
|
||
# How Has This Been Tested? | ||
|
||
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration | ||
|
||
- [ ] Integration tests | ||
- [ ] Unit tests | ||
- [ ] Manual tests | ||
- [ ] No tests required | ||
|
||
# Reviewer checklist | ||
|
||
Mark everything that needs to be checked before merging the PR. | ||
|
||
- [ ] Check if the code is well documented | ||
- [ ] Check if the behavior is what is expected | ||
- [ ] Check if the code is well tested | ||
- [ ] Check if the code is readable and well formatted | ||
- [ ] Additional checks (document below if any) | ||
|
||
# Screenshots (if appropriate): | ||
|
||
# Questions (if appropriate): |
35 changes: 35 additions & 0 deletions
35
src/OSPSuite.Core/Domain/Mappers/IndividualParameterToParameterMapper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using OSPSuite.Core.Domain.Builder; | ||
using OSPSuite.Utility; | ||
|
||
namespace OSPSuite.Core.Domain.Mappers | ||
{ | ||
public interface IIndividualParameterToParameterMapper : IMapper<IndividualParameter, IParameter> | ||
{ | ||
} | ||
|
||
public class IndividualParameterToParameterMapper : IIndividualParameterToParameterMapper | ||
{ | ||
private readonly IParameterFactory _parameterFactory; | ||
|
||
public IndividualParameterToParameterMapper(IParameterFactory parameterFactory) | ||
{ | ||
_parameterFactory = parameterFactory; | ||
} | ||
|
||
public IParameter MapFrom(IndividualParameter individualParameter) | ||
{ | ||
var name = individualParameter.Name; | ||
var dimension = individualParameter.Dimension; | ||
var displayUnit = individualParameter.DisplayUnit; | ||
var distributionType = individualParameter.DistributionType; | ||
|
||
//if the distribution is undefined or the value is set, we create a default parameter to ensure that the value will take precedence. | ||
//Otherwise, we create a distributed parameter and assume that required sub-parameters will be created as well | ||
var parameter = distributionType == null || individualParameter.Value != null ? | ||
_parameterFactory.CreateParameter(name, dimension: dimension, displayUnit: displayUnit) : | ||
_parameterFactory.CreateDistributedParameter(name, distributionType.Value, dimension: dimension, displayUnit: displayUnit); | ||
|
||
return parameter.WithUpdatedMetaFrom(individualParameter); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters