Created
January 9, 2020 10:48
-
-
Save akbertram/d9202ac40f46be1553000a19eab69aa8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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