Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/robiningelbrecht/strava-activities-template

This repository contains template code to generate your own Strava statistics pages
https://github.com/robiningelbrecht/strava-activities-template

strava strava-data website

Last synced: about 1 month ago
JSON representation

This repository contains template code to generate your own Strava statistics pages

Awesome Lists containing this project

README

        


Strava


CI
Codecov.io
License
PHPStan Enabled
PHP

---

# Strava activities template

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](https://github.com/robiningelbrecht/strava-activities-template/issues/new). I'll be glad to help you out 💅.

## 🦄 Examples

* Markdown version: https://github.com/robiningelbrecht/strava-activities
* HTML version: https://strava-statistics.robiningelbrecht.be/

## 🪄 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](https://github.com/new?template_name=strava-activities-template&template_owner=robiningelbrecht) 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](https://www.strava.com/settings/api).
Copy the `client ID` and `client secret`
![Strava API keys](files/install/strava-api-keys.png)
* Create two new repository secrets
![Repo secrets](files/install/repository-secrets.png)
* __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](files/install/strava-refresh-token.png)
* 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](files/install/secrets-example.png)
* After this you need to make sure the automated workflow is able to push changes to your repo.
* Navigate to https://github.com/[YOUR-GITHUB-USERNAME]/[REPOSITORY-NAME]/settings/actions
* Scroll down to `Workflow permissions` and make sure `Read and write permissions` is checked
![Workflow permissions](files/install/workflow-permissions.png)
* 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](files/install/edit-workflow.png)
* Uncomment line 4 and 5 by removing the `#` character
* Scroll down to:
```yml
name: Initialize GIT
run: |
git config --global user.name 'YOUR_GITHUB_USERNAME'
git config --global user.email '[email protected]'
```

* 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 !!!__

* Set your birthday. This is required to 1) accurately calculate the intensity of your activities
in case no power data is available, 2) determine your heart rate zones
* Navigate to https://github.com/[YOUR-GITHUB-USERNAME]/[REPOSITORY-NAME]/actions/workflows/update-key-value-store.yml
* Fill out your birthday using date format `YYYY-MM-DD` and run the workflow
![Update birthday](files/install/update-birthday.png)
* (Optional, but recommended) Configure your FTP (= Functional Threshold Power) history.
* Navigate to https://github.com/[YOUR-GITHUB-USERNAME]/[REPOSITORY-NAME]/actions/workflows/update-ftp.yml
* Fill out the FTP and the date (`YYYY-MM-DD`) you've set the FTP on and run the workflow
![Update FTP](files/install/update-ftp.png)
* Do this for every FTP you've set
* (Optional) Strava does not allow to fetch all your completed challenges and trophies (see Some things to consider),
but there's a little workaround if you'd like to import those:
* Navigate to https://www.strava.com/athletes/[YOUR_ATHLETE_ID]/trophy-case
* Open the page's source code and copy everything
![UTrophy case source code](files/install/trophy-case-source-code.png)
* Next navigate to https://github.com/[YOUR-GITHUB-USERNAME]/[REPOSITORY-NAME]/edit/master/files/strava-challenge-history.html
* Paste the source code you just copied and `commit changes` at the top right-hand corner
* On the next run of the `import activities` workflow, all your challenges will be imported

## ☁️ 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:
* https://github.com/robiningelbrecht/strava-activities-template/blob/master/.github/workflows/update-ftp.yml
* https://github.com/robiningelbrecht/strava-activities-template/blob/master/.github/workflows/update-key-value-store.yml

## 💡 Feature request?

For any feedback, help or feature requests, please [open a new issue](https://github.com/robiningelbrecht/strava-activities-template/issues/new)

## 💻 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:

```bash
# 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](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](https://github.com/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](https://github.com/pdoteter))

#### [2023-12-23]

* Delete orphaned activities (thanks to [mdleye](https://github.com/mdleye))

#### [2023-12-21]

* Split up database into multiple databases, one for each year there is data for.
(thanks to [pdoteter](https://github.com/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](https://github.com/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](https://github.com/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](https://github.com/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](https://github.com/rubenbuysse) for testing)