Skip to content

Instantly share code, notes, and snippets.

@sisao
Last active May 1, 2017 08:41
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 sisao/78cf7d73f9d801abbf4ea1b51a1df7c2 to your computer and use it in GitHub Desktop.
Save sisao/78cf7d73f9d801abbf4ea1b51a1df7c2 to your computer and use it in GitHub Desktop.
"Power in zones over time" graph in R for GoldenCheetah
$$activity <- GC.activity()
$$metrics <- GC.metrics()
$$date <- $$metrics$date
$$zone <- GC.athlete.zones(date=$$date, sport="bike")
$$lows <- $$zone$zoneslow
$$colors <- $$zone$zonescolor
$$duration <- tail($$activity$seconds, n=1)
$$p <- $$activity$power
$$n = 10
$$group <- split($$p, ceiling(seq_along($$p)/$$n))
$$p2 <- sapply($$group, mean)
$$time <- $$activity$seconds[seq(1, length($$activity$seconds), $$n)]
$$breaks <- c(unlist($$lows), Inf)
$$cols <- c(unlist($$colors))[findInterval($$p2, vec=$$breaks)]
$$displaytime <- function(timevalue) {
$$totalMinutes <- timevalue %/% 60
$$totalSeconds <- sprintf("%02d", timevalue %% 60)
paste($$totalMinutes, $$totalSeconds, sep=":")
}
barplot($$p2,
names.arg=lapply($$time, $$displaytime),
space=0, border=NA,
col=$$cols
)
title(main="Power in zones", ylab = "Watts", xlab = "Time")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment