Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

increment fixed drive on lost fumbles with play type pass, run or punt #419

Merged
merged 6 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Workflow derived from https://github.com/r-lib/actions/tree/master/examples
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
Expand All @@ -19,8 +19,8 @@ jobs:
fail-fast: false
matrix:
config:
- {os: macOS-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: macOS-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}
Expand All @@ -30,7 +30,7 @@ jobs:
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-pandoc@v2

Expand All @@ -43,9 +43,12 @@ jobs:
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: |
rcmdcheck
any::rcmdcheck
nflverse/fastrmodels
nflverse/nflreadr
nflverse/nflseedR
needs: check

- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
40 changes: 20 additions & 20 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
tags: ['*']
pull_request:
branches: [master, main]
branches: [main, master]
release:
types: [published]
workflow_dispatch:

name: pkgdown

jobs:
pkgdown:
if: github.event_name == 'push' || github.event.pull_request.head.repo.fork == false || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
# Only restrict concurrency for non-PR jobs
concurrency:
group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
isPush: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r-dependencies@v2
with:
Expand All @@ -43,23 +49,17 @@ jobs:
local::.
needs: website

- name: Build and deploy pkgdown site
if: contains(env.isPush, 'true')
run: |
git config --local user.name "$GITHUB_ACTOR"
git config --local user.email "[email protected]"
Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE)'

- name: Create website
if: contains(env.isPush, 'false')
run: |
pkgdown::build_site()
- name: Build site
run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
shell: Rscript {0}

# - name: Create index file
# if: contains(env.isPush, 'false')
# run: |
# echo '<!DOCTYPE html><html><head><meta http-equiv="refresh" content="0;URL=/dev/index.html" /> <script language="javascript"> window.location.replace('/dev/index.html')</script></head></html>' > ./docs/index.html
- name: Deploy to GitHub pages 🚀
if: github.event_name != 'pull_request'
uses: JamesIves/[email protected]
with:
clean: false
branch: gh-pages
folder: docs

