コード例 #1
0
ファイル: models.py プロジェクト: jbrosamer/StravaScraper
	def __init__(self, athStats, athId):
		self.athId=athId
		self.RecentCount=athStats.recent_run_totals.count
		self.RecentDistance= float(unithelper.miles(athStats.recent_run_totals.distance))#distance in miles
		self.RecentTime= float(unithelper.seconds(athStats.recent_run_totals.moving_time))#time in seconds
		self.YTDCount=athStats.ytd_run_totals.count
		self.YTDDistance= float(unithelper.miles(athStats.ytd_run_totals.distance))#distance in miles
		self.YTDTime= float(unithelper.seconds(athStats.ytd_run_totals.moving_time))#time in seconds
		self.AllCount=athStats.all_run_totals.count
		self.AllDistance= float(unithelper.miles(athStats.all_run_totals.distance))#distance in miles
		self.AllTime= float(unithelper.seconds(athStats.all_run_totals.moving_time))#time in seconds
コード例 #2
0
ファイル: scraper.py プロジェクト: jbrosamer/StravaScraper
def getChallengeRuns(challengeName="strava-races-10k-2015-10"):
	# taking athletes from http://www.strava.com/challenges/turn-up-the-heat-run
	# there are 17311 athletes registered for that challenge
	detailsUrl="https://www.strava.com/challenges/"+challengeName+"/details"
	athPerPage=1
	r = requests.get(detailsUrl)
	data = json.loads(r.text)
	nAthletes=int(data["totals"]["participants"])
	nActivities=int(data["totals"]["num_activities"])
	total_pages = nAthletes/athPerPage
	challenges=[]
	for page in range(1, total_pages + 2):
		pageUrl = detailsUrl+('?paging_type='
				'overall&per_page=%s&overall_page=%s&overall_male_page=1'
				'&overall_female_page=1' %(athPerPage, page))

		r = requests.get(pageUrl)
		data = json.loads(r.text)
		for r in data['data'].values():
			challenges.append(models.Challenge(time=float(unithelper.seconds(r['moving_time'])), distance=float(unithelper.miles(r['distance'])), athId=r['id']))

		break
		print len(challenges)
		time.sleep(TIME_BT_REQUESTS)
	return challenges
コード例 #3
0
def calc_stats(athlete, activities):
    stats = {}
    subs = ['total', 'per_activity', 'per_time', 'per_dist']
    metrics = ['dist', 'time', 'elevation']

    if athlete.measurement_preference != 'feet':
        units_used = {
            #'dist': unithelper.kilometers, # km results in 0 per_dist stats, reason unknown
            'dist': unithelper.meters,
            'time': unithelper.seconds,
            'elevation': unithelper.meters
        }
    else:
        units_used = {
            'dist': unithelper.miles,
            'time': unithelper.seconds,
            'elevation': unithelper.feet
        }

    count = len(activities)

    for sub in subs:
        stats[sub] = {}
        for m in metrics:
            stats[sub][m] = units_used[m](0.0)

    stats_total = stats['total']
    for a in activities:
        stats_total['dist'] += a.distance
        stats_total['time'] += unithelper.seconds(
            float(a.elapsed_time.total_seconds()))
        stats_total['elevation'] += a.total_elevation_gain

    stats_count = stats['per_activity']
    for m in metrics:
        stats_count[m] = stats_total[m] / count

    stats_time = stats['per_time']
    for m in metrics:
        stats_time[m] = stats_total[m] / stats_total['time']

    stats_dist = stats['per_dist']
    for m in metrics:
        stats_dist[m] = stats_total[m] / stats_total['dist']

    stats['count'] = count

    return stats
コード例 #4
0
def activity_dict(athlete, a):
    elapsed_time = unithelper.seconds(a.elapsed_time.total_seconds())
    if athlete.measurement_preference == 'feet':
        distance = str(unithelper.miles(a.distance))
        gain = str(unithelper.feet(a.total_elevation_gain))
        if a.type == 'Ride':
            speed = str(unithelper.mph(a.average_speed))
            elapsed_speed = str(unithelper.mph(a.distance / elapsed_time))
        else:
            try:
                speed = "{0:.2f} /mi".format(
                    60 / (unithelper.mph(a.average_speed).num))
                elapsed_speed = "{0:.2f} /mi".format(
                    60 / unithelper.mph(a.distance / elapsed_time).num)
            except ZeroDivisionError:
                speed = 'NaN'
                elapsed_speed = 'NaN'
    else:
        distance = str(unithelper.kilometers(a.distance))
        gain = str(unithelper.meters(a.total_elevation_gain))
        if a.type == 'Ride':
            speed = str(unithelper.kph(a.average_speed))
            elapsed_speed = str(unithelper.kph(a.distance / elapsed_time))
        else:
            try:
                speed = "{0:.2f} /km".format(
                    60 / (unithelper.kph(a.average_speed).num))
                elapsed_speed = "{0:.2f} /km".format(
                    60 / unithelper.kph(a.distance / elapsed_time).num)
            except ZeroDivisionError:
                speed = 'NaN'
                elapsed_speed = 'NaN'

    date = a.start_date_local.strftime(athlete.date_preference
                                       or "%a, %d %b %Y")
    weekday = calendar.day_name[a.start_date_local.weekday()]

    workout_type = ''
    if a.type == 'Run':
        workout_type = ['', 'Race', 'Long Run', 'Workout'][int(a.workout_type
                                                               or 0)]

    garmin_link = ''
    if a.external_id:
        if a.external_id.startswith('garmin_push_'):
            garmin_id = a.external_id.split('_')[2]
            garmin_link = 'https://connect.garmin.com/modern/activity/{}'.format(
                garmin_id)

    return {
        'id': a.id,
        'link': url_for('query.show_activity', id=a.id),
        'strava_link': 'https://www.strava.com/activities/{}'.format(a.id),
        'garmin_link': garmin_link,
        'name': a.name,
        'type': a.type,
        'workout_type': workout_type,
        'date': date,
        'weekday': weekday,
        'distance': distance,
        'gain': gain,
        'elapsed_time': str(a.elapsed_time),
        'moving_time': str(a.moving_time),
        'speed': speed,
        'elapsed_speed': elapsed_speed,
        'start_latlng': [a.start_latitude, a.start_longitude],
        'polyline': a.map.polyline or a.map.summary_polyline
    }
コード例 #5
0
 def diff(self):
     diff = self.top_effort.elapsed_time.total_seconds() - \
            self.this_effort.elapsed_time.total_seconds()
     return unithelper.seconds(diff).num
コード例 #6
0
 def pr(self):
     return unithelper.seconds(self.top_effort.elapsed_time).num
コード例 #7
0
 def time(self):
     return unithelper.seconds(self.this_effort.elapsed_time).num
コード例 #8
0
 def ride_moving_time(self):
     return unithelper.seconds(self.activity.moving_time).num
コード例 #9
0
 def ride_elapsed_time(self):
     return unithelper.seconds(self.activity.elapsed_time).num