当前位置: 首页>>代码示例>>Python>>正文


Python Client.get_segment_efforts方法代码示例

本文整理汇总了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])
开发者ID:wmycroft,项目名称:strava-data-mining,代码行数:33,代码来源:SegmentDetails.py

示例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))
开发者ID:geodarcy,项目名称:winterbiking,代码行数:33,代码来源:updateRatios.py


注:本文中的stravalib.client.Client.get_segment_efforts方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。