- 
  Notifications
 You must be signed in to change notification settings 
- Fork 404
-
Hi all,
we are using this nuget package in our solutions and it`s great so far.
In the context of power plants there is a thing called heat rate (see wiki). It's a ratio of thermal energy in vs electrical energy out (efficiency) and is therefore dimensionless, but mostly expressed by energy/energy like kJ/kWh or BTU/kWh.
We are saving the name of the quantity and the name of the unit together with the value in our database. What is the best approach I can take to store kJ/kWh since it doesn't exist but is needed in that format? Should I create a new unit definition?
Tanks in advance for your input!
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 4 comments 1 reply
-
Hi, for dimensionless we suggest using Ratio.
As you say, you don't get to represent the actual unit abbreviations this way. You could absolutely create your own custom quantity, see https://github.com/angularsen/UnitsNet/wiki/Extending-with-Custom-Units.
Note that the wiki examples are a bit outdated related to master branch, which is currently the v6 pre-release.
See HowMuch quantity for the current state of how to implement IQuantity.
Not sure if relevant, but there is also some notes on serialization here, but nothing specifically for custom quantities:
https://github.com/angularsen/UnitsNet/wiki/Serializing-to-JSON,-XML-and-more 
Beta Was this translation helpful? Give feedback.
All reactions
-
This is not the first time someone requests a particular dimensionless unit.
We don't have a good way to support this as there are a vast number of such units and everything is statically typed, so we suffer binary size bloat.
I'm not sure what your needs are, but could you just create a simple wrapper type that holds the unit abbreviations?
Something like:
public struct HeatRate(Ratio Value, string Abbreviation) // "kJ/kWh" or "BTU/kWh" { public override string ToString() => $"{Value.DecimalFractions} {Abbreviation}"; }
Beta Was this translation helpful? Give feedback.
All reactions
-
Hi, thanks for your answers.
The problem here is not just the abbreviation, that would be easy to work around like you mentioned. The unit kJ/kWh is dimensionless, but has a factor 1/3600. So when I save it as Ratio in the database it's actually wrong.
Beta Was this translation helpful? Give feedback.
All reactions
-
I see, I suppose it would be possible to extend Ratio with a factor and an abbreviation, to use with ToString() as well as any serialization to JSON or database.
https://github.com/angularsen/UnitsNet/wiki/Serializing-to-JSON,-XML-and-more 
https://github.com/angularsen/UnitsNet/wiki/Saving-to-database 
If we could find a generic way to support any dimensionless unit, then that would be interesting to add to UnitsNet. Is this something you would be willing to attempt a pull request on?
Beta Was this translation helpful? Give feedback.
All reactions
-
I have to think about it.
Beta Was this translation helpful? Give feedback.