Giter Club home page Giter Club logo

strava-best-efforts's Introduction

Strava Best Efforts


NOTE

I'm rewriting this app using Ruby on Rails and can be accessed at http://strafforts.yizeng.me. It's only just work in progress, so it's not open sourced yet, the Heroku server only starts when someone visits the app and the worker process only run once a day in order to minimize any costs.

It means the new app will take a while to load if it's been inactive for more than 30 minutes and after connect with Strava, the data won't pulled from Strava until the next day.

It's welcomed and much appreciated if you want to have a play around and help me testing it.


This small app fetches Strava running best efforts using Strava API, then fires up a webpage to visualize the best efforts data, so that some analysis can be performed on athletes' best efforts data, like half marathon PB progression, fastest shoes for a 10K race, etc.

DEMO HERE: Strava Best Efforts - Yi Zeng

Demo Screenshot

Ideally in the future, this app can be setup and served in a similar fashion as VeloViewer, with front-end UI, back-end DB and a bacground process:

  1. (Users) Open up this web application and see 'Connect with Strava' button.
  2. (Users) Click the button and go through Strava authentication process.
  3. (Users) Get redirected back to this application.
  4. (Server) Save all authentication information to database on the server.
  5. (Background process) Run on the server and get this athlete's data using Strava API.
  6. (Users) See a detailed user interface for analyzing their best efforts data.
  7. (Users) Visit the site anytime later and view all data (which are saved on the server).

Currently the app only contains a background fetching process and a front-end visualizer, as it was all started few as Ruby scripts I wrote to fetch my own Strava Best Efforts.

Documentation

What are 'Best Efforts'?

Quoting from Strava Support:

Estimated Best Efforts are automatically calculated using your GPS-based running activity, and reflect your fastest times for benchmark distances such as 1 mile, 5km, 10km, and half marathon. Strava can find your best effort at any point in each running activity. We do not require that a best effort starts at a mile split.

Side by side Best Efforts Strava Best Efforts

How does this program work?

  1. In fetching mode (ruby app.rb --fetch), the program calls list_athlete_activities from Strava Ruby API to get all activities of current athlete. It tries to get 200 activities per page, maximum of 100 pages, which can hold a total number of 20000 activities. (Strava won't allow more than 200 activities per page.)
  2. Then it loops through all those activities to find out all running activities that have achievement items, and saves the activity ids to a result set.
  3. For each activity id in the result set, call Strava Ruby API retrieve_an_activity method to get detailed information about this activity.
  4. Then calling ruby app.rb --serve command (the serving mode) will serve a web application with JSON data just fetched and provide a visualized way for analysis.

How to run?

Setup config.yml

Get Strava Access Token

All calls to the Strava API require an access_token defining the athlete and application making the call. Any registered Strava user can obtain an access_token by first creating an application at https://www.strava.com/settings/api.

Set directory for result JSON files

dir_result sets the directory where result JSON file should be saved. It defaults to history/ folder where app.rb file is. Every successful run should generate a new file under such folder.

Install Dependencies

At this stage, the app has only Ruby Gem 'strava-api-v3' as a dependency.

gem install 'strava-api-v3'

Or use Ruby Bundler if you prefer:

gem install bundler # if you haven't got bundler installed yet.
bundle install

Run Program

Fetch mode (It fetches the athlete and best efforts data):

ruby app.rb -f

Serve mode (It loads up the JSON files and server at http://localhost:5050):

ruby app.rb -s

What does JSON result look like?

Here is an example JSON result file for my Strava Activity Southern Lakes Half Marathon 2016:

{"pr_rank":1,"activity_id":690235515,"activity_name":"Southern Lakes Half Marathon 2016","distance":21138.8,"moving_time":5645,"elapsed_time":5631,"total_elevation_gain":16.0,"start_date":"2016-04-02T08:59:58Z","start_date_local":"2016-04-02T08:59:50Z","start_latitude":-44.86,"start_longitude":169.03,"athlete_count":8,"trainer":false,"commute":false,"manual":false,"private":false,"average_speed":3.745,"max_speed":5.2,"has_heartrate":true,"elev_high":500.0,"elev_low":282.2,"workout_type":1,"description":"(Uploaded via API. Gear name: ASICS DS Trainer 19 (Blue). Device name: Garmin Forerunner 235. Workout Type: 1)","calories":1590.9,"device_name":null,"location_country":"New Zealand","average_heartrate":169.2,"max_heartrate":180.0,"gear_name":"ASICS DS Trainer 19 (Blue)","name":"Half-Marathon"}

How JSON results are used?

Strava Best Efforts - Yi Zeng page is a demo on how JSON results are used. It loads up the JSON file created using this program, then analyze the data and output into a table.

strava-best-efforts's People

Contributors

bagage avatar lucagrulla avatar yizeng avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.