This repository contains R scripts for connecting to the Sports Data Valley (SDV) API to retrieve wearable data from users (Fitbit, Garmin) in research groups, quantify missing or incomplete heart rate time series, and provide interactive visualization tools for researchers.
The pipeline is part of the Stress in Action consortium (Research Theme 2), which focuses on reliable real-time measurement of daily life stress and its impact on health using wearable technology.
Step 1: Setup and Authentication
Create a .Renviron file with your API credentials and group ID:
BASE_URL=https://app.sportdatavalley.nl
API_PATH=/api/v1
AUTH_HEADER=Bearer your-token
GROUP_NO=your-group-idInstall required R packages:
install.packages(c("httr", "lubridate", "rjson", "here", "tidyverse", "plotly", "data.table"))Step 2: Retrieve Group Information
Use the provided function get_group_info() to list all members in your SDV group. This step creates a profile_list object with user IDs and names.
Fetch all activity data for your group using the get_all_group_rec_act() function. This retrieves recent VDOs (Versioned Data Objects) and parses structured data for:
- User ID and name
- Data type (Fitbit or Garmin)
- Date of measurement (
dateTimeorcalendar_date) - Heart rate time series (
heart_intra_dayfor Fitbit ortime_offset_heart_rate_samplesfor Garmin) - Versioned Data Object ID
The script checks whether:
- The time series is
NULL - The length of the series is less than 50% of expected values:
- Fitbit:
(60 × 24) / 2samples - Garmin:
(4 × 60 × 24) / 2samples
- Fitbit:
Filtered data is saved in filtered_data, grouped by user ID and including:
- User Info: first name, last name
- Record Details: date, time series length, dataset ID
The visualize_missing_data.R script creates an interactive Plotly scatter plot:
- X-axis: Date of measurement
- Y-axis: Time series length
- Dropdown menu: Select a user to filter the view
- Hover details: User name, ID, date, samples, dataset ID
Use get_data() to retrieve and explore specific VDOs:
- Extract heart rate time series
- Convert to a tidy data frame
- Generate an interactive line plot of heart rate values over time using Plotly
An example output is an interactive scatter plot where each point represents a daily record for a user. Researchers can quickly identify:
- Days with missing time series (0 samples)
- Days with incomplete coverage
API Documentation and Resources
