robiningelbrecht/strava-activities-template

dev-master 2024-12-16 13:38 UTC

This package is auto-updated.

Last update: 2024-12-16 13:39:17 UTC


README

Strava

CI Codecov.io License PHPStan Enabled PHP

Strava activities template

This repository is deprecated. Please use the new docker image: https://github.com/robiningelbrecht/strava-statistics

This repository contains the template code to generate your own Strava statistics pages. Just follow the steps below. If you experience any issues with any of the steps, feel free to open an issue. I'll be glad to help you out 💅.

🦄 Examples

🪄 What you'll need

  • A Strava API key
  • A GitHub account

🛠️ Installation

  • Make sure your logged in with your GitHub account
  • Start off by showing some ❤️ and give this repo a star
  • Create a new repository using this template by clicking HERE and filling out the required fields
  • Navigate to your newly created repository Actions secrets and variables page (https://github.com/[YOUR-GITHUB-USERNAME]/[REPOSITORY-NAME]/settings/secrets/actions) Keep this page open, you will need to add several secrets here
  • Next, navigate to your Strava API settings page. Copy the client ID and client secret Strava API keys
  • Create two new repository secrets Repo secrets
    • name: STRAVA_CLIENT_ID, value: client ID copied from Strava API settings page
    • name: STRAVA_CLIENT_SECRET, value: client secret copied from Strava API settings page
  • Now you need to obtain a Strava API refresh token. This might be the hardest step.
    • Navigate to https://developers.strava.com/docs/getting-started/#d-how-to-authenticate and scroll down to "For demonstration purposes only, here is how to reproduce the graph above with cURL:"
    • Follow the 11 steps explained there
    • Make sure you set the scope in step 2 to activity:read_all to make sure your refresh token has access to all activities Refresh token
    • Create a repository secret with the refresh token you obtained: name: STRAVA_REFRESH_TOKEN, value: The refresh token you just obtained
  • You should end up with these repository secrets: Repository secrets
  • After this you need to make sure the automated workflow is able to push changes to your repo.
  • The last thing you need to do is edit the workflow files update-strava-activities.yml, update-ftp.yml and update-key-value-store.yml:
    • Navigate to https://github.com/[YOUR-GITHUB-USERNAME]/[REPOSITORY-NAME]/edit/master/.github/workflows

    • Edit the file Edit workflow

    • Uncomment line 4 and 5 by removing the # character

    • Scroll down to:

      name: Initialize GIT
      run: |
        git config --global user.name 'YOUR_GITHUB_USERNAME'
        git config --global user.email 'YOUR_GITHUB_USERNAME@users.noreply.github.com'
      • Replace YOUR_GITHUB_USERNAME with your own username
      • Click commit changes at the top right-hand corner
    • Do this again for the other 2 files

Configuration

Before running the first activity import, you need to

!!! It's important you wait until a workflow is done, before running another one !!!

☁️ Hosting the HTML version

There's also a HTML versions available with a lot more features. You can easily host this for free on https://vercel.com:

  • Create an account and login
  • Make sure your connect to your GirHub account (https://vercel.com/account/login-connections)
  • Create a new project and reference your repository
  • For the Framework preset setting use Other
  • Make sure the Root directory is set to build/html
  • You can uncheck the option Include source files outside of the Root Directory in the Build Step.
  • You should be good to go

🧐 Some things to consider

  • Any new feature or update added to the template, will automatically end up in your repository 🪄
  • Only (virtual) bike rides are imported, other sports are not relevant for these stats
  • Because of technical (Strava) limitations, not all Strava challenges can be imported. Only the visible ones on your public profile can be imported (please be sure that your profile is public, otherwise this won't work)
  • Strava statistics will be re-calculated once a day. If you want to re-calculate these manually, navigate to https://github.com/[YOUR-GITHUB-USERNAME]/[REPOSITORY-NAME]/actions/workflows/update-strava-activities.yml and click Run workflow at the right-hand side
  • Running the import for the first time can take a while, depending on how many activities you have on Strava. Strava's API has a rate limit of 100 request per 15 minutes and a 1000 requests per day. We have to make sure this limit is not exceeded. See https://developers.strava.com/docs/rate-limits/. If you have more than 500 activities, you might run into the daily rate limit. If you do so, the app will import the remaining activities the next day(s).
  • If you get following error App\Infrastructure\Exception\EntityNotFound: KeyValue "athlete_birthday" not found, it means that you have not set your birthday. Run the "Update athlete birthday" workflow

❌ Getting errors while updating FTP / KeyValue store?

This is because I introduced breaking changes without realising it. Yeah, I know stupid. GitHub does not allow you to automatically update workflow files from a template, so you'll have to do this manually.

Update the following files in your own repository to the latest versions:

💡 Feature request?

For any feedback, help or feature requests, please open a new issue

💻 Local development

If you want to add features or fix bugs yourself, you can do this by setting up the project on your local machine. Just clone this git repository and you should be good to go.

The project can be run in a single Docker container which uses PHP. There's also a Make file to... make things easier:

# Run a docker-compose command.
make dc cmd="run"

# Run "composer" command in the php-cli container.
make dcr cmd="composer"

# Run an app console command
make console arg="app:some:command"

# Run the test suite.
make phpunit

# Run PHPStan
make phpstan

For other useful Make commands, check Makefile

📓 Change Log

All notable changes to this project will be documented in this file.

[2023-01-17]

  • Added hours of riding to weekly stats chart
  • Fixed bug where importing of segments crashed on first run (thanks to dylix for reporting)

[2023-01-13]

  • Added yearly stats

[2023-01-05]

  • Refactored activity and segment overview to be way faster

[2023-01-01]

  • Added first version of heatmap

[2023-12-28]

  • Show segments in activity modal
  • Several small improvements and bug fixes

[2023-12-24]

  • Fix bug where rendering of HTML crashed on non-Zwift virtual activities. (thanks to pdoteter)

[2023-12-23]

  • Delete orphaned activities (thanks to mdleye)

[2023-12-21]

  • Split up database into multiple databases, one for each year there is data for. (thanks to pdoteter for testing with huge dataset)

[2023-12-19]

  • Render and display segments and efforts

[2023-12-18]

  • Reduced DB size by over 50%
  • Import and process segments

[2023-12-03]

  • Added challenge consistency table (thanks to rubenbuysse)

[2023-12-01]

  • Added a monthly calendar view for activities
  • Fixed bug in router

[2023-11-25]

  • Moved gear stats to separate page

[2023-11-18]

  • Added Power and heart rate distribution charts

[2023-11-13]

  • Changed activity drawer with modal

[2023-11-09]

  • Added average speed and distance to multiple stats

[2023-11-07]

  • Allow to import challenge/trophy case history
  • Fix import of double challenges

[2023-11-04]

  • Better masonry layout
  • Show number of photos on tabs
  • Fixed workflow database errors (thanks to mdleye)

[2023-11-02]

  • Added "Time in heart rate zone" charts
  • Optimized existing charts

[2023-10-30]

  • Render FTP history chart

[2023-10-29]

  • Show FTP history
  • More accurate calculation of activity intensity

[2023-10-26]

  • Better moving time formatting

[2023-10-25]

  • Added better tooltips to charts

[2023-10-25]

  • Show longest consecutive streak

[2023-10-24]

  • Added activity stream chart in activity drawer

[2023-10-21]

  • Migrated weather data to separate field

[2023-10-20]

  • Added distance breakdown table
  • Added daytime stats
  • Monthly stats: filter out months that have no activities (thanks to mdleye)
  • Add sorting to the activity list
  • Reworked weekday stats

[2023-10-19]

  • Fixed bug when deploying new template version

[2023-10-15]

  • Initial stable release of the template

[2023-10-12]

  • Bug fixes while importing large sets of Strava activities (thanks to rubenbuysse for testing)