Skip to content

Commit

Permalink
Added blocked punts
Browse files Browse the repository at this point in the history
  • Loading branch information
JackStat committed Sep 18, 2015
1 parent c5c44fa commit ee72801
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
29 changes: 29 additions & 0 deletions R/ParsePunt.R
Expand Up @@ -130,6 +130,35 @@ ParsePunt <- function(x){
x$PuntReturn[Cond6] = FALSE
x$PuntReturnYards[Cond6] = 0


# - Blocked
regParse7 =
paste0(
"([0-9]{1,4}-[A-Z]\\.[A-Za-z\\-]{1,20} |)"
,'punts ([0-9]{1,3}) '
,'yards from '
,'([A-Z]{2,6}) ([0-9]{1,3}) '
,'blocked by '
,"([0-9]{1,4}-[A-Z]\\.[A-Za-z\\-]{1,20})\\. "
,'(.*)\\.'
)

Cond7 <-
grepl(regParse7, x[,"scoreText"]) &
!grepl('Penalty', x[,"scoreText"]) &
!Cond & !Cond2 & !Cond3 & !Cond4 & !Cond5 & !Cond6

x$Punt[Cond7] = TRUE
x$Kicker[Cond7] = gsub(regParse7, '\\1', x[Cond7,"scoreText"])
x$PuntYards[Cond7] = gsub(regParse7, '\\2', x[Cond7,"scoreText"])
x$PuntReturn[Cond7] = FALSE

x$PuntBlocked <- Cond7

afterBlock <- gsub(regParse7, '\\6', x[Cond7,"scoreText"])



x$PuntYards = as.numeric(x$PuntYards)
x$PuntReturnYards = as.numeric(x$PuntReturnYards)
x
Expand Down
12 changes: 11 additions & 1 deletion tests/testthat/test_ParsePunt.R
Expand Up @@ -18,6 +18,8 @@ TestFrame <- data.frame(
,"84-E.Keena punts 35 yards from NTX 27 to SMU 38, fair catch by."
,"punts -13 yards from NEV 29, out of bounds at the NEV 16."
,"91-N.O-Toole punts 43 yards from WVU 39. 1-Z.Parker to LIB 21 for 3 yards (44-H.Christian)."
,"punts 0 yards from TOL 47 blocked by 31-Z.Quinn. Downed at the ARK 25."
,"punts 0 yards from NFS 49 blocked by 68-H.Gaylord. 68-H.Gaylord runs 51 yards for a touchdown."
)
)

Expand All @@ -28,7 +30,7 @@ test_that("Punts are correctly parsing", {

expect_true(all(Punt$Punt))
expect_equal(Punt$PuntYards,
c(31,39,40,31,44,45,59,39,33,45,39,38,35,-13,43))
c(31,39,40,31,44,45,59,39,33,45,39,38,35,-13,43,0,0))
expect_equal(Punt$Kicker,
c("49-H.Hunt"
,"33-T.Hackett"
Expand All @@ -45,6 +47,8 @@ test_that("Punts are correctly parsing", {
,"84-E.Keena"
,""
,"91-N.O-Toole"
,""
,""
))
expect_equal(Punt$PuntReturn,
c(FALSE
Expand All @@ -62,6 +66,8 @@ test_that("Punts are correctly parsing", {
,FALSE
,FALSE
,TRUE
,FALSE
,FALSE
))

expect_equal(Punt$PuntReturnYards,
Expand All @@ -80,7 +86,11 @@ test_that("Punts are correctly parsing", {
,NA
,NA
,3
,NA
,NA
))

expect_equal(Punt$PuntBlocked, grepl(' blocked ', Punt$scoreText))


})

0 comments on commit ee72801

Please sign in to comment.