Skip to content

Instantly share code, notes, and snippets.

@akbertram
Created January 9, 2020 10:48
Show Gist options
  • Save akbertram/d9202ac40f46be1553000a19eab69aa8 to your computer and use it in GitHub Desktop.
Save akbertram/d9202ac40f46be1553000a19eab69aa8 to your computer and use it in GitHub Desktop.
library(httr)
offset <- 0
classifications <- list()
while(TRUE) {
res <- content(GET(sprintf("https://eventresults-api.sporthive.com/api/events/6607610161960078848/races/470648/classifications/search?count=50&offset=%d", offset)))
if(length(res$fullClassifications) == 0) {
break;
}
classifications <- c(classifications, res$fullClassifications)
offset <- offset + 50
cat(sprintf("offset = %d\n", offset))
}
nq <- function(n)
sapply(classifications, function(x) {
v <- x$classification[[n]]
if(is.null(v)) NA else v
})
results <- data.frame(bib = nq("bib"),
category = nq("category"),
rank = nq("rank"),
gunTime = nq("gunTime"),
chipTime = nq("chipTime"),
name = nq("name"),
country = nq("countryCode"),
gender = nq("gender"),
stringsAsFactors = FALSE)
results$chipRank <- rank(results$chipTime, ties.method = "first")
results$chipPercentile <- 100 - (results$chipRank / nrow(results) * 100)
m35 <- subset(results, category == 'M35')
m35 <- m35[order(m35$chipTime), ]
m35$chipRank <- rank(m35$chipTime, ties.method = "first")
m35$chipPercentile <- 100 - (m35$chipRank / nrow(m35) * 100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment