Skip to content

Commit

Permalink
Merge pull request #329 from ffverse/dev
Browse files Browse the repository at this point in the history
Release v1.4.6 to CRAN
  • Loading branch information
tanho63 authored Sep 3, 2021
2 parents 4eff00d + 6a50b43 commit 2e74ecc
Show file tree
Hide file tree
Showing 14,530 changed files with 816,506 additions and 636 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@
^cran-comments\.md$
^CRAN-RELEASE$
^data-raw$
^doc$
^Meta$
^revdep$
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@ vignettes/*.pdf
inst/doc

docs/
/doc/
/Meta/
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: ffscrapr
Title: API Client for Fantasy Football League Platforms
Version: 1.4.5
Version: 1.4.6
Authors@R:
c(person(given = "Tan",
family = "Ho",
Expand Down Expand Up @@ -29,7 +29,7 @@ URL: https://ffscrapr.ffverse.com,
https://www.nflfastr.com/reference/load_player_stats.html
BugReports: https://github.com/ffverse/ffscrapr/issues
Depends:
R (>= 3.0.0)
R (>= 3.6.0)
Imports:
cachem (>= 1.0.0),
checkmate (>= 2.0.0),
Expand All @@ -40,6 +40,7 @@ Imports:
lifecycle,
lubridate (>= 1.5.0),
magrittr (>= 1.5.0),
nflreadr (>= 1.1.0),
memoise (>= 2.0.0),
purrr (>= 0.3.0),
rappdirs (>= 0.3.0),
Expand Down
5 changes: 5 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ S3method(ff_scoring,espn_conn)
S3method(ff_scoring,flea_conn)
S3method(ff_scoring,mfl_conn)
S3method(ff_scoring,sleeper_conn)
S3method(ff_scoring,template_conn)
S3method(ff_scoringhistory,default)
S3method(ff_scoringhistory,espn_conn)
S3method(ff_scoringhistory,flea_conn)
S3method(ff_scoringhistory,mfl_conn)
S3method(ff_scoringhistory,sleeper_conn)
S3method(ff_scoringhistory,template_conn)
S3method(ff_standings,default)
S3method(ff_standings,espn_conn)
S3method(ff_standings,flea_conn)
Expand All @@ -55,6 +57,7 @@ S3method(ff_starter_positions,espn_conn)
S3method(ff_starter_positions,flea_conn)
S3method(ff_starter_positions,mfl_conn)
S3method(ff_starter_positions,sleeper_conn)
S3method(ff_starter_positions,template_conn)
S3method(ff_starters,default)
S3method(ff_starters,espn_conn)
S3method(ff_starters,flea_conn)
Expand All @@ -78,6 +81,7 @@ S3method(print,mfl_api)
S3method(print,mfl_conn)
S3method(print,sleeper_api)
S3method(print,sleeper_conn)
S3method(print,template_conn)
export("%>%")
export(.ff_clear_cache)
export(dp_clean_html)
Expand All @@ -103,6 +107,7 @@ export(ff_scoringhistory)
export(ff_standings)
export(ff_starter_positions)
export(ff_starters)
export(ff_template)
export(ff_transactions)
export(ff_userleagues)
export(fleaflicker_connect)
Expand Down
33 changes: 33 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,41 @@
# ffscrapr 1.4.6

The main goal of v1.4.6 is to patch some minor bugs, introduce a unified dependency on nflreadr, and add some support for kicker scoring.

## New features

- `ff_template()` adds a template connection for `ff_starter_positions()`, `ff_scoring()`, and `ff_scoringhistory()` to more easily pull common scoring templates.
- Add kicker stat mappings for `ff_scoringhistory()` and support ~ most kicker scorings (MFL's may be weird.)

## Minor changes

- `ff_league()` for MFL now returns league type ("dynasty", "keeper", "redraft") if the field is set.
- `ff_league()` for MFL now returns draft type (e.g. "email draft", "live auction") if the field is set.
- `ff_league()` for MFL now returns draft player pool (e.g. "Rookie", "Veteran", "Both") if the field is set. (These three changes fix #311, thanks @maat7043!)
- `ff_schedule()` for ESPN now credits a bye team with a win instead of causing an error.
- `espn_getendpoint()` no longer returns an error for seasons prior to 2018. (Thanks, @JoeSydlowski!)
- `nflfastr_weekly()` and `nflfastr_roster()` now use the [nflreadr](https://nflreadr.nflverse.com) package functions back-end
- Added some names to the name database, c/o @scasanova via #320 - thank you, Santiago!
- `ff_starters()` for ESPN now also tries to return a projected score for the week - thank you, @scottfrechette! Resolves #323.
- `ff_schedule()` for Sleeper no longer broken - resolves #322.
- `ff_schedule()` for MFL now returns NA as the result for unplayed games and becomes consistent with other platforms.
- `ff_scoringhistory()` for MFL now parses decimal ranges correctly
- Refactor `ff_scoringhistory()` into memoisable pieces (`.nflfastr_offense_long`, `.nflfastr_kicker_long`, `.nflfastr_roster`)
- Update http error messages for user readability.
- Minimum R version bumped to 3.6.0 - nflreadr uses RDS versions that require a minimum of R3.6.

## Thanks

Immensely grateful to: Joe Sydlowski, Matt Spencer, Santiago Casanova, Scott Frechette, and all others who raised issues and contributed code towards this release!

---

# ffscrapr 1.4.5

The main goal of v1.4.5 is to comply with CRAN somehow testing our examples.

## Minor changes

- `ff_league()` for ESPN now works for non-ppr leagues.
- Include `try()` in all examples because apparently `\donttest` doesn't do anything anymore 😡 (fixes #308)

Expand Down
5 changes: 4 additions & 1 deletion R/0_cache.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
dp_playerids,
nflfastr_weekly,
nflfastr_rosters,
.nflfastr_kicking_long,
.nflfastr_offense_long,
.nflfastr_roster,
mfl_players,
sleeper_players,
espn_players,
Expand Down Expand Up @@ -51,5 +54,5 @@
ff_schedule.espn_conn
)

purrr::walk(functions, memoise::forget)
lapply(functions, memoise::forget)
}
2 changes: 1 addition & 1 deletion R/0_generics.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#'
#' @examples
#' \donttest{
#' ff_connect(platform = "mfl", season = 2019, league_id = 54040, rate_limit = FALSE)
#' ff_connect(platform = "mfl", season = 2019, league_id = 54040, rate_limit = FALSE)
#' }
#' @export ff_connect
#' @return a connection object to be used with `ff_*` functions
Expand Down
7 changes: 3 additions & 4 deletions R/0_helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,16 @@ set_unescaped_cookies <- function(...) {
#'
#' @keywords internal
#'
release_bullets <- function(){
release_bullets <- function() {

#nocov start
# nocov start

c(
"Tag the current version of ffscrapr-tests as a release version",
'Switch all vignettes and tests to use "ffscrapr-tests-v1.x.x" and download "archive/v1.x.x"'
)

#nocov end

# nocov end
}

#' Mappings for nflfastr to fantasy platform scoring
Expand Down
19 changes: 10 additions & 9 deletions R/1_import_dp.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ dp_playerids <- function() {
#' dp_cleannames(c("A.J. Green", "Odell Beckham Jr.", "Le'Veon Bell Sr."))
#'
#' dp_cleannames(c("Trubisky, Mitch", "Atwell, Chatarius", "Elliott, Zeke", "Elijah Moore"),
#' convert_lastfirst = TRUE,
#' use_name_database = TRUE)
#' convert_lastfirst = TRUE,
#' use_name_database = TRUE
#' )
#' }
#'
#' @seealso `dp_name_mapping`
Expand All @@ -110,15 +111,15 @@ dp_cleannames <- function(player_name, lowercase = FALSE, convert_lastfirst = TR

n <- player_name

if(convert_lastfirst) n <- stringr::str_replace_all(n, "^(.+), (.+)$", "\\2 \\1")
if (convert_lastfirst) n <- stringr::str_replace_all(n, "^(.+), (.+)$", "\\2 \\1")

n <- stringr::str_remove_all(n, "( Jr\\.$)|( Sr\\.$)|( III$)|( II$)|( IV$)|( V$)|(\\')|(\\.)")

n <- stringr::str_squish(n)

if(use_name_database) n <- unname(dplyr::coalesce(ffscrapr::dp_name_mapping[n],n))
if (use_name_database) n <- unname(dplyr::coalesce(ffscrapr::dp_name_mapping[n], n))

if(lowercase) n <- tolower(n)
if (lowercase) n <- tolower(n)

return(n)
}
Expand Down Expand Up @@ -152,17 +153,17 @@ dp_clean_names <- dp_cleannames
#'
#' @examples
#'
#' c("<b><font color= Cyan>Kevin OBrien (@kevinobrienff) </FONT></B>",
#' c(
#' "<b><font color= Cyan>Kevin OBrien (@kevinobrienff) </FONT></B>",
#' "<em><font color= Purple> Other fun names</font></em>"
#' ) %>% dp_clean_html()
#'
#' ) %>% dp_clean_html()
#' @return a character vector of cleaned strings
#'
#' @export
dp_clean_html <- function(names) {
checkmate::assert_character(names)

n <- stringr::str_remove_all(names,"<[^>]*>") %>% stringr::str_squish()
n <- stringr::str_remove_all(names, "<[^>]*>") %>% stringr::str_squish()

return(n)
}
117 changes: 63 additions & 54 deletions R/1_import_nflfastr.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

#' Import latest nflfastr weekly stats
#'
#' Fetches a copy of the latest week-level stats from nflfastr's data repository.
#' The same output as nflfastr's load_player_stats() function.
#' Fetches a copy of the latest week-level stats from nflfastr's data repository, via the [nflreadr](https://nflreadr.nflverse.com) package.
#'
#' The goal of this data is to replicate the NFL's official weekly stats, which
#' can diverge a bit from what fantasy data feeds display.
#'
#' If you have any issues with the output of this data, please open an issue in
#' the nflfastr repository.
#'
#' @param type One of "offense", "defense", or "all" - currently, only "offense" is available.
#' @param seasons The seasons to return, TRUE returns all data available.
#' @param type One of "offense" or "kicking"
#'
#' @seealso <https://www.nflfastr.com/reference/load_player_stats.html>
#' @seealso <https://nflreadr.nflverse.com>
#'
#' @examples
#' \donttest{
Expand All @@ -22,24 +22,15 @@
#' )
#' }
#'
#' @return Weekly stats for all passers, rushers and receivers in the nflfastR play-by-play data from the 1999 season to the most recent season
#' @return Weekly stats for all passers, rushers and receivers in the nflverse play-by-play data from the 1999 season to the most recent season
#'
#' @export
nflfastr_weekly <- function(type = c("offense", "defense", "all")) {
file_name <- match.arg(type)
nflfastr_weekly <- function(seasons = TRUE,
type = c("offense", "kicking")) {

url_query <- "https://github.com/nflverse/nflfastR-data/raw/master/data/player_stats.rds"
type <- match.arg(type)

response <- httr::RETRY("GET", url_query)

if (httr::http_error(response)) {
stop(glue::glue("GitHub request failed with error: <{httr::status_code(response)}> \n
while calling <{url_query}>"), call. = FALSE)
}

raw_weekly <- httr::content(response, as = "raw")

df_weekly <- parse_raw_rds(raw_weekly)
df_weekly <- nflreadr::load_player_stats(seasons = seasons, stat_type = type)

return(df_weekly)
}
Expand All @@ -52,9 +43,9 @@ nflfastr_weekly <- function(type = c("offense", "defense", "all")) {
#' If you have any issues with the output of this data, please open an issue in
#' the nflfastr repository.
#'
#' @param seasons A numeric vector of seasons, earliest of which is 1999
#' @param seasons A numeric vector of seasons, earliest of which is 1999. TRUE returns all seasons, NULL returns latest season.
#'
#' @seealso <https://www.nflfastr.com/reference/fast_scraper_roster.html>
#' @seealso <https://nflreadr.nflverse.com>
#'
#' @examples
#' \donttest{
Expand All @@ -68,45 +59,63 @@ nflfastr_weekly <- function(type = c("offense", "defense", "all")) {
#' @export

nflfastr_rosters <- function(seasons) {
checkmate::assert_numeric(seasons, lower = 1999, upper = lubridate::year(Sys.Date()))

urls <- glue::glue("https://github.com/nflverse/nflfastR-roster/raw/master/data/seasons/roster_{seasons}.rds")

df_rosters <- purrr::map_df(urls, .nflfastr_roster)
df_rosters <- nflreadr::load_rosters(seasons = seasons)

return(df_rosters)
}

.nflfastr_roster <- function(url_query) {
response <- httr::RETRY("GET", url_query)

if (httr::http_error(response)) {
stop(glue::glue("GitHub request failed with error: <{httr::status_code(response)}> \n
while calling <{url_query}>"), call. = FALSE)
}

df_roster <- response %>%
httr::content(as = "raw") %>%
parse_raw_rds()

return(df_roster)
.nflfastr_offense_long <- function(season){
ps <- nflfastr_weekly(seasons = season, type = "offense") %>%
dplyr::select(dplyr::any_of(c(
"season", "week","player_id",
"attempts", "carries", "completions", "interceptions", "passing_2pt_conversions", "passing_first_downs",
"passing_tds", "passing_yards", "receiving_2pt_conversions", "receiving_first_downs",
"receiving_fumbles", "receiving_fumbles_lost", "receiving_tds",
"receiving_yards", "receptions", "rushing_2pt_conversions", "rushing_first_downs",
"rushing_fumbles", "rushing_fumbles_lost", "rushing_tds", "rushing_yards",
"sack_fumbles", "sack_fumbles_lost", "sack_yards", "sacks", "special_teams_tds",
"targets")
)) %>%
tidyr::pivot_longer(
names_to = "metric",
cols = -c("season","week","player_id")
)

return(ps)
}

#' Parse Raw RDS
#'
#' Useful for parsing the raw-content of RDS files downloaded from nflfastr repo, c/o Seb.
#'
#' @param raw raw-content that is known to be an RDS file
#'
#' @seealso `httr::set_cookies`
#'
#' @keywords internal

parse_raw_rds <- function(raw) {
con <- gzcon(rawConnection(raw))

on.exit(close(con))
.nflfastr_kicking_long <- function(season){
psk <- nflfastr_weekly(seasons = season, type = "kicking") %>%
dplyr::select(dplyr::any_of(c(
"season","week","player_id",
"fg_att", "fg_blocked",
"fg_made", "fg_made_0_19", "fg_made_20_29", "fg_made_30_39",
"fg_made_40_49", "fg_made_50_59", "fg_made_60_", "fg_made_distance",
"fg_missed", "fg_missed_0_19", "fg_missed_20_29", "fg_missed_30_39",
"fg_missed_40_49", "fg_missed_50_59", "fg_missed_60_", "fg_missed_distance",
"fg_pct","pat_att", "pat_blocked", "pat_made",
"pat_missed", "pat_pct"
))) %>%
tidyr::pivot_longer(
names_to = "metric",
cols = -c("season","week","player_id")
)
return(psk)
}

readRDS(con) %>%
tibble::tibble()
.nflfastr_roster <- function(season){
ros <- nflfastr_rosters(season) %>%
dplyr::mutate(position = ifelse(.data$position %in% c("HB", "FB"), "RB", .data$position)) %>%
dplyr::select(dplyr::any_of(c(
"season","gsis_id","sportradar_id",
"player_name"="full_name","pos"="position","team"
))) %>%
dplyr::left_join(
dp_playerids() %>%
dplyr::select("sportradar_id","mfl_id","sleeper_id","espn_id","fleaflicker_id"),
by = c("sportradar_id"),
na_matches = "never"
)

return(ros)
}
Loading

0 comments on commit 2e74ecc

Please sign in to comment.