Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not update dimension when it already supports unit to avoid fraction/dimensionless collision #1515

Merged

Conversation

abdelr
Copy link
Member

@abdelr abdelr commented Feb 23, 2022

Fixes #1499 (Do not update dimension when it already supports unit to avoid fraction/dimensionless collision)

@abdelr abdelr added the Importer Observed data importer label Feb 23, 2022
@abdelr abdelr self-assigned this Feb 23, 2022
@msevestre
Copy link
Member

Build is failing

@msevestre
Copy link
Member

Don't forget to reference the issue to close in the commit message #1499

.FirstOrDefault(x => x.HasUnit(column.Unit.SelectedUnit));
if (column.Dimension != null && !column.Dimension.HasUnit(column.Unit.SelectedUnit))
column.Dimension = _columnInfos
.First(x => x.DisplayName == model.MappingName)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's in the place where you used the cache that you just implemented?
Also please add a { } around the if when what comes after is over multiple lines

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. It was on the other PR but it was already merged so I am rebasing to include the changes

column.Dimension = _columnInfos
.First(x => x.DisplayName == model.MappingName)
.SupportedDimensions
.FirstOrDefault(x => x.HasUnit(column.Unit.SelectedUnit));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this code over an over . FirstOrDefault(x=>x.HasUnit). It needs to be refactored at some point. I am pointing out here because I am seeing it. Please create an issue

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's always coming from the SupportedDimensions. If we make it a real class as opposed to a list? Or it belongs to the Columninfo itself. Not that Supporteddimension is a List and not a IReadOnlyList which breaks encapsulation

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -41,6 +42,22 @@ public static IDimension ConcentrationDimensionForSpecs()
return _concentrationDimension;
}

public static IEnumerable<IDimension> ExtendedDimensionsForSpecs()
{
var dimensions = new List<IDimension>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why aren't you using the dimensions already defined in the file (concentration, fraction etc..).
The NO_Dimension already exists also as a dImension normally so you code could be something like
reutnr new []{COnentrationDimForSPecs, NO_DIMENSION, FractionDimForSpecs).

_mappingSource = _parameters[2] as MappingDataFormatParameter;
_mappingSource.MappedColumn.Dimension = supportedDimensions.First(x => x.Name == Constants.Dimension.FRACTION);
A.CallTo(() => _mappingParameterEditorPresenter.Unit).Returns(new UnitDescription(""));
A.CallTo(() => _mappingParameterEditorPresenter.SelectedErrorType).Returns(1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this number means? 1

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have created some named constants

@abdelr abdelr force-pushed the 1499_do_not_update_dimension_when_it_already_supports_unit branch from f8ed534 to c5d36eb Compare February 24, 2022 13:43
@abdelr abdelr requested a review from msevestre February 24, 2022 14:23
@@ -168,7 +170,7 @@ protected override void Context()
{
base.Context();
A.CallTo(() => _mappingParameterEditorPresenter.Unit).Returns(new UnitDescription(""));
A.CallTo(() => _mappingParameterEditorPresenter.SelectedErrorType).Returns(0);
A.CallTo(() => _mappingParameterEditorPresenter.SelectedErrorType).Returns(GEOMETRIC_ERROR);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should return the enum that we have already defined as opposed to number. I am going to accept this PR but create an issue for this because returning the index of the combo box is not ok

@msevestre msevestre merged commit f802b6a into develop Feb 24, 2022
@msevestre msevestre deleted the 1499_do_not_update_dimension_when_it_already_supports_unit branch February 24, 2022 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Importer Observed data importer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Importer: Arithmetic error unit cannot be set to " " for "Fraction"
2 participants