How to use the stravalib.model.BaseEntity 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 / model.py View on Github external
average_watts = Attribute(float, (SUMMARY, DETAILED,))  #: Average watts for lap
    average_heartrate = Attribute(float, (SUMMARY, DETAILED,))  #: Average heartrate for lap
    max_heartrate = Attribute(float, (SUMMARY, DETAILED,))  #: Max heartrate for lap
    lap_index = Attribute(int, (SUMMARY, DETAILED))  #: Index of lap
    device_watts = Attribute(bool, (SUMMARY, DETAILED))  # true if the watts are from a power meter, false if estimated
    pace_zone = Attribute(int, (SUMMARY, DETAILED))  #: (undocumented)
    split = Attribute(int, (SUMMARY, DETAILED))  #: Split number


class Map(IdentifiableEntity):
    id = Attribute(six.text_type, (SUMMARY, DETAILED))  #: Alpha-numeric identifier
    polyline = Attribute(str, (SUMMARY, DETAILED))  #: Google polyline encoding
    summary_polyline = Attribute(str, (SUMMARY, DETAILED))  #: Google polyline encoding for summary shape


class Split(BaseEntity):
    """
    A split -- may be metric or standard units (which has no bearing
    on the units used in this object, just the binning of values).
    """
    distance = Attribute(float, units=uh.meters)  #: Distance for this split
    elapsed_time = TimeIntervalAttribute()  #: :class:`datetime.timedelta` of elapsed time for split
    elevation_difference = Attribute(float, units=uh.meters)   #: Elevation difference for split
    moving_time = TimeIntervalAttribute()  #: :class:`datetime.timedelta` of moving time for split
    average_heartrate = Attribute(float)   #: Average HR for split
    split = Attribute(int)  #: Which split number
    pace_zone = Attribute(int)  #: (undocumented)
    average_speed = Attribute(float, units=uh.meters_per_second)

    def __repr__(self):
        return ''.format(self.split, self.distance, self.elapsed_time)
github hozn / stravalib / stravalib / model.py View on Github external
entries = EntityCollection(SegmentLeaderboardEntry)

    def __iter__(self):
        return iter(self.entries)

    def __len__(self):
        return len(self.entries)

    def __contains__(self, k):
        return k in self.entries

    def __getitem__(self, k):
        return self.entries[k]


class DistributionBucket(BaseEntity):
    """
    A single distribution bucket object, used for activity zones.
    """
    max = Attribute(int)  #: Max datatpoint
    min = Attribute(int)  #: Min datapoint
    time = Attribute(int, units=uh.seconds)  #: Time in seconds (*not* a :class:`datetime.timedelta`)


class BaseActivityZone(LoadableEntity):
    """
    Base class for activity zones.

    A collection of :class:`stravalib.model.DistributionBucket` objects.
    """
    distribution_buckets = EntityCollection(DistributionBucket, (SUMMARY, DETAILED))  #: The collection of :class:`stravalib.model.DistributionBucket` objects
    type = Attribute(six.text_type, (SUMMARY, DETAILED))  #: Type of activity zone (heartrate, power, pace).
github hozn / stravalib / stravalib / model.py View on Github external
starred_date = TimestampAttribute((DETAILED, )) #: datetime when be starred
    athlete_pr_effort = EntityAttribute(AthletePrEffort, (DETAILED,))

    @property
    def leaderboard(self):
        """
        The :class:`stravalib.model.SegmentLeaderboard` object for this segment.
        """
        if self._leaderboard is None:
            self.assert_bind_client()
            if self.id is not None:
                self._leaderboard = self.bind_client.get_segment_leaderboard(self.id)
        return self._leaderboard


class SegmentEfforAchievement(BaseEntity):
    """
    An undocumented structure being returned for segment efforts.
    """
    rank = Attribute(int)  #: Rank in segment (either overall leaderboard, or pr rank)
    type = Attribute(six.text_type)  #: The type of achievement -- e.g. 'year_pr' or 'overall'
    type_id = Attribute(int)  #: Numeric ID for type of achievement?  (6 = year_pr, 2 = overall ??? other?)


class BaseEffort(LoadableEntity):
    """
    Base class for a best effort or segment effort.
    """
    name = Attribute(six.text_type, (SUMMARY, DETAILED))  #: The name of the segment
    segment = EntityAttribute(Segment, (SUMMARY, DETAILED))  #: The associated :class:`stravalib.model.Segment` for this effort
    activity = EntityAttribute("Activity", (SUMMARY, DETAILED))  #: The associated :class:`stravalib.model.Activity`
    athlete = EntityAttribute(Athlete, (SUMMARY, DETAILED))  #: The associated :class:`stravalib.model.Athlete`
