aaron-schroeder / distilling-flask

Strava app for display and analysis of personal running data, powered by Flask, Dash, and Pandas.
MIT License
3 stars 0 forks source link
flask pandas plotly-dash python strava strava-api

distilling-flask

Personal running data display and analysis app, powered by Flask/Dash/Pandas.

License


Table of Contents


Introduction

Given a valid client id and client secret for your Strava API app, this app talks to Strava's API and displays running activities in a variety of dashboards using plotly Dash.

I built this app so I could pick apart my raw Strava data, which includes data streams for elevation, grade, and moving/stopped periods. I think Strava presents data in an unrealistically favorable way in its app ecosystem, and I wanted to work with the raw feeds. There is power in looking at the reality of things.

If you have a [ersponal Strava API application, you can view any of your Strava runs in a dashboard powered by Plotly Dash. From there, you can save each run to a database, and view the long-term effects of training in a training log dashboard.

A demo app is available to view on my website.

See the Running the App below to see how everything works.


Dependencies and Installation

Check out the requirements file to see all dependencies.

Python IDE

Clone the repo:

git clone https://github.com/aaron-schroeder/distilling-flask.git

Change into the new directory and start a virtual environment. Then, install the requirements:

pip install -r requirements.txt

You should be able to run the app now. See Examples below for more info.

Docker container

Create an image by running the following command in the same dir as Dockerfile:

docker build -t distillingflask:latest .

Create and start a container from the image with

docker run --name distillingflask  \
    -e MODULE_NAME=application.app  \
    -e VARIABLE_NAME=server  \
    -e STRAVA_CLIENT_ID=<client id>  \
    -e STRAVA_CLIENT_SECRET=<client secret>  \
    -e PASSWORD=<password>  \
    -d  \
    -p 5000:80  \
    --rm  \
    distillingflask:latest

Running the App

Locally

Strava-connected, with your Strava app client id and client secret

This option pretty much gets you the full-blown app running on your local machine. You can now authorize the app to use the data from your Strava account.

To do this, you must:

To run the app using Flask's CLI:

STRAVA_CLIENT_ID=${STRAVA_CLIENT_ID}  \
STRAVA_CLIENT_SECRET=${STRAVA_CLIENT_SECRET}  \
PASSWORD=super_secret_password  \
flask --app application

List of activities

Saved activities in training log dashboard

Strava-disconnected, allowing a subset of features.

You don't need to set your app up with Strava to access some of its features like the file upload analysis dashboard. The command to run this configuration of the app is simpler.

Flask CLI:

PASSWORD=super_secret_password  \
flask --app 'application:create_app("dummy")'

distilling-flask CLI: To use df (the distilling-flask CLI), first install the package locally with pip install -e .

PASSWORD=super_secret_password  \
df rundummy

In a python script:

import os

import application

# Choose the password for this app. Ideally don't use your Strava password.
os.environ['PASSWORD'] = 'super_secret_password'
app = application.create_app()
app.run()

There are a number of optional settings that control the behavior of the simulated Strava client. They can all be set with environment variables, a .env file, or (in the case of the distilling-flask CLI) arguments to the command.

Filetypes accepted by the upload-to-analyze dashboard: