Skip to content
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

conversion of unit to string #80

Closed
fkloosterman opened this issue Jun 12, 2020 · 3 comments · Fixed by #82
Closed

conversion of unit to string #80

fkloosterman opened this issue Jun 12, 2020 · 3 comments · Fixed by #82

Comments

@fkloosterman
Copy link

Hi,

Thanks for the nice library. I have been playing with it to convert strings to measurements or units, and so far it works well. When converting back to a string, though, the original representation of the unit is lost. For example, if I define a custom count unit samples, then the string "samples/second" is correctly parsed, but converting the resulting unit back to a string results in Bq. What is the recommended way to preserve the original unit representation?

Separately, I was wondering if the unit Hz should actually be defined as count per second (i.e. counting the number of cycles per second). This would then make it compatible with samples/second (sampling rate) and spikes/second (firing rate of brain cells) that are generally expressed in Hz. Alternatively, I don't define samples and spikes as count units, but then I wonder how I could differentiate after conversion of a string to a measurement between "2" and "2 samples" without parsing the string again myself.

-Fabian

@phlptp
Copy link
Collaborator

phlptp commented Jun 12, 2020

The original conversion is lost, there is no way to store the original string in a very compact data structure. So generally the to string operations convert to the most compact representation. Still some bugs I am sure, but the general requirement was that the string produced needed to be able be converted back into the same unit.

A Bq is a count/sec usually used in counting radioactivity so technically correct but obviously not what you might be looking for.

so options would include

units::precise_unit samples=generate_custom_count_unit(3);
addUserDefinedUnit("samples",samples);

Then it would never get mistaken for a count. and the string would produce
"samples/s" Though if you really wanted samples/second at that point

addUserDefinedUnit("samples/second", samples/precise::s);

Side Note: still need to generate more documentation on generating custom_units and custom_count_units.

@phlptp
Copy link
Collaborator

phlptp commented Jun 12, 2020

As for Hz Kind of an interesting discussion I suppose. On the systems I interact with it would be more appropriate to have Hz be defined at 2*pi*rad/s but then the relationship of second==Hz.inv() wouldn't work. Though there are routines in the convert methods that deal with conversions between radians, count, and moles.

As far as counting of specific things I have either used a custom_count_unit or use the commodity field of the precise_unit type to keep track of what it is. Though based on your comment I might want to revisit the use of Bequerel in the case of count/s for string output, maybe I should just take that out of the string output as it seems to be more of niche unit and could be confusing in other fields.

@phlptp
Copy link
Collaborator

phlptp commented Aug 17, 2020

added documentation
and removed Bq from the unit to string conversion since that is an uncommon unit and often was confusing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants