stravalib.model.Distance#

class stravalib.model.Distance(x=0, /)[source]#

A class for representing distances as quantities (using meter as unit, which is the implicit default of Strava). These quantities can then be converted to other units such as feet or meters using the stravalib.unit_helper module.

Examples

Once you have distance in meters, you can then use the unit_helper module to convert to other units such as feet

>>> from stravalib import unit_helper
>>> activity = client.get_activity(11416949675)
>>> activity.distance
8055.9
>>> activity.distance.quantity()
<Quantity(8055.9, 'meter')>
>>>  unit_helper.feet(activity.distance)
<Quantity(26430.1181, 'foot')>
>>> unit_helper.miles(activity.distance)
<Quantity(5.00570419, 'mile')>
>>> unit_helper.miles(activity.distance).magnitude
5.00570419
__init__()#

Methods

fromhex()

Create a floating-point number from a hexadecimal string.

hex()

Return a hexadecimal representation of a floating-point number.

is_integer()

Return True if the float is an integer.

quantity()

Returns the base type (e.g., float) as a pint.Quantity by attaching the unit to it.

Attributes

unit

The quantity's unit

fromhex()#

Create a floating-point number from a hexadecimal string.

>>> float.fromhex('0x1.ffffp10')
2047.984375
>>> float.fromhex('-0x1p-1074')
-5e-324
hex()#

Return a hexadecimal representation of a floating-point number.

>>> (-0.1).hex()
'-0x1.999999999999ap-4'
>>> 3.14159.hex()
'0x1.921f9f01b866ep+1'
is_integer()#

Return True if the float is an integer.

quantity() Quantity#

Returns the base type (e.g., float) as a pint.Quantity by attaching the unit to it.

unit: str = 'meters'#

The quantity’s unit