Skip to content

ethanlee928/cycling

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

68 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cycling

Extract cycling workout data from Strava, analyse the performance using Strava API.

🖥️ Dependencies

Python Environment

uv venv .venv
source .venv/bin/activate
uv sync

Code Quality (Dev Dependencies)

uv sync --extra dev
make style           # Format code with ruff
make check_code_quality  # Lint code with ruff

Use Docker

make build
make run

📈 Streamlit Dashboard

Check out the Streamlit app for workout analysis & performance management.

Start Streamlit App

cd app/
streamlit run app.py

Dashboard Preview

After clicking login, you will be redirected to the Strava login page. After logging in, you will be redirected back to the app.

Successful Login

streamlit_dashboard

Workout Summary

weekly-tss

Performance Management Chart

performance-management

References

  1. Power Zones by Strava
  2. Power Zones by Pro Cycling Coaching
  3. Strava Guide: Features to Take Your Training to The Next Level
  4. TSS, IF, NP
  5. TSS by Peaksware
  6. CTL by Peaksware
  7. A blog about CTL and ATL
  8. More indepth CTL and ATL analysis
  9. A blog about CTL, ATL, and TSB in Chinese

Strava API

OAuth 2.0 with Strava

  1. Redirect the user to the Strava authorization page with the following parameters:

    • client_id: Your Strava API client ID
    • redirect_uri: The URL to redirect to after authorization. Must be within the callback domain specified by the application. localhost and 127.0.0.1 are white-listed.
    • response_type: Set to "code"
    • scope: The permissions you want to request (e.g., "read,activity:read")
    • approval_prompt=force: (optional) Forces the user to approve each time

    Example:

    https://www.strava.com/oauth/authorize?client_id=YOUR_CLIENT_ID&response_type=code&redirect_uri=YOUR_REDIRECT_URI&approval_prompt=force&scope=read,activity:read
  2. After user approval, Strava redirects the user back to your specified redirect_uri with an authorization code in the URL query string:

    https://yourapp.com/callback?code=AUTHORIZATION_CODE&scope=accepted_scopes
  3. The backend exchanges the authorization code for tokens:

    • Make a POST request to the Strava token endpoint with the following parameters:
      • client_id: Your Strava API client ID
      • client_secret: Your Strava API client secret
      • code: The authorization code received in step 2
      • grant_type: Set to "authorization_code"

    Example:

    curl -X POST https://www.strava.com/oauth/token \
    -d "client_id=YOUR_CLIENT_ID" \
    -d "client_secret=YOUR_CLIENT_SECRET" \
    -d "code=AUTHORIZATION_CODE" \
    -d "grant_type=authorization_code"
  4. Strava responds with an access token and a refresh token:

    Strava's response includes JSON containing:

    • access_token (short-lived)
    • refresh_token (used to obtain new access tokens)
    • User information (e.g., athlete ID).

Patch Streamlit index.html

Using st.set_page_config does not immediately set the title and page icon; for a fraction of a second, you will still see Streamlit's default logo and title. To avoid this, you need to patch the index.html file in the Streamlit source code.

The index.html file is located at <python-env>/lib/<python-version>/site-packages/streamlit/static.

About

Exploring cycling data

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors