length(outdata[2,])
length(outdata[2,1])
outdata[2,]
outdata[2]
outdata[,2]
outdata[,2][1]
nrow(outdata)
View(outdata)
full.game.database(extra.seasons=0)
full.game.database(extra.seasons="20172018")
full.game.database(extra.seasons=1)
full.game.database(extra.seasons=0)
full.game.database(extra.seasons=1)
full.game.database(extra.seasons=0)
full.game.database()
full.game.database
full.game.database <- function(){
game.roster <- NULL
seasons <- c("20022003", "20032004", "20052006", "20062007",
"20072008", "20082009", "20092010", "20102011", "20112012",
"20122013", "20132014", "20142015", "20152016", "20162017", "20172018")
if (extra.seasons > 0)
seasons <- c(seasons, paste(2013 + 1:extra.seasons, 2014 +
1:extra.seasons, sep = ""))
games <- c(rep(1230, 9), 720, 1230, 1230, rep(1230, extra.seasons))
bad.game.list <- list(c(1:127, 134, 135, 582, 598, 872),
c(10, 251, 453, 456, 482, 802, 1205), c(18, 140, 127,
234, 298, 458, 974), c(1024), c(1178), c(259, 409,
1077), c(81, 827, 836, 857, 863, 874, 885), c(124,
429), c(259), c(), c(), c())
if (extra.seasons > 0)
bad.game.list[[length(bad.game.list) + 1]] <- c()
playoff.series <- c("11", "12", "13", "14", "15", "16", "17",
"18", "21", "22", "23", "24", "31", "32", "41")
gnum <- paste0("0", c(t(outer(playoff.series, 1:7, paste0))))
for (ss in 1:length(seasons)) {
gn1 <- as.character(1:games[ss])
while (any(nchar(gn1) < 4)) gn1[nchar(gn1) < 4] <- paste0("0",
gn1[nchar(gn1) < 4])
df1 <- data.frame(season = seasons[ss], session = c(rep("Regular",
games[ss]), rep("Playoffs", length(gnum))), gamenumber = c(gn1,
gnum), gcode = "", status = 1, valid = c(!(1:games[ss] %in%
bad.game.list[[ss]]), rep(TRUE, length(gnum))), awayteam = "",
hometeam = "", awayscore = "", homescore = "", date = "",
game.start = "", game.end = "", periods = 0, stringsAsFactors = FALSE)
game.roster <- rbind(game.roster, df1)
}
game.roster[, 1] <- as.character(game.roster[, 1])
game.roster[, 2] <- as.character(game.roster[, 2])
game.roster$gcode <- paste0(2 + 1 * (game.roster$session ==
"Playoffs"), game.roster$gamenumber)
game.roster$status[!game.roster$valid] <- 0
game.roster <- game.roster[, colnames(game.roster) != "valid"]
playoff.series.lengths <- c(5, 5, 6, 7, 6, 4, 7, 7, 6, 5,
6, 7, 7, 4, 7, 5, 7, 5, 7, 6, 5, 7, 5, 4, 6, 6, 6, 7,
6, 7, 5, 6, 4, 6, 6, 5, 7, 5, 5, 5, 6, 4, 7, 5, 7, 5,
6, 4, 5, 6, 5, 7, 5, 6, 5, 6, 5, 5, 6, 5, 7, 4, 7, 5,
6, 7, 6, 6, 5, 5, 4, 6, 5, 6, 6, 4, 7, 7, 6, 6, 4, 4,
6, 7, 7, 7, 6, 4, 5, 7, 7, 5, 6, 6, 6, 6, 6, 7, 7, 7,
5, 6, 5, 4, 6, 5, 7, 7, 7, 7, 6, 4, 6, 4, 4, 6, 7, 7,
5, 7, 7, 7, 7, 6, 5, 5, 6, 5, 7, 5, 4, 5, 6, 5, 6, 6,
5, 7, 7, 5, 7, 4, 6, 5, 5, 7, 7, 4, 5, 6, 5, 4, 6, 7,
7, 6, 6, 7, 7, 7, 6, 7, 6, 7, 5, rep(7, 15), rep(7, 15 *
(extra.seasons)))
sequence.seven <- function(nn) c(rep(1, nn), rep(0, 7 - nn))
playoff.status <- c(sapply(playoff.series.lengths, sequence.seven))
game.roster$status[game.roster$session == "Playoffs"] <- playoff.status
bad.playoff <- matrix(c("20032004", "30134", "20052006",
"30233"), nrow = 2)
for (kk in 1:dim(bad.playoff)[2]) game.roster$status[game.roster$season ==
bad.playoff[1, kk] & game.roster$gcode == bad.playoff[2,
kk]] <- 0
gamecols <- match(paste0("20142015", as.character(nhlscrapr::date201415$gcode)),
paste0(game.roster$season, game.roster$gcode))
game.roster$awayteam[gamecols] <- as.character(nhlscrapr::date201415$awayteam)
game.roster$hometeam[gamecols] <- as.character(nhlscrapr::date201415$hometeam)
unplayed <- which(game.roster$game.start[gamecols] == "")
game.roster$game.start[gamecols[unplayed]] <- paste(as.character(nhlscrapr::date201415$StartET[unplayed]),
"ET")
game.roster$date[gamecols[unplayed]] <- as.character(nhlscrapr::date201415$GameDate[unplayed])
return(game.roster)
}
full.game.database()
full.game.database(extra.seasons=0)
allthegames <- function(){
game.roster <- NULL
seasons <- c("20022003", "20032004", "20052006", "20062007",
"20072008", "20082009", "20092010", "20102011", "20112012",
"20122013", "20132014", "20142015", "20152016", "20162017", "20172018")
if (extra.seasons > 0)
seasons <- c(seasons, paste(2013 + 1:extra.seasons, 2014 +
1:extra.seasons, sep = ""))
games <- c(rep(1230, 9), 720, 1230, 1230, rep(1230, extra.seasons))
bad.game.list <- list(c(1:127, 134, 135, 582, 598, 872),
c(10, 251, 453, 456, 482, 802, 1205), c(18, 140, 127,
234, 298, 458, 974), c(1024), c(1178), c(259, 409,
1077), c(81, 827, 836, 857, 863, 874, 885), c(124,
429), c(259), c(), c(), c())
if (extra.seasons > 0)
bad.game.list[[length(bad.game.list) + 1]] <- c()
playoff.series <- c("11", "12", "13", "14", "15", "16", "17",
"18", "21", "22", "23", "24", "31", "32", "41")
gnum <- paste0("0", c(t(outer(playoff.series, 1:7, paste0))))
for (ss in 1:length(seasons)) {
gn1 <- as.character(1:games[ss])
while (any(nchar(gn1) < 4)) gn1[nchar(gn1) < 4] <- paste0("0",
gn1[nchar(gn1) < 4])
df1 <- data.frame(season = seasons[ss], session = c(rep("Regular",
games[ss]), rep("Playoffs", length(gnum))), gamenumber = c(gn1,
gnum), gcode = "", status = 1, valid = c(!(1:games[ss] %in%
bad.game.list[[ss]]), rep(TRUE, length(gnum))), awayteam = "",
hometeam = "", awayscore = "", homescore = "", date = "",
game.start = "", game.end = "", periods = 0, stringsAsFactors = FALSE)
game.roster <- rbind(game.roster, df1)
}
game.roster[, 1] <- as.character(game.roster[, 1])
game.roster[, 2] <- as.character(game.roster[, 2])
game.roster$gcode <- paste0(2 + 1 * (game.roster$session ==
"Playoffs"), game.roster$gamenumber)
game.roster$status[!game.roster$valid] <- 0
game.roster <- game.roster[, colnames(game.roster) != "valid"]
playoff.series.lengths <- c(5, 5, 6, 7, 6, 4, 7, 7, 6, 5,
6, 7, 7, 4, 7, 5, 7, 5, 7, 6, 5, 7, 5, 4, 6, 6, 6, 7,
6, 7, 5, 6, 4, 6, 6, 5, 7, 5, 5, 5, 6, 4, 7, 5, 7, 5,
6, 4, 5, 6, 5, 7, 5, 6, 5, 6, 5, 5, 6, 5, 7, 4, 7, 5,
6, 7, 6, 6, 5, 5, 4, 6, 5, 6, 6, 4, 7, 7, 6, 6, 4, 4,
6, 7, 7, 7, 6, 4, 5, 7, 7, 5, 6, 6, 6, 6, 6, 7, 7, 7,
5, 6, 5, 4, 6, 5, 7, 7, 7, 7, 6, 4, 6, 4, 4, 6, 7, 7,
5, 7, 7, 7, 7, 6, 5, 5, 6, 5, 7, 5, 4, 5, 6, 5, 6, 6,
5, 7, 7, 5, 7, 4, 6, 5, 5, 7, 7, 4, 5, 6, 5, 4, 6, 7,
7, 6, 6, 7, 7, 7, 6, 7, 6, 7, 5, rep(7, 15), rep(7, 15 *
(extra.seasons)))
sequence.seven <- function(nn) c(rep(1, nn), rep(0, 7 - nn))
playoff.status <- c(sapply(playoff.series.lengths, sequence.seven))
game.roster$status[game.roster$session == "Playoffs"] <- playoff.status
bad.playoff <- matrix(c("20032004", "30134", "20052006",
"30233"), nrow = 2)
for (kk in 1:dim(bad.playoff)[2]) game.roster$status[game.roster$season ==
bad.playoff[1, kk] & game.roster$gcode == bad.playoff[2,
kk]] <- 0
gamecols <- match(paste0("20142015", as.character(nhlscrapr::date201415$gcode)),
paste0(game.roster$season, game.roster$gcode))
game.roster$awayteam[gamecols] <- as.character(nhlscrapr::date201415$awayteam)
game.roster$hometeam[gamecols] <- as.character(nhlscrapr::date201415$hometeam)
unplayed <- which(game.roster$game.start[gamecols] == "")
game.roster$game.start[gamecols[unplayed]] <- paste(as.character(nhlscrapr::date201415$StartET[unplayed]),
"ET")
game.roster$date[gamecols[unplayed]] <- as.character(nhlscrapr::date201415$GameDate[unplayed])
return(game.roster)
}
allthegames()
library(nhlscrapr)
full.game.database
allthegames <- function(extra.seasons=0){
game.roster <- NULL
seasons <- c("20022003", "20032004", "20052006", "20062007",
"20072008", "20082009", "20092010", "20102011", "20112012",
"20122013", "20132014", "20142015", "20152016", "20162017", "20172018")
if (extra.seasons > 0)
seasons <- c(seasons, paste(2013 + 1:extra.seasons, 2014 +
1:extra.seasons, sep = ""))
games <- c(rep(1230, 9), 720, 1230, 1230, rep(1230, extra.seasons))
bad.game.list <- list(c(1:127, 134, 135, 582, 598, 872),
c(10, 251, 453, 456, 482, 802, 1205), c(18, 140, 127,
234, 298, 458, 974), c(1024), c(1178), c(259, 409,
1077), c(81, 827, 836, 857, 863, 874, 885), c(124,
429), c(259), c(), c(), c())
if (extra.seasons > 0)
bad.game.list[[length(bad.game.list) + 1]] <- c()
playoff.series <- c("11", "12", "13", "14", "15", "16", "17",
"18", "21", "22", "23", "24", "31", "32", "41")
gnum <- paste0("0", c(t(outer(playoff.series, 1:7, paste0))))
for (ss in 1:length(seasons)) {
gn1 <- as.character(1:games[ss])
while (any(nchar(gn1) < 4)) gn1[nchar(gn1) < 4] <- paste0("0",
gn1[nchar(gn1) < 4])
df1 <- data.frame(season = seasons[ss], session = c(rep("Regular",
games[ss]), rep("Playoffs", length(gnum))), gamenumber = c(gn1,
gnum), gcode = "", status = 1, valid = c(!(1:games[ss] %in%
bad.game.list[[ss]]), rep(TRUE, length(gnum))), awayteam = "",
hometeam = "", awayscore = "", homescore = "", date = "",
game.start = "", game.end = "", periods = 0, stringsAsFactors = FALSE)
game.roster <- rbind(game.roster, df1)
}
game.roster[, 1] <- as.character(game.roster[, 1])
game.roster[, 2] <- as.character(game.roster[, 2])
game.roster$gcode <- paste0(2 + 1 * (game.roster$session ==
"Playoffs"), game.roster$gamenumber)
game.roster$status[!game.roster$valid] <- 0
game.roster <- game.roster[, colnames(game.roster) != "valid"]
playoff.series.lengths <- c(5, 5, 6, 7, 6, 4, 7, 7, 6, 5,
6, 7, 7, 4, 7, 5, 7, 5, 7, 6, 5, 7, 5, 4, 6, 6, 6, 7,
6, 7, 5, 6, 4, 6, 6, 5, 7, 5, 5, 5, 6, 4, 7, 5, 7, 5,
6, 4, 5, 6, 5, 7, 5, 6, 5, 6, 5, 5, 6, 5, 7, 4, 7, 5,
6, 7, 6, 6, 5, 5, 4, 6, 5, 6, 6, 4, 7, 7, 6, 6, 4, 4,
6, 7, 7, 7, 6, 4, 5, 7, 7, 5, 6, 6, 6, 6, 6, 7, 7, 7,
5, 6, 5, 4, 6, 5, 7, 7, 7, 7, 6, 4, 6, 4, 4, 6, 7, 7,
5, 7, 7, 7, 7, 6, 5, 5, 6, 5, 7, 5, 4, 5, 6, 5, 6, 6,
5, 7, 7, 5, 7, 4, 6, 5, 5, 7, 7, 4, 5, 6, 5, 4, 6, 7,
7, 6, 6, 7, 7, 7, 6, 7, 6, 7, 5, rep(7, 15), rep(7, 15 *
(extra.seasons)))
sequence.seven <- function(nn) c(rep(1, nn), rep(0, 7 - nn))
playoff.status <- c(sapply(playoff.series.lengths, sequence.seven))
game.roster$status[game.roster$session == "Playoffs"] <- playoff.status
bad.playoff <- matrix(c("20032004", "30134", "20052006",
"30233"), nrow = 2)
for (kk in 1:dim(bad.playoff)[2]) game.roster$status[game.roster$season ==
bad.playoff[1, kk] & game.roster$gcode == bad.playoff[2,
kk]] <- 0
gamecols <- match(paste0("20142015", as.character(nhlscrapr::date201415$gcode)),
paste0(game.roster$season, game.roster$gcode))
game.roster$awayteam[gamecols] <- as.character(nhlscrapr::date201415$awayteam)
game.roster$hometeam[gamecols] <- as.character(nhlscrapr::date201415$hometeam)
unplayed <- which(game.roster$game.start[gamecols] == "")
game.roster$game.start[gamecols[unplayed]] <- paste(as.character(nhlscrapr::date201415$StartET[unplayed]),
"ET")
game.roster$date[gamecols[unplayed]] <- as.character(nhlscrapr::date201415$GameDate[unplayed])
return(game.roster)
}
allthegames()
seasons <- c("20022003", "20032004", "20052006", "20062007",
"20072008", "20082009", "20092010", "20102011", "20112012",
"20122013", "20132014", "20142015", "20152016", "20162017", "20172018")
length(seasons)
for (ss in 1:length(seasons)) {
print(ss)}
download.games
sample.game <- NULL
season
gcode
shotscum
# make dataframe of game info
date <- c(paste0(sample.game$date[2],',',sample.game$date[3],',',sample.game$date[4]))
# make dataframe of game info
date <- c(paste0(sample.game$date[2],',',sample.game$date[3],',',sample.game$date[4]))
date
# make dataframe of game info
date <- c(paste0(sample.game$date[2],',',sample.game$date[3],',',sample.game$date[4]))
date
sample.game <- retrieve.game(season="20172018", gcode="20014")
gameinfo[[j]] <-
sample.game$
}
gameinfo[[j]] <-
sample.game$teams
gameinfo[[j]] <-
sample.game
sample.game
sample.game$teams[1]
j = 0
gamelist =list()
gameinfo = list()
for(i in 20001:20221){
j=j+1
sample.game <- NULL
print(i)
sample.game <- retrieve.game(season="20172018", gcode=i)
game <- sample.game[["playbyplay"]]
#just get the shot and goals
shots <- dplyr::filter(game, etype%in% "SHOT" | etype%in% "GOAL")
#get shot differential
shotscum <- shots %>% dplyr::mutate(shotdff= cumsum(ev.team == shots$hometeam[1])-cumsum(ev.team == shots$awayteam[1]))
gcode<-unlist(shotscum["gcode"][1,1], use.names = FALSE)
outdata <- dplyr::select(shotscum,seconds,etype,shotdff,awayteam, hometeam,ev.team)
gamelist[[j]] <- outdata
# make dataframe of game info
date <- c(paste0(sample.game$date[2],',',sample.game$date[3],',',sample.game$date[4]))
scorehome <- sample.game$score[1]
scoreaway <- sample.game$score[2]
home <- ample.game$teams[1]
away <- ample.game$teams[1]
df<-data.frame(date,home,away,scorehome,scoreaway,gcode)
rownames(df) <- NULL
gameinfo[[j]] <- df
}
j = 0
gamelist =list()
gameinfo = list()
for(i in 20001:20221){
j=j+1
sample.game <- NULL
print(i)
sample.game <- retrieve.game(season="20172018", gcode=i)
game <- sample.game[["playbyplay"]]
#just get the shot and goals
shots <- dplyr::filter(game, etype%in% "SHOT" | etype%in% "GOAL")
#get shot differential
shotscum <- shots %>% dplyr::mutate(shotdff= cumsum(ev.team == shots$hometeam[1])-cumsum(ev.team == shots$awayteam[1]))
gcode<-unlist(shotscum["gcode"][1,1], use.names = FALSE)
outdata <- dplyr::select(shotscum,seconds,etype,shotdff,awayteam, hometeam,ev.team)
gamelist[[j]] <- outdata
# make dataframe of game info
date <- c(paste0(sample.game$date[2],',',sample.game$date[3],',',sample.game$date[4]))
scorehome <- sample.game$score[1]
scoreaway <- sample.game$score[2]
home <- sample.game$teams[1]
away <- sample.game$teams[1]
df<-data.frame(date,home,away,scorehome,scoreaway,gcode)
rownames(df) <- NULL
gameinfo[[j]] <- df
}
gamelist
#bind all months
x <- bind_rows(datalist)
#bind all months
x <- bind_rows(gamelist)
saveRDS(x, file="allGames.rds")
gameinfo
inf <- bind_rows(gameinfo)
inf <- bind_rows(gameinfo)
inf
inf <- bind_rows(gameinfo)
x
gameinfo
bind_rows(gameinfo)
gameinfo
View(gameinfo)
View(gamelist)
View(x)
bind_rows(gameinfo)
gameinfo[1]
gameinfo[1]$gcode
gameinfo[1]
gameinfo[1,1]
gameinfo[[1]]
gameinfo[[1]]$gcode
as.numeric(gameinfo[[1]]$gcode)
gcode
gcode+22
as.data.frame(gameinfo)
test=as.data.frame(gameinfo)
View(test)
bind_rows(gameinfo)
rbind.fill(gameinfo)
library(plyr)
library(plyr); library(dplyr)
rbind.fill(gameinfo)
inf <- rbind.fill(gameinfo)
saveRDS(inf, file="allGamesInfo.rds")
inf
View(x)
write.csv(x,file='allgames.csv')
write.csv(inf,file='allgamesinfo.csv')
library(plyr); library(dplyr)
nrow(outdata)
j = 0
gamelist =list()
gameinfo = list()
for(i in 20001:20003){
j=j+1
sample.game <- NULL
print(i)
sample.game <- retrieve.game(season="20172018", gcode=i)
game <- sample.game[["playbyplay"]]
#just get the shot and goals
shots <- dplyr::filter(game, etype%in% "SHOT" | etype%in% "GOAL")
#get shot differential
shotscum <- shots %>% dplyr::mutate(shotdff= cumsum(ev.team == shots$hometeam[1])-cumsum(ev.team == shots$awayteam[1]))
gcode<-unlist(shotscum["gcode"][1,1], use.names = FALSE)
outdata <- dplyr::select(shotscum,seconds,etype,shotdff,awayteam, hometeam,ev.team)
gamelist[[j]] <- outdata
# make dataframe of game info
date <- c(paste0(sample.game$date[2],',',sample.game$date[3],',',sample.game$date[4]))
scorehome <- sample.game$score[1]
scoreaway <- sample.game$score[2]
home <- sample.game$teams[1]
away <- sample.game$teams[2]
df<-data.frame(date,home,away,scorehome,scoreaway,gcode,nrow(outdata))
rownames(df) <- NULL
gameinfo[[j]] <- df
}
#bind all months
x <- bind_rows(gamelist)
inf <- rbind.fill(gameinfo)
View(x)
View(inf)
j = 0
gamelist =list()
gameinfo = list()
for(i in 20001:20021){
j=j+1
sample.game <- NULL
print(i)
sample.game <- retrieve.game(season="20172018", gcode=i)
game <- sample.game[["playbyplay"]]
#just get the shot and goals
shots <- dplyr::filter(game, etype%in% "SHOT" | etype%in% "GOAL")
#get shot differential
shotscum <- shots %>% dplyr::mutate(shotdff= cumsum(ev.team == shots$hometeam[1])-cumsum(ev.team == shots$awayteam[1]))
gcode<-unlist(shotscum["gcode"][1,1], use.names = FALSE)
outdata <- dplyr::select(shotscum,seconds,etype,shotdff,awayteam, hometeam,ev.team)
gamelist[[j]] <- outdata
# make dataframe of game info
date <- c(paste0(sample.game$date[2],',',sample.game$date[3],',',sample.game$date[4]))
scorehome <- sample.game$score[1]
scoreaway <- sample.game$score[2]
home <- sample.game$teams[1]
away <- sample.game$teams[2]
df<-data.frame(date,home,away,scorehome,scoreaway,gcode,nrow(outdata))
rownames(df) <- NULL
gameinfo[[j]] <- df
}
#bind all months
x <- bind_rows(gamelist)
saveRDS(x, file="allGames.rds")
inf <- rbind.fill(gameinfo)
saveRDS(inf, file="allGamesInfo.rds")
write.csv(x,file='allgames.csv')
write.csv(inf,file='allgamesinfo.csv')
inf
head(inf)
colnames(inf)
colnames(inf$nrow.outdata.)
colnames(in)[4]
colnames(inf)[4]
colnames(inf)[7]
colnames(inf)[7] <-'shots'
inf
colnames(inf)[7] <-'shots'
saveRDS(inf, file="allGamesInfo.rds")
write.csv(inf,file='allgamesinfo.csv')
82*30
82*30/2
82*30/2*40
82*30/2*80
j = 0
gamelist =list()
gameinfo = list()
for(i in 20001:20021){
j=j+1
sample.game <- NULL
print(i)
sample.game <- retrieve.game(season="20172018", gcode=i)
game <- sample.game[["playbyplay"]]
#just get the shot and goals
shots <- dplyr::filter(game, etype%in% "SHOT" | etype%in% "GOAL")
#get shot differential
shotscum <- shots %>% dplyr::mutate(shotdff= cumsum(ev.team == shots$hometeam[1])-cumsum(ev.team == shots$awayteam[1]))
gcode<-unlist(shotscum["gcode"][1,1], use.names = FALSE)
outdata <- dplyr::select(shotscum,seconds,etype,shotdff,ev.team,gcode)
gamelist[[j]] <- outdata
# make dataframe of game info
date <- c(paste0(sample.game$date[2],',',sample.game$date[3],',',sample.game$date[4]))
scorehome <- sample.game$score[1]
scoreaway <- sample.game$score[2]
home <- sample.game$teams[1]
away <- sample.game$teams[2]
df<-data.frame(date,home,away,scorehome,scoreaway,gcode,nrow(outdata))
rownames(df) <- NULL
gameinfo[[j]] <- df
}
#bind all months
x <- bind_rows(gamelist)
#bind all months
x <- rbind.fill(gamelist)
saveRDS(x, file="allGames.rds")
inf <- rbind.fill(gameinfo)
colnames(inf)[7] <-'shots'
saveRDS(inf, file="allGamesInfo.rds")
write.csv(x,file='allgames.csv')
write.csv(inf,file='allgamesinfo.csv')
3416/60
250*250
14*24
14*24*250
16*22
14*30
14*30*47
020262
setwd('/Users/mathewbrown/fun/shotDiff')
library(nhlscrapr)
library(ggplot2)
library(plyr); library(dplyr)
library(jsonlite)
#Give me a single game record. gcode starts at 20001 each seasoon
j = 0
gamelist =list()
gameinfo = list()
for(i in 20001:20262){
j=j+1
sample.game <- NULL
print(i)
sample.game <- retrieve.game(season="20172018", gcode=i)
game <- sample.game[["playbyplay"]]
#just get the shot and goals
shots <- dplyr::filter(game, etype%in% "SHOT" | etype%in% "GOAL")
#get shot differential
shotscum <- shots %>% dplyr::mutate(shotdff= cumsum(ev.team == shots$hometeam[1])-cumsum(ev.team == shots$awayteam[1]))
gcode<-unlist(shotscum["gcode"][1,1], use.names = FALSE)
outdata <- dplyr::select(shotscum,seconds,etype,shotdff,ev.team,gcode)
gamelist[[j]] <- outdata
# make dataframe of game info
date <- c(paste0(sample.game$date[2],',',sample.game$date[3],',',sample.game$date[4]))
scorehome <- sample.game$score[1]
scoreaway <- sample.game$score[2]
home <- sample.game$teams[1]
away <- sample.game$teams[2]
df<-data.frame(date,home,away,scorehome,scoreaway,gcode,nrow(outdata))
rownames(df) <- NULL
gameinfo[[j]] <- df
}
saveRDS()
saveRDS()
saveRDS(gamelist,file='gamelist_20262.rds')
saveRDS(gameinfo,file='gameinfo_20262.rds')
#bind all months
x <- rbind.fill(gamelist)
inf <- rbind.fill(gameinfo)
colnames(inf)[7] <-'shots'
saveRDS(inf, file="allGamesInfo.rds")
write.csv(x,file='allgames.csv')
write.csv(inf,file='allgamesinfo.csv')