github hozn / stravalib / stravalib / model.py View on Github external
class ResourceStateEntity(BaseEntity):
    """
    Mixin for entities that include the resource_state attribute.
    """
    resource_state = Attribute(int, (META, SUMMARY, DETAILED))  #: The detail-level for this entity.


class IdentifiableEntity(ResourceStateEntity):
    """
    Mixin for entities that include an ID attribute.
    """
    id = Attribute(int, (META, SUMMARY, DETAILED))  #: The numeric ID for this entity.


class BoundEntity(BaseEntity):
    """
    Base class for entities that support lazy loading additional data using a bound client.
    """

    bind_client = None  #: The :class:`stravalib.client.Client` that can be used to load related resources.

    def __init__(self, bind_client=None, **kwargs):
        """
        Base entity initializer, which accepts a client parameter that creates a "bound" entity
        which can perform additional lazy loading of content.

        :param bind_client: The client instance to bind to this entity.
        :type bind_client: :class:`stravalib.simple.Client`
        """
        self.bind_client = bind_client
        super(BoundEntity, self).__init__(**kwargs)
github hozn / stravalib / stravalib / model.py View on Github external
created_at = TimestampAttribute((SUMMARY, DETAILED))  #: :class:`datetime.datetime` when was coment created
    athlete = EntityAttribute(Athlete, (SUMMARY, DETAILED))  #: Associated :class:`stravalib.model.Athlete` (summary-level representation)


class ActivityPhotoPrimary(LoadableEntity):
    """
    A primary photo attached to an activity (different structure from full photo record)
    """
    id = Attribute(int, (META, SUMMARY, DETAILED))  #: ID of photo, if external.
    unique_id = Attribute(six.text_type, (META, SUMMARY, DETAILED))  #: ID of photo, if internal.
    urls = Attribute(dict, (META, SUMMARY, DETAILED))
    source = Attribute(int, (META, SUMMARY, DETAILED))  #: 1=internal, 2=instagram
    use_primary_photo = Attribute(bool,(META, SUMMARY, DETAILED))  #: (undocumented)


class ActivityPhotoMeta(BaseEntity):
    """
    The photos structure returned with the activity, not to be confused with the full loaded photos for an activity.
    """
    count = Attribute(int, (META, SUMMARY, DETAILED))
    primary = EntityAttribute(ActivityPhotoPrimary, (META, SUMMARY, DETAILED))
    use_primary_photo = Attribute(bool, (META, SUMMARY, DETAILED))

    def __repr__(self):
        return '<{0} count={1}>'.format(self.__class__.__name__, self.count)


class ActivityPhoto(LoadableEntity):
    """
    A full photo record attached to an activity.
    """
    athlete_id = Attribute(int, (META, SUMMARY, DETAILED))  #: ID of athlete
