Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to deal with heat rate unit of measurement? #1572

Unanswered
theilens asked this question in Q&A
Discussion options

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!

You must be logged in to vote

Replies: 4 comments 1 reply

Comment options

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

You must be logged in to vote
0 replies
Comment options

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}";
 }
You must be logged in to vote
0 replies
Comment options

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.

You must be logged in to vote
0 replies
Comment options

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?

You must be logged in to vote
1 reply
Comment options

I have to think about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /