The horizon.utils.units
ModuleΒΆ
-
horizon.utils.units.
convert
(value, source_unit, target_unit, fmt=False)[source] Converts value from source_unit to target_unit. Returns a tuple containing the converted value and target_unit. Having fmt set to True causes the value to be formatted to 1 decimal digit if it’s a decimal or be formatted as integer if it’s an integer.
E.g:
>>> convert(2, 'hr', 'min') (120.0, 'min') >>> convert(2, 'hr', 'min', fmt=True) (120, 'min') >>> convert(30, 'min', 'hr', fmt=True) (0.5, 'hr')
-
horizon.utils.units.
is_larger
(unit_1, unit_2)[source] Returns a boolean indicating whether unit_1 is larger than unit_2.
E.g:
>>> is_larger('KB', 'B') True >>> is_larger('min', 'day') False
-
horizon.utils.units.
is_supported
(unit)[source] Returns a bool indicating whether the unit specified is supported by this module.
-
horizon.utils.units.
normalize
(value, unit)[source] Converts the value so that it belongs to some expected range. Returns the new value and new unit.
E.g:
>>> normalize(1024, 'KB') (1, 'MB') >>> normalize(90, 'min') (1.5, 'hr') >>> normalize(1.0, 'object') (1, 'object')