本文整理汇总了Python中stravalib.client.Client.get_segment_efforts方法的典型用法代码示例。如果您正苦于以下问题:Python Client.get_segment_efforts方法的具体用法?Python Client.get_segment_efforts怎么用?Python Client.get_segment_efforts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stravalib.client.Client
的用法示例。
在下文中一共展示了Client.get_segment_efforts方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: datetime
# 需要导入模块: from stravalib.client import Client [as 别名]
# 或者: from stravalib.client.Client import get_segment_efforts [as 别名]
# authorize_url = client.authorization_url(client_id=client_id, redirect_uri='http://localhost:8282/authorized')
# code = "<RETURNED CODE>"
# access_token = client.exchange_code_for_token(client_id=client_id, client_secret=secret, code=code)
if __name__ == "__main__":
segment_id = 8516849 # 2015 Leeds Abbey Dash
race_time = datetime(2015,11,15)
output_file = 'data/leeds.times.csv'
access_token = "<ACCESS TOKEN>"
client = Client()
client.access_token = access_token
# Get all efforts on the day of the race
efforts = client.get_segment_efforts(segment_id,
start_date_local=race_time,
end_date_local=race_time+timedelta(1))
data = []
data.append(["athlete_id", "sex", "first_name", "last_name", "time"])
print "a"
counter = 0
for effort in efforts:
print counter
counter = counter + 1
time = effort.elapsed_time.seconds
athlete_id = effort.athlete.id
athlete = client.get_athlete(athlete_id)
first_name = re.sub('[^0-9a-zA-Z]+', '', athlete.firstname)
last_name = re.sub('[^0-9a-zA-Z]+', '', athlete.lastname)
data.append([athlete_id, athlete.sex, first_name, last_name, time])
示例2: ST_GeomFromGeoJSON
# 需要导入模块: from stravalib.client import Client [as 别名]
# 或者: from stravalib.client.Client import get_segment_efforts [as 别名]
cl.sql('UPDATE wbstrava SET the_geom = ST_GeomFromGeoJSON(\'' + inputGeojson + '\') WHERE segment_id=' + str(id))
except Exception as e:
if "Not Found" in e.message:
cl.sql('DELETE FROM wbstrava WHERE segment_id= ' + str(id))
print("Deleted Strava ID: {}".format(id))
else:
print("Something's wrong with Strava ID: {}".format(id))
## get list of segments already in CartoDB
queryResult = cl.sql('select segment_id from wbstrava')
currentSegments = [x['segment_id'] for x in queryResult['rows']]
now = datetime.datetime.now()
weekAgo = now + datetime.timedelta(days=-7)
for segment in currentSegments:
weekEfforts = client.get_segment_efforts(segment, start_date_local=weekAgo, end_date_local=now)
weekEffortsTimes = [i.moving_time.seconds for i in weekEfforts]
try:
leaderboard = client.get_segment_leaderboard(segment, top_results_limit=100)
leaderboardTimes = [x.moving_time.seconds for x in leaderboard if x.rank <= 100]
# print('Updated {} with {} efforts and {} leaderboard entries'.format(segment, len(weekEffortsTimes), leaderboard.effort_count))
except:
# cl.sql('DELETE FROM wbstrava WHERE segment_id=' + str(segment))
# print('Deleted: {}'.format(client.get_segment(segment).name))
print('Couldn\'t update: {}'.format(client.get_segment(segment).name))
if len(weekEffortsTimes) and len(leaderboardTimes):
segmentMean = np.divide(np.mean(leaderboardTimes), np.mean(weekEffortsTimes)).astype('str')
else:
segmentMean = '0'
cl.sql('UPDATE wbstrava SET ratio = ' + segmentMean + ' WHERE segment_id=' + str(segment))
cl.sql('UPDATE wbstrava SET count = ' + str(len(weekEffortsTimes)) + ' WHERE segment_id=' + str(segment))