How to use the stravalib.measurement.kph function in stravalib

To help you get started, weโ€™ve selected a few stravalib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hozn / stravalib / stravalib / protocol / __init__.py View on Github external
def _convert_speed(self, v):
        """
        Converts speed (must have units) to configured imperial/metric units.
        :param v: The speed.  If this is not a units object, assumed to be meters per second.
        :type v: :class:`units.abstract.AbstractUnit` or float
        """
        #print("Got raw value %r" % (v,))
        if not isinstance(v, AbstractUnit):
            v = measurement.meters_per_second(v)
        
        #print("Normalized: %r" % (v,))
        
        if self.units == IMPERIAL:
            result = measurement.mph(v)
        else:
            result = measurement.kph(v)
            
        return result.get_num()
github hozn / stravalib / stravalib / protocol / v1.py View on Github external
def populate_ride_effort_base(self, entity_model, entity_struct):
        """
        Populates the attributes shared by rides and efforts.
        """
        self.populate_minimal(entity_model, entity_struct)
        
        athlete_struct = entity_struct['athlete']
        athlete = Athlete(bind_client=entity_model.bind_client)
        self.populate_athlete(athlete, athlete_struct)
        entity_model.athlete = athlete
        
        entity_model.average_speed = self._convert_speed(entity_struct['averageSpeed'])
        entity_model.average_watts = entity_struct['averageWatts']
        entity_model.maximum_speed = self._convert_speed(measurement.kph(entity_struct['maximumSpeed'] / 1000.0)) # Not sure why this is in meters per *hour* ... !?
        entity_model.elevation_gain = self._convert_elevation(entity_struct['elevationGain'])
        entity_model.distance = self._convert_distance(entity_struct['distance'])
        entity_model.elapsed_time = timedelta(seconds=entity_struct['elapsedTime'])
        entity_model.moving_time = timedelta(seconds=entity_struct['movingTime'])
        entity_model.start_date = self._parse_datetime(entity_struct['startDateLocal'], entity_struct['timeZoneOffset'])