TheAthlytics R package simplifies advanced analysis ofathletic performance and training load using data sourced directly fromthe Strava API. It provides functions to fetch Strava data (via therStrava package), calculate key metrics based on sportsscience principles, and generate insightful visualizations for trainingmonitoring.
This vignette covers:
You can install the released version of Athlytics from CRAN (onceavailable) with:
Alternatively, install the development version from GitHub:
Athlytics requires a valid Strava API token to fetchdata. This is handled using therStrava package.
localhost.rStrava::strava_oauth().cache = TRUE is highly recommended to securelystore the token and avoid re-authenticating every session.# --- Example Authentication Code ---# (Do not run this block directly in the vignette build)# Replace with your actual credentials or use environment variables# app_name <- 'MyAthlyticsApp'# client_id <- "YOUR_CLIENT_ID"# client_secret <- "YOUR_SECRET"# This function performs the OAuth handshake (may open browser)# stoken <- rStrava::strava_oauth(# app_name,# client_id = client_id,# client_secret = client_secret,# app_scope = "activity:read_all", # Ensure necessary scopes# cache = TRUE # IMPORTANT: caches the token# )# For the examples below, we assume you have obtained a valid token# object named 'stoken' in your interactive R session.# Replace this placeholder line if running interactively:stoken_placeholder<-"<Replace this string with your actual stoken object>"# You would use the real 'stoken' object in function calls, e.g.:# some_data <- calculate_acwr(stoken = stoken, ...)Important: The following examples usestoken = stoken_placeholder and haveeval=FALSE. You need to replacestoken_placeholder with your actual token object(stoken) and potentially seteval=TRUE ifrunning interactively with a valid, cached token.
These functions generate plots to analyze trends and performance.
Visualizes the relationship between short-term (acute) and long-term(chronic) training load to assess readiness and potential injury risk.Note that TSS/HRSS calculations based on activity summaries areapproximations.
# Calculate using approximate TSS for Rides (Requires FTP)exposure_data_tss<-calculate_exposure(stoken = stoken_placeholder,activity_type ="Ride",load_metric ="tss",user_ftp =280,# Example FTP, replace with yoursacute_period =7,chronic_period =28)# Plot the resultplot_exposure(exposure_data = exposure_data_tss,risk_zones =TRUE)# Calculate using approximate HRSS for Runs (Requires Max & Resting HR)hrss_data<-calculate_exposure(stoken = stoken_placeholder,activity_type ="Run",load_metric ="hrss",user_max_hr =190,# Example Max HRuser_resting_hr =50,# Example Resting HRacute_period =7,chronic_period =42)plot_exposure(exposure_data = hrrss_data,risk_zones =TRUE)Tracks the Acute:Chronic Workload Ratio over time, highlightingperiods of potentially risky load increases.
Monitors aerobic efficiency, typically calculated as output (Pace orPower) divided by input (Heart Rate). Requires activities with bothrelevant metrics.
Visualizes the progression of estimated best efforts over variousdistances (currently primarily for running).
Note: Fetching PB data can be slow andAPI-intensive.
Assesses cardiovascular drift during activities by comparingperformance (Pace or Power) in the first half vs. the second halfrelative to Heart Rate.
Note: Fetching decoupling data now uses directStrava API calls viahttr (instead ofrStrava::get_activity_streams) to obtain detailed activitystreams. This can be very slow and may hit API rate limits more easily,especially for many activities. Consider using themax_activities parameter.
# Calculate Pace/HR decoupling for Runs# Limit activities checked for speeddecoupling_data_run<-calculate_decoupling(stoken = stoken_placeholder,activity_type ="Run",decouple_metric ="Pace_HR",max_activities =20# Limit for example)# Plot the trendplot_decoupling(decoupling_data = decoupling_data_run,add_trend_line =TRUE)MyAthlyticsApp)This vignette provides a basic overview. For details on specificfunctions, their parameters, and underlying calculations, please consultthe function help pages (e.g.,?calculate_acwr,?plot_acwr) in R.
For bug reports or feature requests, please use the GitHub repositoryissues tracker:https://github.com/HzaCode/Athlytics/issues