-
Notifications
You must be signed in to change notification settings - Fork 36
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
Synergi reader length unit parser #197
Synergi reader length unit parser #197
Conversation
Codecov Report
@@ Coverage Diff @@
## master #197 +/- ##
==========================================
+ Coverage 43.65% 43.97% +0.31%
==========================================
Files 74 75 +1
Lines 17027 17038 +11
==========================================
+ Hits 7433 7492 +59
+ Misses 9594 9546 -48
Continue to review full report at Codecov.
|
Thanks for starting the effort on this @etimberg! We are definitely planning to work on that soon since the way units are handled right now is really far from optimum... We were thinking about using a callback when an attribute of the models is set and use Pint to manage the conversion. Basically, when setting an attribute, the user can specify whatever unit he/she wants as long as the unit makes sense for this attribute (providing a length in Ohms for example should raise an Error...). Basically, instead of doing something like this in the reader with hardcoded conversion factors: api_line.length = data_length * 1609.34 # data_length in mi and DiTTo in meters you would do something like: api_line.set_attribute("length", data_length, "mi")
Hope this makes sense (more or less). This is something we are still thinking and designing so feel free to give your opinion/ideas! Concerning this PR, I think it's a good improvement compared to what the current Synergi reader is doing. We probably want to do some testing before merging as you said but this could be a good solution for the Synergi reader before we have a more consistent unit framework in place. |
@NicolasGensollen I like the idea of using another library for the conversion. I think when creating the wrapper, especially for Synergi, I think it would make sense to abstract away the input unit a bit to avoid if-else checks against the length units in a number of places. I think that would be a simple abstraction though.
|
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.
Thanks a lot for putting this together @etimberg!
I pulled your branch and merged it with the branch synergi_bugfix. Unfortuantely we don't have any great Synergi tests on the repo yet, but I tested it with some Synergi utility feeders we have and it seemed to work well.
The only discrepancy I had with the previous conversion was due to the Per_LUL value for English 2 being 1/1609.34 rather than the decimal value in this pull request, but I'm happy to approve it as is.
@tarekelgindy thanks for the review. I updated the Per_LuL constant for English2 to be |
This was an idea I had based on the discussion in #158 regarding units. I created a separate function that handles unit conversions for Synergi values based on the type (short unit, medium unit, long unit, and per long unit) and the length units from the Synergi DB (
'English2'
,'English1'
, and'Metric'
).I added some tests to cover this convert function. For English1, since the units of SUL and MUL are unknown, I assumed they were the same as English2.
I also converted the Synergi reader to use this new convert function which removes some of the hard coded constants that assumed
'English2'
units. I would wait to merge this until after the Synergi reader has some tests to be more confident in how it works.