- name: Deploy to Netlify
if: contains(env.isPush, 'false')
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: nflfastR
Title: Functions to Efficiently Access NFL Play by Play Data
Version: 4.5.1.9004
Version: 4.5.1.9005
Authors@R:
c(person(given = "Sebastian",
family = "Carl",
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- The function `calculate_player_stats()` now returns the opponent team when called with argument `weekly = TRUE` (#414)
- The function `calculate_player_stats_def()` no longer errors when small subsets of pbp data are missing stats. (#415)
- The function `calculate_series_conversion_rates()` no longer returns `NA` values if a small subset of pbp data is missing series on offense or defense. (#417)
- `fixed_drive` now correctly increments on plays where posteam lost a fumble but remains posteam because defteam also lost a fumble during the same play. (#419)

# nflfastR 4.5.1

Expand Down
48 changes: 14 additions & 34 deletions R/helper_add_fixed_drives.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,44 +67,24 @@ add_drive_results <- function(d) {
new_drive = dplyr::if_else(
# this line is to prevent it from overwriting already-defined new drives with NA
# when there's a timeout on prior line bc if_else is obnoxious like that
( .data$new_drive != 1 | is.na(.data$new_drive) ) &

# same team has ball after lost fumble on punt
(.data$new_drive != 1 | is.na(.data$new_drive)) &
(
(.data$posteam == dplyr::lag(.data$posteam) & dplyr::lag(.data$fumble_lost) == 1 & dplyr::lag(.data$play_type) == "punt" &
# but not if the play resulted in a touchdown because otherwise the
# following extra point or 2pt conversion will be new drives
# same team has ball after lost fumble on punt, pass or rush
(.data$posteam == dplyr::lag(.data$posteam) & dplyr::lag(.data$fumble_lost) == 1 & dplyr::lag(.data$play_type) %in% c("punt", "pass", "run") &
# but not if the play resulted in a touchdown because otherwise the
# following extra point or 2pt conversion will be new drives
dplyr::lag(.data$touchdown) == 0) |

# same team has ball after lost fumble on interception
(.data$posteam == dplyr::lag(.data$posteam) & dplyr::lag(.data$fumble_lost) == 1 & dplyr::lag(.data$interception) == 1 &
# but not if the play resulted in a touchdown because otherwise the
# following extra point or 2pt conversion will be new drives
dplyr::lag(.data$touchdown) == 0) |

# same team has ball after lost fumble on punt 2 plays earlier with prior play missing posteam
(is.na(dplyr::lag(.data$posteam)) &
# posteam is same as posteam 2 plays ago
.data$posteam == dplyr::lag(.data$posteam, 2) &
# muffed punt 2 plays ago
dplyr::lag(.data$fumble_lost, 2) == 1 & dplyr::lag(.data$play_type, 2) == "punt" &
# but not if the muff 2 plays ago resulted in a touchdown because otherwise the
# following extra point or 2pt conversion will be new drives
dplyr::lag(.data$touchdown, 2) == 0) |

# same team has ball after lost fumble on interception 2 plays earlier with prior play missing posteam
# same team has ball after lost fumble on punt, pass or rush 2 plays earlier with prior play missing posteam
(is.na(dplyr::lag(.data$posteam)) &
# posteam is same as posteam 2 plays ago
.data$posteam == dplyr::lag(.data$posteam, 2) &
# muffed punt 2 plays ago
dplyr::lag(.data$fumble_lost, 2) == 1 & dplyr::lag(.data$interception, 2) == 1 &
# but not if the lost fumble 2 plays ago resulted in a touchdown because otherwise the
# following extra point or 2pt conversion will be new drives
dplyr::lag(.data$touchdown, 2) == 0)

)

,
# posteam is same as posteam 2 plays ago
.data$posteam == dplyr::lag(.data$posteam, 2) &
# lost fumble 2 plays ago
dplyr::lag(.data$fumble_lost, 2) == 1 & dplyr::lag(.data$play_type, 2) %in% c("punt", "pass", "run") &
# but not if the lost fumble 2 plays ago resulted in a touchdown because otherwise the
# following extra point or 2pt conversion will be new drives
dplyr::lag(.data$touchdown, 2) == 0)
),
1, .data$new_drive
),
# first observation of a half is also a new drive
Expand Down
10 changes: 10 additions & 0 deletions R/report.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,18 @@
#' @inherit nflreadr::nflverse_sitrep
#' @examples
#' \donttest{
#' \dontshow{
#' # set CRAN mirror to avoid failing checks in weird scenarios
#' old_ops <- options(repos = c("CRAN" = "https://cran.rstudio.com/"))
#' }
#'
#' report(recursive = FALSE)
#' nflverse_sitrep(pkg = "nflreadr", recursive = TRUE)
#'
#' \dontshow{
#' # restore old options
#' options(old_ops)
#' }
#' }
#' @export
report <- function(...) nflreadr::nflverse_sitrep(...)
Expand Down
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ knitr::opts_chunk$set(
[![CRAN status](https://www.r-pkg.org/badges/version-last-release/nflfastR)](https://CRAN.R-project.org/package=nflfastR)
[![CRAN downloads](http://cranlogs.r-pkg.org/badges/grand-total/nflfastR)](https://CRAN.R-project.org/package=nflfastR)
[![Dev status](https://img.shields.io/github/r-package/v/nflverse/nflfastR/master?label=dev%20version&style=flat-square&logo=github)](https://www.nflfastr.com/)
[![R-CMD-check](https://github.com/nflverse/nflfastR/workflows/R-CMD-check/badge.svg)](https://github.com/nflverse/nflfastR/actions)
[![R-CMD-check](https://github.com/nflverse/nflfastR/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/nflverse/nflfastR/actions/workflows/R-CMD-check.yaml)
[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
[![nflverse support](https://img.shields.io/discord/789805604076126219?color=7289da&label=nflverse%20support&logo=discord&logoColor=fff&style=flat-square)](https://discord.com/invite/5Er2FBnnQa)
[![Twitter Follow](https://img.shields.io/twitter/follow/nflfastR.svg?style=social)](https://twitter.com/nflfastR)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ status](https://www.r-pkg.org/badges/version-last-release/nflfastR)](https://CRA
downloads](http://cranlogs.r-pkg.org/badges/grand-total/nflfastR)](https://CRAN.R-project.org/package=nflfastR)
[![Dev
status](https://img.shields.io/github/r-package/v/nflverse/nflfastR/master?label=dev%20version&style=flat-square&logo=github)](https://www.nflfastr.com/)
[![R-CMD-check](https://github.com/nflverse/nflfastR/workflows/R-CMD-check/badge.svg)](https://github.com/nflverse/nflfastR/actions)
[![R-CMD-check](https://github.com/nflverse/nflfastR/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/nflverse/nflfastR/actions/workflows/R-CMD-check.yaml)
[![Lifecycle:
stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
[![nflverse
Expand Down
10 changes: 10 additions & 0 deletions man/report.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading