Skip to contents

Calculates aerobic decoupling for Strava activities.

Usage

calculate_decoupling(
  stoken,
  activity_type = c("Run", "Ride"),
  decouple_metric = c("Pace_HR", "Power_HR"),
  start_date = NULL,
  end_date = NULL,
  min_duration_mins = 45,
  max_activities = 50,
  stream_df = NULL
)

Arguments

stoken

A valid Strava token from `rStrava::strava_oauth()`.

activity_type

Type(s) of activities to analyze (e.g., "Run", "Ride").

decouple_metric

Basis for calculation: "Pace_HR" or "Power_HR".

start_date

Optional. Analysis start date (YYYY-MM-DD string or Date). Defaults to one year ago.

end_date

Optional. Analysis end date (YYYY-MM-DD string or Date). Defaults to today.

min_duration_mins

Minimum activity duration (minutes) to include. Default 45.

max_activities

Maximum number of recent activities to analyze. Default 50.

stream_df

Optional. A pre-fetched data frame for a *single* activity's stream. If provided, calculates decoupling for this data directly, ignoring `stoken` and other fetching parameters. Must include columns: `time`, `heartrate`, and either `velocity_smooth`/`distance` (for Pace_HR) or `watts` (for Power_HR).

Value

Returns a data frame with `date` and `decoupling` [ a single numeric decoupling value if `stream_df` is provided.

Details

Calculates aerobic decoupling (HR drift relative to pace/power) using detailed Strava activity streams. Fetching streams via API can be slow.

Provides data for `plot_decoupling`. Compares output/HR efficiency between first and second halves of activities. Positive values indicate HR drift. Fetching streams via API using `httr` is slow and subject to rate limits.

Examples

# 使用模拟数据示例 (注意: 模拟数据本身已是计算结果, 此处仅作演示)
data(Athlytics_sample_data)
if (!is.null(athlytics_sample_decoupling)) {
  print(head(athlytics_sample_decoupling))
}
#> # A tibble: 6 × 2
#>   date       decoupling
#>   <date>          <dbl>
#> 1 2024-11-28       4.62
#> 2 2024-12-14       4.89
#> 3 2024-12-21     -30.0 
#> 4 2025-01-11     -14.8 
#> 5 2025-01-11       7.19
#> 6 2025-01-18       3.39

# \donttest{
# 使用真实数据的示例(需要认证)
stoken <- rStrava::strava_oauth(..., cache = TRUE)
#> Error: '...' used in an incorrect context

# 计算最近跑步的Pace/HR解耦 (限制为10次活动以提高速度)
run_decoupling <- calculate_decoupling(
    stoken = stoken,
    activity_type = "Run",
    decouple_metric = "Pace_HR",
    max_activities = 10
)
#> Error: object 'stoken' not found
print(tail(run_decoupling))
#> Error: object 'run_decoupling' not found
# }