class SegmentExplorerResult(LoadableEntity): """ Represents a segment result from the segment explorer feature. (These are not full segment objects, but the segment object can be fetched via the 'segment' property of this object.) """ _segment = None id = Attribute(int) #: ID of the segment. name = Attribute(unicode) #: Name of the segment climb_category = Attribute(int) #: Climb category for the segment (0 is higher) climb_category_desc = Attribute(unicode) #: Climb category text avg_grade = Attribute(float) #: Average grade for segment. start_latlng = LocationAttribute() #: Start lat/lon for segment end_latlng = LocationAttribute() #: End lat/lon for segment 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 @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 Segment(LoadableEntity): """ Represents a single Strava segment. """ _leaderboard = None name = Attribute(str, (SUMMARY, DETAILED)) #: Name of the segment. activity_type = Attribute(str, (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(str, (SUMMARY, DETAILED)) #: The city this segment is in. state = Attribute(str, (SUMMARY, DETAILED)) #: The state this segment is in. country = Attribute(str, (SUMMARY, DETAILED)) #: The country this segment is in. private = Attribute(bool, (SUMMARY, DETAILED)) #: Whether this is a private segment. starred = Attribute(bool, (SUMMARY, DETAILED)) #: Whether this segment is starred by authenticated athlete athlete_segment_stats = EntityAttribute(AthleteSegmentStats, (DETAILED,)) #: Undocumented attrib holding stats for current athlete. # 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 star_count = Attribute(int, (DETAILED,)) #: number of stars on this segment. @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 ActivityPhoto(LoadableEntity): """ Information about photos attached to an activity. """ activity_id = Attribute(int, (META,SUMMARY,DETAILED)) #: ID of activity ref = Attribute(unicode, (META,SUMMARY,DETAILED)) #: ref eg. "http://instagram.com/p/eAvA-tir85/" uid = Attribute(unicode, (META,SUMMARY,DETAILED)) #: unique id caption = Attribute(unicode, (META,SUMMARY,DETAILED)) #: caption on photo type = Attribute(unicode, (META,SUMMARY,DETAILED)) #: type of photo #left this off to prevent name clash uploaded_at = TimestampAttribute((SUMMARY,DETAILED)) #: :class:`datetime.datetime` when was phto uploaded created_at = TimestampAttribute((SUMMARY,DETAILED)) #: :class:`datetime.datetime` when was phto created location = LocationAttribute() #: Start lat/lon of photo
class ActivityPhoto(LoadableEntity): """ A full photo record attached to an activity. """ activity_id = Attribute(int, (META, SUMMARY, DETAILED)) #: ID of activity ref = Attribute(str, (META, SUMMARY, DETAILED)) #: ref eg. "http://instagram.com/p/eAvA-tir85/" uid = Attribute(str, (META, SUMMARY, DETAILED)) #: unique id caption = Attribute(str, (META, SUMMARY, DETAILED)) #: caption on photo type = Attribute(str, (META, SUMMARY, DETAILED)) #: type of photo (currently only InstagramPhoto) uploaded_at = TimestampAttribute((SUMMARY, DETAILED)) #: :class:`datetime.datetime` when was photo uploaded created_at = TimestampAttribute((SUMMARY, DETAILED)) #: :class:`datetime.datetime` when was photo created location = LocationAttribute() #: Start lat/lon of photo urls = Attribute(dict, (META, SUMMARY, DETAILED))
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
def test_without_location(self): location = LocationAttribute((SUMMARY, DETAILED)) self.assertIsNone(location.unmarshal([]))
def test_with_location(self): location = LocationAttribute((SUMMARY, DETAILED)) self.assertEqual(LatLon(1., 2.), location.unmarshal([1., 2.]))