-
Notifications
You must be signed in to change notification settings - Fork 386
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
Unit for "Amount of times" #849
Comments
Can you make do with Ratio or Frequency?
|
Frequency does not work, since it has a time component in it, i.e. times per second.
In my opinion the QunatityType "None" with unit "Times" would therefore be a good enhancement, even if just for API purposes. What do you think? |
You are not the first to ask, and the answer has typically been to use Since people keep asking about it, I suppose we could add it.
Amount.FromMillons(1.5).Count; // 1.5e6
Amount.FromCount(1500).Thousands; // 1.5 Not to be confused with https://github.com/angularsen/UnitsNet/blob/master/Common/UnitDefinitions/AmountOfSubstance.json Since we don't know what we're counting, I feel |
I am taking the self-explanatory API position again: var numberOfSheep = Amount.FromCount(42); reads very good. This would not be the case when the word Ratio is somewhere in that line... So I'd say you should go for the new type and unit. I guess .FromCount is enough. The other creation methods might lead to missusages. C# already has enough syntax sugar for creating big numbers, i.e. 42e6. Not sure about the type, tho. Count always sounds like an int inside the .NET world. Counts like 2.3 and 4.23 do sound more like they could fit inside Ratio since they actually are one. 🤔 |
I agree 1.5 "count" does not make much sense, integers would be more natural there - otherwise use Ratio as you say. Alternative names: var amount = Amount.FromUnits(42);
amount.Units; // 42
var amount = Amount.FromSingles(42);
amount.Singles; // 42
var amount = Amount.FromOnes(42);
amount.Ones; // 42
var amount = Amount.FromIndividuals(42);
amount.Individuals; // 42 I would argue to keep units of thousands, millions etc. to benefit from these: var amount = Amount.FromOnes(4200000);
var amountInMilions = amount.Millions; // 4.2
var millionString = amount.ToUnit(AmountUnit.Million).ToString(); // 4.2 M
// as opposed to
var amountInMilions = amount.Ones / 1e6; // 4.2
var millionString = $"{amount.Ones / 1e6} M"; // 4.2 M |
Okay, I see the benifit of the helper methods. 👌 Don't like the alternative names (for the default creator method) tho. My favorites would be FromValue, FromCount or FromAmount. |
I think I like @selmaohneh If we agree on this, would you be interested in attempting a pull request on this? I'm happy to assist. |
I'll come back to you later today. I'll have to talk to my colleague about this. If we decide to go the UnitsNet way, I can work on the PR. We would need that functionality in around 3 weeks then. 🙄 Is that goal realistic? |
Great, yes 6 weeks is plenty. Detailed steps here: It is pretty easy once you understand how the code generation based on the JSON files works, and there are a lot of existing quantities to compare to. |
Yep, already read that doc. Just wanted to make sure we won't have huge loose ends shortly before the deadline because we aren't able to get a UnitsNet-PR merged. :D |
We decided that switching to UnitsNet is out of scope for our sprint. So right now I won't find the time to start implementing it. Freetime is daughter time currently. 😐😊 |
This is really just the need to have double/float/etc in an IQuantity format. I would call it Scalar or Dimensionless and FromValue/Value does seem to be the best fit. |
No problem @selmaohneh , let us know if you want to continue this. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I know this has been closed as stale, but I wanted to add support for this feature. I did take a look to see if I could do the work, but got stuck at the first hurdle, where BaseUnits are in 7 categories and this one doesn't really fit in any (could possibly squeeze it into a length, but felt hacky). |
No I agree, if you are interested in doing a pull request then I'm happy to help. The way I see it, we have two options:
I sort of think it could be slightly useful to add units "Thousands", "Millions" etc. However, I'm also fine with letting this kind of numeric text representation be a concern for Humanizer. As for BaseUnits, see how Ratio did it. Many quantities don't map to SI base units. |
Is your feature request related to a problem? Please describe.
I have a property of type
IQuantity
that users of my framework can fill as they desire. Often the value represents a technical number with a corresponding unit.But sometimes the value should represents a simple count of how often something was done. This quantity would be unit-less although being numerical.
Therefore the users have no way to generate the quantity, since the unit is a required argument of i.e.
Quantity.From(...)
.Describe the solution you'd like
A
QuantityType
called "None" would fit my needs. It should contain a single unit called "Times", e.g. [1].The text was updated successfully, but these errors were encountered: