Last active
January 22, 2017 20:03
-
-
Save romovpa/9ee2fc7a5d38e4390437e57215d1ceb8 to your computer and use it in GitHub Desktop.
Query OpenDota from R
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(jsonlite) | |
library(dplyr) | |
opendota.query <- function(sqlQuery) { | |
requestUrl = paste("https://api.opendota.com/api/explorer?sql=", URLencode(sqlQuery), sep="") | |
result <- fromJSON(requestUrl) | |
return(result$rows) | |
} | |
sampleQuery = "select * from public_matches where start_time > 1483362553 AND duration > 900 AND avg_mmr > 2500 AND num_mmr > 2 limit 10" | |
opendota.query(sampleQuery) | |
sampleQuery = " | |
SELECT | |
match_id, | |
account_id, | |
player_slot, | |
hero_id, | |
actions.key AS action, | |
actions.value AS action_cnt | |
FROM player_matches, | |
json_each_text(player_matches.actions) AS actions | |
LIMIT 50" | |
opendota.query(sampleQuery) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment