Skip to content

Commit

Permalink
initial dataset of pc and psn players (top 300 each); xbox broken
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-keller committed Sep 4, 2018
1 parent 999aaa1 commit 836ab9f
Show file tree
Hide file tree
Showing 4 changed files with 5,107 additions and 6 deletions.
5 changes: 4 additions & 1 deletion ParseUserData.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ parseUserData<-function(response){
trnchange<-flatten_dbl(map(recent,function(x) x$trnRatingChange))
trnrating<-flatten_dbl(map(recent,function(x) x$trnRating))
gid<-flatten_int(map(recent,function(x) x$id))
df<-tibble::tibble(game_id=gid,kills=kills,score=score,ptype=playtype,trnchange=trnchange,trnrating=trnrating,matches=1:10)
res_ls$epicUserHandle
res_ls$platformName
df<-tibble::tibble(player_name=rep(res_ls$epicUserHandle,10),platform=rep(res_ls$platformName,10),game_id=gid,kills=kills,
score=score,ptype=playtype,trnchange=trnchange,trnrating=trnrating,matches=1:10)
return(df)
}

Expand Down
111 changes: 111 additions & 0 deletions education_example.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
---
title: "R Notebook"
output: html_notebook
---

This is an [R Markdown](http://rmarkdown.rstudio.com) Notebook. When you execute code within the notebook, the results appear beneath the code.

Try executing this chunk by clicking the *Run* button within the chunk or by placing your cursor inside it and pressing *Ctrl+Shift+Enter*.

```{r}
library(purrr)
setwd('C:/Users/thoma/Desktop/EducationOutreach/')
source('getUserData.R')
source('ParseUserData.R')
res<-getUserData('ninja','pc','your_fortnite_tracker_api')
res_df<-parseUserData(res)
res_ls<-jsonlite::fromJSON(content(res, "text"), simplifyVector = FALSE)
recent<-res_ls$recentMatches
kills<-flatten_int(map(recent,function(x) x$kills))
score<-flatten_dbl(map(recent,function(x) x$score))
playtype<-flatten_chr(map(recent,function(x) x$playlist))
trnchange<-flatten_dbl(map(recent,function(x) x$trnRatingChange))
trnrating<-flatten_dbl(map(recent,function(x) x$trnRating))
df<-tibble::tibble(kills=kills,score=score,ptype=playtype,trnchange=trnchange,trnrating=trnrating,matches=1:10)
#first place to look
library(ggplot2)
library(cowplot)
p1<-ggplot(aes(kills),data=df)+geom_histogram()
p2<-ggplot(aes(score),data=df)+geom_histogram()
p3<-plot_grid(p1,p2)
library(rvest)
url<-"https://fortnitetracker.com/leaderboards/pc/Top1?mode=all"
url1<-"https://fortnitetracker.com/leaderboards/"
url2<-"/Top1?mode=all"
webp<-read_html(url)
rank_data_html <- html_nodes(webp,'.trn-lb-entry__name')
rank_names<-html_text(rank_data_html)
```

```{r-mongo}
library(mongolite)
m<-mongo(collection="fortnite_stats")
m$insert(res_ls)
source("topPlayers.R")
txbox<-getTopUsers('xbox',1)
#could make this nicer with maps, but ehhh
txbox<-c()
for(i in 1:3){
txbox<-c(txbox,getTopUsers('xbox',i))
Sys.sleep(5)
}
Sys.sleep(30)
tpc<-c()
for(i in 1:3){
tpc<-c(tpc,getTopUsers('pc',i))
Sys.sleep(5)
}
Sys.sleep(30)
tpsn<-c()
for(i in 1:3){
tpsn<-c(tpsn,getTopUsers('psn',i))
Sys.sleep(5)
}
collect_pdata<-function(pid,platform=c("xbox","pc","psn")){
res<-getUserData(pid,platform,'your_fortnite_tracker_api')
df<-parseUserData(res)
Sys.sleep(5)
return(df)
}
safely_collect<-safely(collect_pdata)
txbox_df<-map2_df(txbox,rep("xb1",length(txbox)),collect_pdata(.x,.y))
tpcl<-vector(mode="list",length=300)
for(i in 1:300){
pid<-tpc[i]
tpcl[i]<-safely_collect(pid,'pc')
}
tpc_df<-bind_rows(tpcl)
tpsnl<-vector(mode="list",length=300)
for(i in 1:300){
pid<-tpsn[i]
tpsnl[i]<-safely_collect(pid,'psn')
}
tpsn_df<-bind_rows(tpsnl)
#dunno why this is erroring out
tpc_df<-map2_dfr(tpc,rep("pc",length(tpc)),~safely_collect(.x,.y))
tpsn_df<-map2_df(tpsn,rep("psn",length(tpsn)),~collect_pdata(.x,.y))
fortnite_df <- bind_rows(tpc_df,tpsn_df)
write_csv(fortnite_df,"fortnite.csv")
```
Loading

0 comments on commit 836ab9f

Please sign in to comment.