Song of the Run

June 24, 2022

My friends and I who run use an app called Strava to share our runs and other workouts with each other. A common caption for running posts is your “Song of the Run” to show what your favorite song from your workout was. I wanted to figure out not just what my favorite was, but see which song helped me to run the fastest. To accomplish this I looked for ways to analyze both my Spotify listening data as well as the data from my Strava runs.

My first step was to figure out what data I had available to work with. I found that you can download data from a run from Strava’s website in a file with lots of cool data like location, speed, and timestamps. Next I found a python library called Spotipy for interacting with Spotify’s API. There’s tons of data that you can find here which includes users’ listening history with timestamps. Spotipy made accessing the data super simple since it took care of all of the API interactions for me.

After parsing the Strava data file, I left myself with a list of data points containing the current pace and timestamp throughout the run. From Spotify, I grabbed a list of the latest songs the user listened to with the timestamp each one started playing. Now I could easily filter through the Strava data based on the timestamps of each song. By doing this I was able to calculate the average running pace during each song and find the one that made me run the fastest.

The last thing I wanted to do was send this information to my phone somehow. The solution I found was to use the SMTP protocol client to send an email to myself. This library was super easy to use and takes care of pretty much everything for sending the email. 

In the end I was successful in calculating the “Song of the Run”, but it doesn’t work automatically yet. Next time I work on this project, I want to use Strava’s API to watch for new runs and download the data for me instead of having to do this manually.

Going forward, I want to use more of the available data from Spotify’s API to further explore the effects of different types of music on running performance. The data that’s available for each song includes its tempo, genre,  ratings for different attributes like “energy”, “danceability”, and “loudness”, and a bunch more. There’s definitely some cool analysis you could do to put together the perfect workout playlist!