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

Fixes #1949 data importer parsing unit should be case insensitive #1952

Merged

Conversation

msevestre
Copy link
Member

@georgeDaskalakis The function hasUnit should not be used as it checked for actual value by keys. The code should always use SupportUnits In my opinion

I found a section that still uses hasUnit. The code is too complicated for me to review or change at this stage so I will ask you to do the modifications if required.
image

I really think the code in those functions (validateUnitsSupportedAndSameDimension or validateErrorAgainstMeasurement etc) is very complicated. We should extract some of the logic regarding error mapping, finding units etc...we repeat almost the same code throughout the Datasource file and this makes modification much harder than they should

Copy link
Member Author

@msevestre msevestre left a comment

Choose a reason for hiding this comment

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

I ran resharper in a bunch of files. This should be done more often

Copy link
Member Author

@msevestre msevestre left a comment

Choose a reason for hiding this comment

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

@georgeDaskalakis Please review

@@ -76,7 +75,7 @@ private void setDimensionsForMappings(ColumnInfoCache columnInfos)
else
{
var supportedDimensions = concreteColumnInfo.SupportedDimensions;
var dimensionForUnit = supportedDimensions.FirstOrDefault(x => x.HasUnit(mappedColumn.Unit.SelectedUnit));
var dimensionForUnit = supportedDimensions.FirstOrDefault(x => x.SupportsUnit(mappedColumn.Unit.SelectedUnit, ignoreCase: true));
Copy link
Member Author

Choose a reason for hiding this comment

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

this is the one change that did not impact my failing test but should be done I believe?

Copy link
Contributor

Choose a reason for hiding this comment

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

agreed

@@ -159,7 +158,12 @@ public UnitDescription ExtractUnitDescriptions(string description, IReadOnlyList

protected string ValidateUnit(string unit, IReadOnlyList<IDimension> supportedDimensions)
{
return supportedDimensions.Any(x => x.HasUnit(unit)) ? unit : UnitDescription.InvalidUnit;
var dimensionForUnit = supportedDimensions.FirstOrDefault(x => x.SupportsUnit(unit, ignoreCase: true));
Copy link
Member Author

Choose a reason for hiding this comment

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

this was the one change that was required

protected override void Context()
{
_fakedTimeDimension = A.Fake<IDimension>();
_fakedConcentrationDimensionMolar = A.Fake<IDimension>();
_fakedConcentrationDimensionMolar = A.Fake<IDimension>();
Copy link
Member Author

Choose a reason for hiding this comment

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

Why are we faking all the dimensions here? shouldn't we use real dimension instead?

@georgeDaskalakis
Copy link
Contributor

@msevestre I am removing the remaining .HasUnit and am thinking a bit about how to restructure the functions. Should I commit directly to the PR?

@msevestre
Copy link
Member Author

@georgeDaskalakis I don't think we need to refactor RIGHT Now. But this needs refactoring for sure
As for the HasUnit. I can't tell. If this comes from the program, then hasUnit is the way to go. But if this comes from PARSING, then hasUnit is wrong

@@ -76,7 +75,7 @@ private void setDimensionsForMappings(ColumnInfoCache columnInfos)
else
{
var supportedDimensions = concreteColumnInfo.SupportedDimensions;
var dimensionForUnit = supportedDimensions.FirstOrDefault(x => x.HasUnit(mappedColumn.Unit.SelectedUnit));
var dimensionForUnit = supportedDimensions.FirstOrDefault(x => x.SupportsUnit(mappedColumn.Unit.SelectedUnit, ignoreCase: true));
Copy link
Contributor

Choose a reason for hiding this comment

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

agreed

@msevestre msevestre merged commit 8e8ab52 into develop Apr 4, 2023
@msevestre msevestre deleted the 1949-data-importer-parsing-units-should-be-case-insensitive branch April 4, 2023 14:51
rwmcintosh added a commit that referenced this pull request Feb 14, 2024
* 1886 importer unit for fraction not recognized (#1892)

* changing the check

* correction to get the first non empty unit

* cleaning up

* Fixes #1925 (#1926)

@Yuri05 Merging. NEed to test in the app

* Fixes #1925 (#1927)

* 2566 fixed (#1932)

* nunit adapter updated (#1938)

* Fixes #1379 (#1948)

* Fixes #1946 mobi cannot handler observed data sets with only 1 point (#1947)

* Fixes #1949 data importer parsing unit should be case insensitive (#1952)

* Fixes #1949 data importer parsing unit should be case insensitive

* Run resharper

* Remove fake to use real dimensions

* Remove fake to use real dimensions

* refactoring and removing further .HasUnit() calls

---------

Co-authored-by: georgeDaskalakis <37107428+georgeDaskalakis@users.noreply.github.com>

* preventing exception (#1957)

* templates changed (#1962)

---------

Co-authored-by: georgeDaskalakis <37107428+georgeDaskalakis@users.noreply.github.com>
Co-authored-by: Michael Sevestre <michael@design2code.ca>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants