ふと自分のロードバイク偏差値が気になったので計算してみた。

まず、Stravaのアプリを登録して、CLIENT_SECRETをゲット

https://medium.com/@annthurium/getting-started-with-the-strava-api-a-tutorial-f3909496cd2d

対象となるセグメントの全ランキングを取得。
今回は、ベイエリアのライダーがベンチマークにしている Old La Honda(https://graphics.stanford.edu/~lucasp/grade/oldlahonda.html) を使用。

import requests
import json
import time

apiPath = "https://www.strava.com/api/v3/segments/8109834/leaderboard"

headers = {'Authorization': 'Bearer STRAVA_CLIENT_SECRET'}

pageLimit = 100

firstPagePath = apiPath + "?page=1&per_page=" + str(pageLimit)
firstPage = requests.get(firstPagePath, headers=headers).json()
totalCount = firstPage["entry_count"]

pageCount = totalCount / pageLimit

entries = []

for num in range(pageCount):
    pageNum = num + 1
    path = apiPath + "?page=" + str(pageNum) + "&per_page=" + str(pageLimit)
    pageData = requests.get(path, headers=headers).json()
    entries += pageData["entries"]
    time.sleep(0.5)

print json.dumps(entries)

Jupiter notebookでヒストグラムと偏差値を計算

%matplotlib inline

import numpy as np
import matplotlib.pyplot as plt
import json


f = open('oldlahonda.json', 'r')
entries = json.load(f)

elapsed = []
ranking = {}
power = []

for entry in entries:
    ranking[entry["rank"]] = entry

for t in ranking.values():
    elapsed.append(t["elapsed_time"])

np_scores = np.array(elapsed)  
mean = np.mean(np_scores)
std = np.std(np_scores)

score_a = 1531 # My best record

deviation = (score_a - mean) / std
deviation_value = 50 - deviation * 10

print(deviation_value)

plt.hist(elapsed, bins=200)
plt.plot()

偏差値 57.8らしい 精進せねば

ヒストグラムはこんな感じ(x軸は秒)
download.png

Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account log in.