-
Notifications
You must be signed in to change notification settings - Fork 10
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
WIP Fixes failign build #625
Conversation
Rate *= multiplier * Math.Pow(10, scale); | ||
} | ||
private Unit _direct { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private menber. Why a get set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really needed, sometimes I do this for finding easier where it is been used. So even when it is private, it is a full property and you can easily navigate but you are right, not necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resharper navigates with private members...plus it follows the rest of the code
@@ -48,37 +53,39 @@ public class UnitDefinitionImporter : SBMLImporter, IStartable, IUnitDefinitionI | |||
{ | |||
private readonly IMoBiDimensionFactory _moBiDimensionFactory; | |||
private readonly IDictionary<int, Unit> _baseUnitsDictionary; | |||
private readonly IDictionary<string, UnitConvertionInfo> _unitConvertionDictionary; | |||
private IDimensionFactory _dimensionFactory; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this guy here sinec we have a MoBiDimensionFactory (which is a specification of IDimensionFActory)
{ | ||
_baseUnitsDictionary.Add(libsbml.UNIT_KIND_AMPERE, _moBiDimensionFactory.Dimension("Ampere").Unit("A")); | ||
_baseUnitsDictionary.Add(libsbml.UNIT_KIND_BECQUEREL, _moBiDimensionFactory.Dimension("Becquerel").Unit("Bq")); | ||
_baseUnitsDictionary.Add(libsbml.UNIT_KIND_CANDELA, _moBiDimensionFactory.Dimension("Candela").Unit("cd")); | ||
_baseUnitsDictionary.Add(libsbml.UNIT_KIND_COULOMB, _moBiDimensionFactory.Dimension("Coulomb").Unit("C")); | ||
_baseUnitsDictionary.Add(libsbml.UNIT_KIND_DIMENSIONLESS, _moBiDimensionFactory.NoDimension.DefaultUnit); | ||
_baseUnitsDictionary.Add(libsbml.UNIT_KIND_DIMENSIONLESS, _moBiDimensionFactory.NoDimension.BaseUnit); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am pretty sure you mean BaseUnit and not DefaultUnit. We always need to convert to BaseUnit.
@@ -131,7 +140,7 @@ public IDimension ConvertUnit(UnitDefinition unitDefinition) | |||
if (dimension != Constants.Dimension.NO_DIMENSION) | |||
{ | |||
_sbmlInformation.MobiDimension[sbmlUnit] = dimension; | |||
_unitConvertionDictionary.Add(sbmlUnit, new UnitConvertionInfo() { Dimension = dimension, Unit = dimension.DefaultUnit, Rate = 1 }); | |||
_unitConversionDictionary.Add(sbmlUnit, new UnitConversionInfo {Dimension = dimension, Unit = dimension.BaseUnit, Rate = 1}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am pretty sure you mean BaseUnit and not DefaultUnit. We always need to convert to BaseUnit.
return dimensionAndUnit.dimension; | ||
} | ||
|
||
_unitConvertionDictionary.Add(sbmlUnit, new UnitConvertionInfo() { Dimension = dimension, Unit = dimension.DefaultUnit, Rate = 1 }); | ||
_unitConversionDictionary.Add(sbmlUnit, new UnitConversionInfo {Dimension = dimension, Unit = dimension.BaseUnit, Rate = 1}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am pretty sure you mean BaseUnit and not DefaultUnit. We always need to convert to BaseUnit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure
var convertionData = _unitConvertionDictionary[unit]; | ||
return (convertionData.Dimension.UnitValueToBaseUnitValue(convertionData.Unit, value * convertionData.Rate), convertionData.Dimension); | ||
var conversionData = _unitConversionDictionary[unit]; | ||
return (conversionData.Dimension.UnitValueToBaseUnitValue(conversionData.Unit, value * conversionData.Rate), conversionData.Dimension); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this rate? It feels that yo are converting twice since we are also converting using the value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@msevestre There are indeed two conversions. The first conversion is based on the description on the sbml file. The second is to the mobi base unit. Suppose there is a description from unit A to a (sbml) base unit B described in the file. This will be captured by the rate. Unit A does not exist on mobi but unit B does. Additionally, unit B needs to be translated to mobi base unit C. More specifically, we have an entry on the sbml file that specifies that "unit A" is going to be used and it has a given rule to be translated to "mole" (which is a conventional unit known in mobi too). This translation is captured in rate. But when we translate in mobi, we actually need to translate from "unit A" to "micro mole" which is the base unit, so we need to translate from "unit A" to "mole" and then to "micro mole". Does it make sense? It is not a clean explanation but we could talk about this tomorrow if you like. I will take a look on the changes though and also on the failing test.
public void NewDimensionsTests() | ||
{ | ||
sut.ToMobiBaseUnit("substance", 3e6).value.ShouldBeEqualTo(3e12); | ||
sut.ToMobiBaseUnit("inverse_day", 0.83).value.ShouldBeEqualTo(0.83 / 1440); //base unit is in minutes so 1440 minutes in one day |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but isn't the value in second based on _unit3?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minutes is the base unit, right?
@@ -117,7 +100,7 @@ protected override void Context() | |||
[Observation] | |||
public void ParameterWithVolumeUnitTest() | |||
{ | |||
var tc = _moBiProject.SpatialStructureCollection.FirstOrDefault().TopContainers.FirstOrDefault(); | |||
var tc = _moBiProject.SpatialStructureCollection.First().TopContainers.First(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should always be First since you are calling something after. FirstOrDefault does not make sense. Probably old code but we might as well fix it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, you are right.
@abdelr The test is still failing. Just some cleanup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I found the issue. The factor was wrong. I have also added some comments. Please let me know if they are accurate
Rate *= multiplier * Math.Pow(10, scale); | ||
} | ||
private Unit _direct { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resharper navigates with private members...plus it follows the rest of the code
|
||
_unit3 = _sbmlModel.createUnit(); | ||
_unit3.setExponent(-1); | ||
_unit3.setMultiplier(1 / 86400.0); //86400 seconds in one day |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@abdelr This was wrong I think. The way I understand the code. This is the factor to go from 1/ day to 1/s
so it should be 1/86400 asd not 86400 correct?
{ | ||
public IDimension Dimension { get; set; } | ||
|
||
//Unit in which the values are stored in SBML Base unit | ||
public Unit Unit { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@abdelr Comment here? Is this correct?
public string Name => (_direct?.Name ?? "1") + (_inverse != null ? $"/{_inverse.Name}" : ""); | ||
|
||
// Rate is the factor to convert from the unit used in sbml to the base unit used in sbml. | ||
// This is not necessarily the base unit in the ospsuite (1/s vs 1/min for inversed day for instance) | ||
public double Rate { get; private set; } = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@abdelr Comment here. Can you verify that this is correct?
@abdelr I forgot to publish my comment yesterday. Since you approved, I am assuming it's fine |
@msevestre Yes, I looked into the changes and made perfect sense for me. |
@abdelr I tried to fix the code but I have no idea what's going on .Why aren't you using the capability of the internal unit system to convert from one unit to another? If feels that you are multiplying TWICE with the rate when you care converting.
I have run resharper on the file (it would be awesome if you could run it as well) to simplify the code and I also implemented all the suggestion.
Then I removed the usage of two dimensionFactory in the same file (they should be the same instance anyways). I am sure you can figure out what's going on