We have a unit parser to help convert strings to messages. For each type of unit, there are multiple possible units (e.g., days, hours, minutes, seconds for time).
We might want to parse a string in one format into a message, then convert that message units into a default for that unit type, or a specific target. For example, converting "11 days" to "264 hours". This will require defining conversion factors, as we already do for volumes and flow rates to handle flow rates.
We also might want to make it easier to interpret a message that defines a value and unit. The default __repr__ for a message will print the value and unit on two lines. We can easily access message.value to get a float and message.unit to get an int corresponding to the enum, but this message.unit is not very helpful. Conversion from that int to a string requires slightly more familiarity with protocol buffers (and more code) than I'd like. Should we consider overriding the __repr__ for messages that have (value, unit, precision) fields to be "{value} \pm {precision} {unit_as_string}"?
We have a unit parser to help convert strings to messages. For each type of unit, there are multiple possible units (e.g., days, hours, minutes, seconds for time).
__repr__
for a message will print the value and unit on two lines. We can easily accessmessage.value
to get a float andmessage.unit
to get an int corresponding to the enum, but thismessage.unit
is not very helpful. Conversion from that int to a string requires slightly more familiarity with protocol buffers (and more code) than I'd like. Should we consider overriding the__repr__
for messages that have (value, unit, precision) fields to be"{value} \pm {precision} {unit_as_string}"
?Edit: The second use case is addressed by https://github.com/open-reaction-database/ord-schema/blob/main/ord_schema/units.py#L253 already