Giter Site home page Giter Site logo

pelotonr's Introduction

pelotonR

Lifecycle: maturing

pelotonR provides an R interface into the Peloton data API. The package handles authentication, response parsing, and provides helper functions to find and extract data from the most important endpoints.

Installation

Currently on Github only. Install with:

devtools::install_github("bweiher/pelotonR")

Overview

Authentication

You need to set environmental variables: PELOTON_LOGIN and PELOTON_PASSWORD, or provide them in this initial step, which must be run before you can issue other queries.

library(pelotonR)
peloton_auth()

Data Available

The main endpoints each have their own helper function that helps parse the API response into a tibble, as well as iterating through multiple inputs if necessary.

You can also query other endpoints using peloton_api in case new endpoints are introduced, or if the automatic parsing fails (can also set p.

The table below documents each endpoint along with its R counterpart, and provides a description of what data is there:

endpoint function endpoint description
api/me get_my_info() info about you
api/workout/workout_id/performance_graph get_performance_graphs() time series metrics for individual rides
api/workout/workout_id get_workouts_data() data about rides
api/user/user_id/workouts get_all_workouts() lists n workouts

You can show which endpoint (and arguments) are being passed on under the hood by setting the print_path to TRUE in any of the get_ functions or in the peloton_api function directly.

Queries

There are a couple endpoints where you need to already know some piece of information to get that particular data.

For example, to list workouts, you will need your user_id, which you can get from the api/me endpoint.

Either supply it or set it as an environmental variable, PELOTON_USERID:

# get data about yourself
me <- get_my_info() # peloton_api("api/me")
user_id <- me$id

It can then be used against the workouts endpoint, to fetch your workout_id's:

# get a list of your workouts
workouts <- get_all_workouts(user_id) # peloton_api("api/$USER_ID/workouts")
workout_ids <- workouts$id

The final two endpoints contain your performance graphs and other workout data. You need to provide workout_id's here, but each function accepts multiple at once:

# get performance graph data
# vectorized function
pg <- get_performance_graphs(workout_ids) # peloton_api("api/workout/$WORKOUT_ID/performance_graph")

# get other workout data
# vectorized function

wd <- get_workouts_data(workout_ids = workout_ids)

โŒErrors โŒ

Sometimes the data types returned for particular fields will differ across rides, resulting in an error, like below:

#> Error: Can't combine `..1$v3_custom_column_name` <integer> and `..10$v3_custom_column_name` <character>.

Each function provides a dictionary of mappings for a few fields that have been identified as being problematic like v3_custom_column_name above.

If the defaults fail, you can override (just be sure to also look at the what the function has set by default).

In the hypothetical previous error the v3_custom_column_name column had an issue:

# fix for error 
workouts <- get_all_workouts(
userid = user_id,
dictionary = list(
"numeric" = c("v3_custom_column_name")
)
)

You can coerce fields to one of (character, numeric, or list) if you see an error pop up.

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.