fawda123 / rStrava

Functions to access data from Strava's v3 API.
154 stars 31 forks source link

Lap data #76

Closed olangford closed 4 years ago

olangford commented 4 years ago

Hi,

Firstly, love the package. Very useful.

Is it possible to retrieve the laps segments from the strava API and add it to get_activity_streams?

Sorry if this isn't the place to post it. Please let me know if there is a more appropriate place.

Best,

Oliver

fawda123 commented 4 years ago

Hi @olangford, apologies for not responding sooner. I'm looking at the Strava API documentation - are you asking about retrieving segment data (i.e., https://developers.strava.com/docs/reference/#api-Streams-getSegmentEffortStreams)? I'm not sure what you mean by "laps data".

olangford commented 4 years ago

No worries @fawda123 . Thanks for looking into it.

I think what I'm after is the list activity laps (https://developers.strava.com/docs/reference/#api-Activities-getLapsByActivityId)

The lap data appears on strava when your watch clicks new lap or you have your watch setup for intervals. I'd like to be able to overlay some of my workouts.

What do you think?

fawda123 commented 4 years ago

@olangford does this work for you? Just change the activity id to the activity with laps data. Use the stoken you got when you went through the authentication process described on the readme.

id <- 3604906195
url_ <- paste("https://www.strava.com/api/v3/activities/", id, "/laps", sep="")
dataRaw <- get_basic(url_, stoken)

If that works, I can create a function around this API call.

olangford commented 4 years ago

Thanks @fawda123 Worked well. I can see the dataRaw[[1]]$start_index and dataRaw[[1]]$end_index for each of the laps.

Would be much appreciated if you can write the wrapper. Happy to help!

fawda123 commented 4 years ago

@olangford for sure, I can probably get to this next week.

fawda123 commented 4 years ago

@olangford I added the get_laps() function, try it out and let me know what you think.

stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE))
get_laps(stoken, id = 351217692)
#  activity.id activity.resource_state athlete.id athlete.resource_state average_heartrate
# 1   351217692                       1    2837007                      1              <NA>
#   average_speed distance elapsed_time end_index         id lap_index max_heartrate
# 1          7.38  17446.4         2363      2114 1103474011         1          <NA>
#   max_speed moving_time  name pace_zone resource_state split           start_date
# 1      13.2        2363 Lap 1      <NA>              2     1 2015-07-21T22:57:48Z
#       start_date_local start_index total_elevation_gain
# 1 2015-07-21T17:57:48Z           0                 52.2