Skip to content

Instantly share code, notes, and snippets.

@z1lc
Last active August 15, 2016 03:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save z1lc/9b4e9433fef608953e9e7ea2f06f33ea to your computer and use it in GitHub Desktop.
Save z1lc/9b4e9433fef608953e9e7ea2f06f33ea to your computer and use it in GitHub Desktop.
Fitbit Surge vs. Polar H7 + Nexus 6 + Strava: Comparing Heart Rate Sensors
library(XML)
library(dplyr)
library(lubridate)
library(reshape2)
library(ggplot2)
fitbit <- xmlToDataFrame(getNodeSet(xmlParse("fitbit.tcx"), "//ns:Trackpoint", "ns"),
stringsAsFactors = FALSE)
strava <- xmlToDataFrame(getNodeSet(xmlParse("strava.tcx"), "//ns:Trackpoint", "ns"),
stringsAsFactors = FALSE)
fitbitG <- fitbit %>%
mutate(
Time = as.POSIXct(strptime(Time, "%Y-%m-%dT%H:%M:%S")),
HeartRateBpm = as.numeric(HeartRateBpm)
) %>%
select(Time, HeartRateBpm)
stravaG <- strava %>%
mutate(
Time = as.POSIXct(strptime(Time, "%Y-%m-%dT%H:%M:%SZ") - hours(7)),
HeartRateBpm = as.numeric(HeartRateBpm)
) %>%
select(Time, HeartRateBpm) %>%
filter(Time >= as.POSIXct("2016-08-14 17:38:10"))
both <- full_join(fitbitG, stravaG, by = c("Time")) %>%
rename(
"Fitbit Surge" = HeartRateBpm.x,
"Strava + Nexus 6 + H7" = HeartRateBpm.y)
both %>%
na.omit() %>%
transmute(diff = .[[2]] - .[[3]]) %>%
summarise(averageDifference = mean(diff))
longData <- melt(both, id.vars = "Time") %>%
na.omit()
ggplot(longData, aes(Time, value, color = variable)) +
geom_line() +
coord_cartesian(ylim = c(120, 190)) +
labs(title = "Comparing Heart Rate Sensor Readings") +
theme(legend.position = "bottom")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment