예제 #1
0
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
예제 #2
0
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
    split = Attribute(int) #: Which split number
예제 #3
0
class SegmentLeaderboardEntry(BoundEntity):
    """
    Represents a single entry on a segment leaderboard.

    The :class:`stravalib.model.SegmentLeaderboard` object is essentially a collection
    of instances of this class.
    """
    _athlete = None
    _activity = None
    _effort = None

    effort_id = Attribute(int) #: The numeric ID for the segment effort.
    athlete_id = Attribute(int) #: The numeric ID for the athlete.
    athlete_name = Attribute(unicode) #: The athlete's name.
    athlete_gender = Attribute(unicode) #: The athlete's sex (M/F)
    athlete_profile = Attribute(unicode) #: Link to athlete profile photo
    average_hr = Attribute(float) #: The athlete's average HR for this effort
    average_watts = Attribute(float) #: The athlete's average power for this effort
    distance = Attribute(float, units=uh.meters) #: The distance for this effort.
    elapsed_time = TimeIntervalAttribute() #: The elapsed time for this effort
    moving_time = TimeIntervalAttribute() #: The moving time for this effort
    start_date = TimestampAttribute((SUMMARY,DETAILED)) #: :class:`datetime.datetime` when this effot was started in GMT
    start_date_local = TimestampAttribute((SUMMARY,DETAILED), tzinfo=None)  #: :class:`datetime.datetime` when this effort was started in activity timezone
    activity_id = Attribute(int) #: The numeric ID of the associated activity for this effort.
    rank = Attribute(int) #: The rank on the leaderboard.

    def __repr__(self):
        return '<SegmentLeaderboardEntry rank={0} athlete_name={1!r}>'.format(self.rank, self.athlete_name)

    @property
    def athlete(self):
        """ The related :class:`stravalib.model.Athlete` (performs additional server fetch). """
        if self._athlete is None:
            self.assert_bind_client()
            if self.athlete_id is not None:
                self._athlete = self.bind_client.get_athlete(self.athlete_id)
        return self._athlete

    @property
    def activity(self):
        """ The related :class:`stravalib.model.Activity` (performs additional server fetch). """
        if self._activity is None:
            self.assert_bind_client()
            if self.activity_id is not None:
                self._activity = self.bind_client.get_activity(self.activity_id)
        return self._activity

    @property
    def effort(self):
        """ The related :class:`stravalib.model.SegmentEffort` (performs additional server fetch). """
        if self._effort is None:
            self.assert_bind_client()
            if self.effort_id is not None:
                self._effort = self.bind_client.get_segment_effort(self.effort_id)
        return self._effort
