8 September 2016

Introduction

Outline

  • Motivation
  • Functionality of trackeR
  • Code examples and implementation detail

Questions to answer in the next 15 minutes:

  • Why care?
  • What can you do with trackeR?
  • How does it work?

Motivation

  • Increasing amount of fitness and sports data from GPS-enabled tracking devices.
  • Proprietary software for analysis from device manufacturers and various apps.
  • Open-source software Golden Cheetah for cycling analysis.
  • Typically tools for descriptive analysis, unlike the many opportunities in R.
  • trackeR aims to bridge the gap between the routine collection of such data and their analysis in R.
  • Relatively few R packages related to sports: sport management, ranking teams, scraping betting odds, etc and cycleRtools/elpatron for cycling data.

Package structure

What can you do?

  • Read data from Training Center XML (TCX) files, SQLite databases and Golden Cheetah JSON files.
  • Store the data in session-based, unit- and operation-aware objects of class trackeRdata.
  • Basic operations: summarise, plot, handle units, etc.
  • Analyse time in zones, work capacity above critical power/speed, distribution of training time.
  • Utilise the rich tool set of statistical methodology provided in R base and other packages.

Read data

Package structure: read functionality

Read data

library("trackeR")
filepath <- system.file("extdata", "2013-06-08-090442.TCX", 
                        package = "trackeR")
runDF <- readTCX(file = filepath, timezone = "GMT")
str(runDF)
## 'data.frame':    1191 obs. of  9 variables:
##  $ time      : POSIXct, format: "2013-06-08 08:04:42" ...
##  $ latitude  : num  51.4 51.4 51.4 51.4 51.4 ...
##  $ longitude : num  1.04 1.04 1.04 1.04 1.04 ...
##  $ altitude  : num  6.2 6.2 6.2 6.2 6.2 ...
##  $ distance  : num  0 1.68 5.28 8.33 14.88 ...
##  $ heart.rate: num  83 84 84 86 89 93 96 98 101 102 ...
##  $ speed     : num  0 0.594 1.416 1.928 2.614 ...
##  $ cadence   : num  NA 54 74 97 97 97 97 98 97 97 ...
##  $ power     : num  NA NA NA NA NA NA NA NA NA NA ...

Read data

runTr0 <- trackeRdata(runDF)
runTr1 <- readContainer(filepath, type = "tcx", timezone = "GMT")
identical(runTr0, runTr1)
## [1] TRUE
runTr2 <- readDirectory(system.file("extdata", package = "trackeR"), 
                        timezone = "GMT")
## Reading file /home/frick/lib/R/trackeR/extdata/2013-06-08-090442.TCX (file 1 out of 1) ...
## Cleaning up...Done
identical(runTr0, runTr2)
## [1] TRUE

Session-based data structure

  • Very basic data cleaning: no missing time stamps, heart rate of 0 set to NA.
  • Split observations in sessions based on ordered time stamps: any observations further apart than a threshold (default: 2 hours) are considered to be in different sessions.
  • Short gaps in recordings can occur within sessions, usually due to a reduced sampling rate or to the device being paused. We impute zero speed/power during such periods.
  • Store each session in a multivariate zoo object.
  • A trackeRdata object is a list of session objects with attributes for units of measurement and operations such as smoothing.

Example data

  • 27 sessions by a male runner in June 2013 available via
data("runs", package = "trackeR")
  • Different visualisations available
plot(runs, session = c(3,13))
plotRoute(runs, session = 1:4, source = "osm")
leafletRoute(runs, session = c(3,6,7,10,12,13,21))

Visualise sessions