Giter Site home page Giter Site logo

pelotonr's People

Contributors

bweiher avatar dusty-turner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

pelotonr's Issues

shiny dashboard

it would be cool to create a nice shiny dashboard that could:

  • update gathered data (maybe add to a local data store or DB ; incrementally find new data it needs)

  • create some plots based off data
    show user progress

  • activity patterns, etc

issue with joins in get_all_workouts()

library(pelotonR)
library(tidyverse)


Sys.setenv("PELOTON_LOGIN" = "username")
Sys.setenv("PELOTON_PASSWORD" = "pw")

peloton_auth()

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

# ---------------- GET

pel_workouts <- get_all_workouts(user_id, num_workouts = me$total_workouts, joins = "ride,ride.instructor")

Error: Problem with `mutate()` input `live_stream_id`.
x character string is not in a standard unambiguous format
i Input `live_stream_id` is `(function (x, ...) ...`.

Getting this error when using joins = "ride,ride.instructor"

Error when retrieving workouts

I'm getting an error when I try to retrieve my workouts:

library(pelotonR)
peloton_auth()
#> [1] "Logged in"

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

# get a list of your workouts
workouts <- get_all_workouts(user_id) # peloton_api("api/user_id/workouts")
#> Error: Can't combine `..1$v2_total_video_watch_time_seconds` <integer> and `..18$v2_total_video_watch_time_seconds` <character>.

Allow for paging when querying workouts

It appears there is a limit of 100 responses when querying workouts, which means you have to page through in batches of 100 to get all workouts (if you have more than 100). Right now page=0 is hardcoded into the function, but it seems like there should be a way to make it so you can specify the page. I am currently using this, where the only thing I'm modiying is the page_num in the parameters and API call.

get_all_workouts_page <- function(userid = Sys.getenv("PELOTON_USERID"),
                             num_workouts = 20,
                             joins = "",
                             page_num = 0, 
                             dictionary = list(
                                 "numeric" = c(
                                     "v2_total_video_buffering_seconds",
                                     "v2_total_video_watch_time_seconds"
                                 )
                             ),
                             parse_dates = TRUE,
                             ...) {
    if (userid == "")
        stop("Provide a userid or set an environmental variable `PELOTON_USERID`",
             call. = FALSE)
    if (length(joins) > 1 ||
        !is.character(joins))
        stop("Provide joins as a length one character vector", call. = FALSE)
    
    # see if joins is provided, if so, append to request
    if (joins != "")
        joins <- glue::glue("joins={joins}")
    
    workouts <-
        peloton_api(
            glue::glue(
                "/api/user/{userid}/workouts?{joins}&limit={num_workouts}&page={page_num}"
            ),
            ...
        )
    n_workouts <- length(workouts$content$data)
    # v2_total_video_buffering_seconds v2_total_video_watch_time_seconds
    if (n_workouts > 0) {
        workouts <-
            purrr::map_df(
                1:n_workouts,
                ~ parse_list_to_df(
                    workouts$content$data[[.]],
                    dictionary = dictionary,
                    parse_dates = parse_dates
                )
            )
        
        # IF JOIN PARAM is specified, get data out for ride list and add it to that row
        if (joins != "") {
            rides <- purrr::map_df(1:n_workouts, function(x) {
                parse_list_to_df(
                    stats::setNames(workouts$ride[[x]], paste0(
                        "ride_", names(workouts$ride[[x]])
                    )),
                    dictionary = dictionary,
                    parse_dates = parse_dates,
                    ...
                )
            })
            
            dplyr::left_join(
                dplyr::mutate(workouts, rn = dplyr::row_number()),
                dplyr::mutate(rides, rn = dplyr::row_number()),
                by  = "rn"
            ) %>%
                dplyr::select(-.data$rn)
        } else {
            workouts
        }
    }
}

query caching

if you run get_perfomance_graphs (maybe get_all_workouts, but would have to be smart) repeatedly you may have to fetch and process the same data many times.

its possible to cache which workouts already have fetched data, so it doesnt hit the API. older results could be stored in local files.

Thank you

I just discovered today I can download my peloton data. then through lucky googling I found this package. Was worried I'd have to do this myself... Thanks for your work here - you've made my day!

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.