github hozn / stravalib / stravalib / model.py View on Github external
"""


class ActivityTotals(BaseEntity):
    """
    Represent ytd/recent/all run/ride totals.
    """
    achievement_count = Attribute(int)  #: How many achievements
    count = Attribute(int)  #: How many activities
    distance = Attribute(float, units=uh.meters)  #: Total distance travelled
    elapsed_time = TimeIntervalAttribute()  #: :class:`datetime.timedelta` of total elapsed time
    elevation_gain = Attribute(float, units=uh.meters)  #: Total elevation gain
    moving_time = TimeIntervalAttribute()  #: :class:`datetime.timedelta` of total moving time


class AthleteStats(BaseEntity):
    """
    Represents a combined set of an Athlete's statistics.
    """
    biggest_ride_distance = Attribute(float, units=uh.meters)  #: Longest ride for athlete.
    biggest_climb_elevation_gain = Attribute(float, units=uh.meters)  #: Greatest single elevation gain for athlete.
    recent_ride_totals = EntityAttribute(ActivityTotals)  #: Recent totals for rides. (:class:`stravalib.model.ActivityTotals`)
    recent_run_totals = EntityAttribute(ActivityTotals)  #: Recent totals for runs. (:class:`stravalib.model.ActivityTotals`)
    recent_swim_totals = EntityAttribute(ActivityTotals)  #: Recent totals for swims. (:class:`stravalib.model.ActivityTotals`)
    ytd_ride_totals = EntityAttribute(ActivityTotals)  #: Year-to-date totals for rides. (:class:`stravalib.model.ActivityTotals`)
    ytd_run_totals = EntityAttribute(ActivityTotals)  #: Year-to-date totals for runs. (:class:`stravalib.model.ActivityTotals`)
    ytd_swim_totals = EntityAttribute(ActivityTotals)  #: Year-to-date totals for swims. (:class:`stravalib.model.ActivityTotals`)
    all_ride_totals = EntityAttribute(ActivityTotals)  #: All-time totals for rides. (:class:`stravalib.model.ActivityTotals`)
    all_run_totals = EntityAttribute(ActivityTotals)  #: All-time totals for runs. (:class:`stravalib.model.ActivityTotals`)
    all_swim_totals = EntityAttribute(ActivityTotals)  #: All-time totals for swims. (:class:`stravalib.model.ActivityTotals`)
github hozn / stravalib / stravalib / model.py View on Github external
class Bike(Gear):
    """
    Represents an athlete's bike.
    """
    frame_type = Attribute(int, (DETAILED,))  #: (detailed-only) Type of bike frame.


class Shoe(Gear):
    """
    Represent's an athlete's pair of shoes.
    """


class ActivityTotals(BaseEntity):
    """
    Represent ytd/recent/all run/ride totals.
    """
    achievement_count = Attribute(int)  #: How many achievements
    count = Attribute(int)  #: How many activities
    distance = Attribute(float, units=uh.meters)  #: Total distance travelled
    elapsed_time = TimeIntervalAttribute()  #: :class:`datetime.timedelta` of total elapsed time
    elevation_gain = Attribute(float, units=uh.meters)  #: Total elevation gain
    moving_time = TimeIntervalAttribute()  #: :class:`datetime.timedelta` of total moving time


class AthleteStats(BaseEntity):
    """
    Represents a combined set of an Athlete's statistics.
    """
    biggest_ride_distance = Attribute(float, units=uh.meters)  #: Longest ride for athlete.
github hozn / stravalib / stravalib / model.py View on Github external
o.from_dict(v)
        return o

    def __repr__(self):
        attrs = []
        if hasattr(self.__class__, 'id'):
            attrs.append('id={0}'.format(self.id))
        if hasattr(self.__class__, 'name'):
            attrs.append('name={0!r}'.format(self.name))
        if hasattr(self.__class__, 'resource_state'):
            attrs.append('resource_state={0}'.format(self.resource_state))

        return '<{0} {1}>'.format(self.__class__.__name__, ' '.join(attrs))


class ResourceStateEntity(BaseEntity):
    """
    Mixin for entities that include the resource_state attribute.
    """
    resource_state = Attribute(int, (META, SUMMARY, DETAILED))  #: The detail-level for this entity.


class IdentifiableEntity(ResourceStateEntity):
    """
    Mixin for entities that include an ID attribute.
    """
    id = Attribute(int, (META, SUMMARY, DETAILED))  #: The numeric ID for this entity.


class BoundEntity(BaseEntity):
    """
    Base class for entities that support lazy loading additional data using a bound client.
github hozn / stravalib / stravalib / model.py View on Github external
elev_difference = Attribute(float, units=uh.meters)  #: Total elevation difference over segment.
    distance = Attribute(float, units=uh.meters)  #: Distance of segment.
    points = Attribute(str)  #: Encoded Google polyline of points in segment
    starred = Attribute(bool)  #: Whether this segment is starred by authenticated athlete

    @property
    def segment(self):
        """ Associated (full) :class:`stravalib.model.Segment` object. """
        if self._segment is None:
            self.assert_bind_client()
            if self.id is not None:
                self._segment = self.bind_client.get_segment(self.id)
        return self._segment


class AthleteSegmentStats(BaseEntity):
    """
    An undocumented structure being returned for segment stats for current athlete.
    """
    effort_count = Attribute(int)  #: (UNDOCUMENTED) Presumably how many efforts current athlete has on segment.
    pr_elapsed_time = TimeIntervalAttribute() #: (UNDOCUMENTED) Presumably PR elapsed time for segment.
    pr_date = DateAttribute()  #: (UNDOCUMENTED) Presumably date of PR :)

class AthletePrEffort(IdentifiableEntity):
    """
    An undocumented structure being returned for segment Athlete Pr Effort.
    """
    distance = Attribute(float, (SUMMARY, DETAILED), units=uh.meters)
    elapsed_time = TimeIntervalAttribute((SUMMARY, DETAILED))
    start_date = TimestampAttribute((SUMMARY, DETAILED))
    start_date_local = TimestampAttribute((SUMMARY, DETAILED))
    is_kom = Attribute(bool, (SUMMARY, DETAILED))