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

boost sum_play_stats #402

Merged
merged 5 commits into from
Dec 20, 2022
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
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.0.9002
Version: 4.5.0.9003
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 @@ -3,6 +3,7 @@
* New implementation of tests to be able to identify breaking changes in reverse dependencies
* `calculate_standings()` no more freezes when computing standings from schedules where some games are missing results, i.e. upcoming games. (v4.5.0.9000)
* Bug fix that caused problems with upcoming dplyr and tidyselect updates that weren't reverse compatible.
* Significant performance improvements of internal functions. (#402)
* Wrap examples in `try()` to avoid CRAN problems. (#404)
* Fixed a bug where `calculate_standings()` wasn't able to handle nflverse pbp data. (#404)

Expand Down
8 changes: 2 additions & 6 deletions R/helper_scrape_gc.R
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,8 @@ get_pbp_gc <- function(gameId, dir = NULL, qs = FALSE, ...) {
playStatSeq = "sequence"
)


pbp_stats <- furrr::future_map(unique(stats$playId), function(x, s) {
sum_play_stats(x, s)
}, stats)

pbp_stats <- dplyr::bind_rows(pbp_stats)
pbp_stats <- lapply(unique(stats$playId), sum_play_stats, stats)
pbp_stats <- data.table::rbindlist(pbp_stats) %>% tibble::as_tibble()

# drive info
d <- tibble::tibble(drives) %>%
Expand Down
8 changes: 2 additions & 6 deletions R/helper_scrape_nfl.R
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,9 @@ get_pbp_nfl <- function(id, dir = NULL, qs = FALSE, ...) {

# if I don't put this here it breaks
suppressWarnings(
pbp_stats <-
furrr::future_map(unique(stats$playId), function(x, s) {
sum_play_stats(x, s)
}, stats)
pbp_stats <- lapply(unique(stats$playId), sum_play_stats, stats)
)

pbp_stats <- dplyr::bind_rows(pbp_stats)
pbp_stats <- data.table::rbindlist(pbp_stats) %>% tibble::as_tibble()

combined <- game_info %>%
dplyr::bind_cols(plays %>% dplyr::select(-"playStats", -"game_id")) %>%
Expand Down
4 changes: 2 additions & 2 deletions R/helper_tidy_play_stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
# @param stats A dataframe including multiple rows for each play_Id holding
# gsis stat ids and stats
sum_play_stats <- function(play_Id, stats) {
play_stats <- stats %>% filter(.data$playId == play_Id)
play_stats <- stats[stats$playId == play_Id,]

row <- bind_cols(play_id = as.integer(play_Id), tidy_play_stats_row)
row <- c("play_id" = as.integer(play_Id), tidy_play_stats_row)

for (index in seq_along(play_stats$playId)) {
stat_id <- play_stats$statId[index]
Expand Down