예제 #4
0
class BaseEffort(LoadableEntity):
    """
    Base class for a best effort or segment effort.
    """
    name = Attribute(unicode, (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` 
    kom_rank = Attribute(int, (SUMMARY,DETAILED)) #: 1-10 segment KOM ranking for athlete at time of upload
    pr_rank = Attribute(int, (SUMMARY,DETAILED)) #: 1-3 personal record ranking for athlete at time of upload
    moving_time = TimeIntervalAttribute((SUMMARY,DETAILED)) #: :class:`datetime.timedelta` 
    elapsed_time = TimeIntervalAttribute((SUMMARY,DETAILED))#: :class:`datetime.timedelta` 
    start_date = TimestampAttribute((SUMMARY,DETAILED)) #: :class:`datetime.datetime` when effort was started in GMT
    start_date_local = TimestampAttribute((SUMMARY,DETAILED), tzinfo=None) #: :class:`datetime.datetime` when effort was started in activity timezone for this effort
    distance = Attribute(int, (SUMMARY,DETAILED), units=uh.meters) #: The distance for this effort. 
예제 #5
0
class PaceActivityZone(BaseActivityZone):
    """
    Activity zone for pace.
    """
    score = Attribute(int, (SUMMARY, DETAILED)) #: The score for this zone.
    sample_race_distance = Attribute(int, (SUMMARY, DETAILED), units=uh.meters) #: (Not sure?)
    sample_race_time = TimeIntervalAttribute((SUMMARY, DETAILED)) #: (Not sure?)
예제 #6
0
파일: model.py 프로젝트: wmorrill/elevation
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 :)
예제 #7
0
class ActivityLap(LoadableEntity):

    name = Attribute(unicode, (SUMMARY,DETAILED)) #: Name of lap
    activity = EntityAttribute("Activity", (SUMMARY,DETAILED)) #: The associated :class:`stravalib.model.Activity`
    athlete = EntityAttribute(Athlete, (SUMMARY,DETAILED)) #: The associated :class:`stravalib.model.Athlete`


    elapsed_time = TimeIntervalAttribute((SUMMARY, DETAILED)) #: :class:`datetime.timedelta` of elapsed time for lap
    moving_time = TimeIntervalAttribute((SUMMARY, DETAILED)) #: :class:`datetime.timedelta` of moving time for lap
    start_date = TimestampAttribute((SUMMARY,DETAILED)) #: :class:`datetime.datetime` when lap was started in GMT
    start_date_local = TimestampAttribute((SUMMARY,DETAILED), tzinfo=None) #: :class:`datetime.datetime` when lap was started local
    distance = Attribute(float, (SUMMARY,DETAILED), units=uh.meters) #: The distance for this lap.
    start_index= Attribute(int, (SUMMARY,DETAILED)) #:
    end_index= Attribute(int, (SUMMARY,DETAILED)) #:
    total_elevation_gain = Attribute(float, (SUMMARY,DETAILED,), units=uh.meters) #: What is total elevation gain for lap
    average_speed = Attribute(float, (SUMMARY,DETAILED,), units=uh.meters_per_second) #: Average speed for lap
    max_speed = Attribute(float, (SUMMARY,DETAILED,), units=uh.meters_per_second) #: Max speed for lap
    average_cadence = Attribute(float, (SUMMARY,DETAILED,)) #: Average cadence for lap
    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
예제 #8
0
파일: model.py 프로젝트: wmorrill/elevation
class BaseEffort(LoadableEntity):
    """
    Base class for a best effort or segment effort.
    """
    name = Attribute(str, (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`
    kom_rank = Attribute(int, (SUMMARY, DETAILED))  #: 1-10 segment KOM ranking for athlete at time of upload
    pr_rank = Attribute(int, (SUMMARY, DETAILED))  #: 1-3 personal record ranking for athlete at time of upload
    moving_time = TimeIntervalAttribute((SUMMARY, DETAILED))  #: :class:`datetime.timedelta`
    elapsed_time = TimeIntervalAttribute((SUMMARY, DETAILED))  #: :class:`datetime.timedelta`
    start_date = TimestampAttribute((SUMMARY, DETAILED))  #: :class:`datetime.datetime` when effort was started in GMT
    start_date_local = TimestampAttribute((SUMMARY, DETAILED), tzinfo=None)  #: :class:`datetime.datetime` when effort was started in activity timezone for this effort
    distance = Attribute(int, (SUMMARY, DETAILED), units=uh.meters)  #: The distance for this effort.
    average_watts = Attribute(float, (SUMMARY, DETAILED))  #: Average power during effort
    device_watts = Attribute(bool, (SUMMARY, DETAILED))  #: True if the watts are from a power meter, false if estimated
    average_heartrate = Attribute(float, (SUMMARY, DETAILED))   #: Average HR during effort
    max_heartrate = Attribute(float, (SUMMARY, DETAILED))   #: Max HR during effort
    average_cadence = Attribute(float, (SUMMARY, DETAILED))   #: Average cadence during effort
    start_index = Attribute(int, (SUMMARY, DETAILED))  #: The activity stream index of the start of this effort
    end_index = Attribute(int, (SUMMARY, DETAILED))  #: The activity stream index of the end of this effort

    achievements = EntityCollection(SegmentEfforAchievement, (SUMMARY, DETAILED))  #: Undocumented attribute includes list of achievements for this effort.
예제 #9
0
class Segment(LoadableEntity):
    """
    Represents a single Strava segment.
    """
    _leaderboard = None
    
    name = Attribute(unicode, (SUMMARY,DETAILED)) #: Name of the segment.
    activity_type = Attribute(unicode, (SUMMARY,DETAILED)) #: Activity type of segment ('Ride' or 'Run')
    distance = Attribute(float, (SUMMARY,DETAILED), units=uh.meters) #: Distance of segment
    average_grade = Attribute(float, (SUMMARY,DETAILED)) #: Average grade (%) for segment
    maximum_grade = Attribute(float, (SUMMARY,DETAILED)) #: Maximum grade (%) for segment
    elevation_high = Attribute(float, (SUMMARY,DETAILED), units=uh.meters) #: The highest point of the segment.
    elevation_low = Attribute(float, (SUMMARY,DETAILED), units=uh.meters) #: The lowest point of the segment.
    start_latlng = LocationAttribute((SUMMARY,DETAILED)) #: The start lat/lon (:class:`tuple`)
    end_latlng = LocationAttribute((SUMMARY,DETAILED)) #: The end lat/lon (:class:`tuple`)
    start_latitude = Attribute(float, (SUMMARY,DETAILED)) #: The start latitude (:class:`float`)
    end_latitude = Attribute(float, (SUMMARY,DETAILED)) #: The end latitude (:class:`float`)
    start_longitude = Attribute(float, (SUMMARY,DETAILED)) #: The start longitude (:class:`float`)
    end_longitude = Attribute(float, (SUMMARY,DETAILED)) #: The end longitude (:class:`float`)
    climb_category = Attribute(int, (SUMMARY,DETAILED)) # 0-5, lower is harder
    city = Attribute(unicode, (SUMMARY,DETAILED)) #: The city this segment is in.
    state = Attribute(unicode, (SUMMARY,DETAILED)) #: The state this segment is in.
    private = Attribute(bool, (SUMMARY,DETAILED)) #: Whether this is a private segment.
    
    # detailed attribs
    created_at = TimestampAttribute((DETAILED,)) #: :class:`datetime.datetime` when was segment created.
    updated_at = TimestampAttribute((DETAILED,)) #: :class:`datetime.datetime` when was segment last updated.
    total_elevation_gain = Attribute(float, (DETAILED,), units=uh.meters) #: What is total elevation gain for segment.
    map = EntityAttribute(Map, (DETAILED,)) #: :class:`stravalib.model.Map` object for segment.
    effort_count = Attribute(int, (DETAILED,)) #: How many times has this segment been ridden.
    athlete_count = Attribute(int, (DETAILED,)) #: How many athletes have ridden this segment
    hazardous = Attribute(bool, (DETAILED,)) #: Whether this segment has been flagged as hazardous
    pr_time = TimeIntervalAttribute((DETAILED,)) #: :class:`datetime.timedelta`  of the PR time for authenticated athlete
    pr_distance = Attribute(float, (DETAILED,), units=uh.meters) #: The PR distance for authenticated athlete
    starred = Attribute(bool, (DETAILED,)) #: Whether this segment is starred by authenticated athlete
    
    @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
예제 #10
0
class Activity(LoadableEntity):
    """
    Represents an activity (ride, run, etc.).
    """
    # "Constants" for types of activities
    RIDE                = "Ride"
    RUN                 = "Run"
    SWIM                = "Swim"
    WALK                = "Walk"

    ALPINESKI           = "AlpineSki"
    BACKCOUNTRYSKI      = "BackcountrySki"
    CANOEING            = "Canoeing"
    CROSSCOUNTRYSKIING  = "CrossCountrySkiing"
    CROSSFIT            = "Crossfit"
    ELLIPTICAL          = "Elliptical"
    HIKE                = "Hike"
    ICESKATE            = "IceSkate"
    INLINESKATE         = "InlineSkate"
    KAYAKING            = "Kayaking"
    KITESURF            = "Kitesurf"
    NORDICSKI           = "NordicSki"
    ROCKCLIMBING        = "RockClimbing"
    ROLLERSKI           = "RollerSki"
    ROWING              = "Rowing"
    SNOWBOARD           = "Snowboard"
    SNOWSHOE            = "Snowshoe"
    STAIRSTEPPER        = "StairStepper"
    STANDUPPADDLING     = "StandUpPaddling"
    SURFING             = "Surfing"
    WEIGHTTRAINING      = "WeightTraining"
    WINDSURF            = "Windsurf"
    WORKOUT             = "Workout"
    YOGA                = "Yoga"

    _comments = None
    _zones = None
    _kudos = None
    _photos = None
    #_gear = None
    _laps = None

    TYPES = ( RIDE, RUN, SWIM, WALK, ALPINESKI, BACKCOUNTRYSKI, CANOEING,
              CROSSCOUNTRYSKIING, CROSSFIT, ELLIPTICAL, HIKE, ICESKATE,
              INLINESKATE, KAYAKING, KITESURF, NORDICSKI, ROCKCLIMBING,
              ROLLERSKI, ROWING, SNOWBOARD, SNOWSHOE, STAIRSTEPPER,
              STANDUPPADDLING, SURFING, WEIGHTTRAINING, WINDSURF, WORKOUT, YOGA)

    guid = Attribute(unicode, (SUMMARY,DETAILED)) #: (undocumented)

    external_id = Attribute(unicode, (SUMMARY,DETAILED)) #: An external ID for the activity (relevant when specified during upload).
    upload_id = Attribute(unicode, (SUMMARY,DETAILED)) #: The upload ID for an activit.
    athlete = EntityAttribute(Athlete, (SUMMARY,DETAILED)) #: The associated :class:`stravalib.model.Athlete` that performed this activity.
    name = Attribute(unicode, (SUMMARY,DETAILED)) #: The name of the activity.
    distance = Attribute(float, (SUMMARY,DETAILED), units=uh.meters) #: The distance for the activity.
    moving_time = TimeIntervalAttribute((SUMMARY,DETAILED)) #: The moving time duration for this activity.
    elapsed_time = TimeIntervalAttribute((SUMMARY,DETAILED)) #: The total elapsed time (including stopped time) for this activity.
    total_elevation_gain = Attribute(float, (SUMMARY,DETAILED), units=uh.meters) #: Total elevation gain for activity.
    type = Attribute(unicode, (SUMMARY,DETAILED)) #: The activity type.
    start_date = TimestampAttribute((SUMMARY,DETAILED)) #: :class:`datetime.datetime` when activity was started in GMT
    start_date_local = TimestampAttribute((SUMMARY,DETAILED), tzinfo=None) #: :class:`datetime.datetime` when activity was started in activity timezone
    timezone = TimezoneAttribute((SUMMARY,DETAILED)) #: The timezone for activity.
    start_latlng = LocationAttribute((SUMMARY,DETAILED))#: The start location (lat/lon :class:`tuple`)
    end_latlng = LocationAttribute((SUMMARY,DETAILED)) #: The end location (lat/lon :class:`tuple`)

    location_city = Attribute(unicode, (SUMMARY,DETAILED)) #: The activity location city
    location_state = Attribute(unicode, (SUMMARY,DETAILED)) #: The activity location state
    location_country = Attribute(unicode, (SUMMARY,DETAILED)) #: The activity location state
    start_latitude = Attribute(float, (SUMMARY,DETAILED)) #: The start latitude
    start_longitude = Attribute(float, (SUMMARY,DETAILED)) #: The start longitude

    achievement_count = Attribute(int, (SUMMARY,DETAILED)) #: How many achievements earned for the activity
    kudos_count = Attribute(int, (SUMMARY,DETAILED)) #: How many kudos received for activity
    comment_count = Attribute(int, (SUMMARY,DETAILED)) #: How many comments  for activity.
    athlete_count = Attribute(int, (SUMMARY,DETAILED)) #: How many other athlete's participated in activity
    photo_count = Attribute(int, (SUMMARY,DETAILED)) #: How many photos linked to activity
    map = EntityAttribute(Map, (SUMMARY,DETAILED)) #: :class:`stravavlib.model.Map` of activity.

    trainer = Attribute(bool, (SUMMARY,DETAILED)) #: Whether activity was performed on a stationary trainer.
    commute = Attribute(bool, (SUMMARY,DETAILED)) #: Whether activity is a commute.
    manual = Attribute(bool, (SUMMARY,DETAILED)) #: Whether activity was manually entered.
    private = Attribute(bool, (SUMMARY,DETAILED)) #: Whether activity is private
    flagged = Attribute(bool, (SUMMARY,DETAILED))  #: Whether activity was flagged.

    gear_id = Attribute(unicode, (SUMMARY,DETAILED)) #: Which bike/shoes were used on activity.
    gear = EntityAttribute(Gear, (DETAILED,))

    average_speed = Attribute(float, (SUMMARY,DETAILED), units=uh.meters_per_second) #: Average speed for activity.
    max_speed = Attribute(float, (SUMMARY,DETAILED), units=uh.meters_per_second) #: Max speed for activity

    truncated = Attribute(int, (SUMMARY,DETAILED)) #: Only present if activity is owned by authenticated athlete, set to 0 if not truncated by privacy zones
    has_kudoed = Attribute(bool, (SUMMARY,DETAILED)) #: If authenticated user has kudoed this activity

    best_efforts = EntityCollection(BestEffort, (DETAILED,)) #: :class:`list` of metric :class:`stravalib.model.BestEffort` summaries
    segment_efforts = EntityCollection(SegmentEffort, (DETAILED,)) #: :class:`list` of :class:`stravalib.model.SegmentEffort` efforts for activity.
    splits_metric = EntityCollection(Split, (DETAILED,)) #: :class:`list` of metric :class:`stravalib.model.Split` summaries (running activities only)
    splits_standard = EntityCollection(Split, (DETAILED,)) #: :class:`list` of standard/imperial :class:`stravalib.model.Split` summaries (running activities only)

    # Undocumented attributes
    average_watts = Attribute(float, (SUMMARY,DETAILED)) #: (undocumented) Average power during activity
    weighted_average_watts = Attribute(int, (SUMMARY,DETAILED)) # rides with power meter data only similar to xPower or Normalized Power
    average_heartrate = Attribute(float, (SUMMARY,DETAILED))  #: (undocumented) Average HR during activity
    max_heartrate = Attribute(int, (SUMMARY,DETAILED))  #: (undocumented) Max HR during activity
    average_cadence = Attribute(float, (SUMMARY,DETAILED))  #: (undocumented) Average cadence during activity
    kilojoules = Attribute(float, (SUMMARY,DETAILED))  #: (undocumented) Kilojoules of energy used during activity
    device_watts = Attribute(bool, (SUMMARY,DETAILED)) # true if the watts are from a power meter, false if estimated
    average_temp = Attribute(int, (SUMMARY,DETAILED)) #: (undocumented) Average temperature (when available from device) during activity.

    calories = Attribute(float, (DETAILED,))  #: Calculation of how many calories burned on activity
    description = Attribute(unicode, (DETAILED,))  #: (undocumented) Description of activity.
    workout_type = Attribute(unicode, (DETAILED,))  #: (undocumented)

    @property
    def comments(self):
        """
        Iterator of :class:`stravalib.model.ActivityComment` objects for this activity.
        """
        if self._comments is None:
            self.assert_bind_client()
            if self.comment_count > 0:
                self._comments = self.bind_client.get_activity_comments(self.id)
            else:
                # Shortcut if we know there aren't any
                self._comments = []
        return self._comments

    @property
    def laps(self):
        """
        Iterator of :class:`stravalib.model.ActivityLap` objects for this activity.
        """
        if self._laps is None:
            self.assert_bind_client()
            self._laps = self.bind_client.get_activity_laps(self.id)
        return self._laps

    @property
    def zones(self):
        """
        :class:`list` of :class:`stravalib.model.ActivityZone` objects for this activity.
        """
        if self._zones is None:
            self.assert_bind_client()
            self._zones = self.bind_client.get_activity_zones(self.id)
        return self._zones

    @property
    def kudos(self):
        """
        :class:`list` of :class:`stravalib.model.ActivityKudos` objects for this activity.
        """
        if self._kudos is None:
            self.assert_bind_client()
            self._kudos = self.bind_client.get_activity_kudos(self.id)
        return self._kudos

    @property
    def photos(self):
        """
        :class:`list` of :class:`stravalib.model.ActivityPhoto` objects for this activity.
        """
        if self._photos is None:
            if self.photo_count > 0:
                self.assert_bind_client()
                self._photos = self.bind_client.get_activity_photos(self.id)
            else:
                self._photos = []
        return self._photos