Skip to content

Commit

Permalink
Merge branch 'main' into flea_ffstarters_enhance
Browse files Browse the repository at this point in the history
  • Loading branch information
tanho63 authored Aug 13, 2023
2 parents b571887 + 519915b commit 0f07cbe
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 30 deletions.
13 changes: 5 additions & 8 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@ positions that did not have dedicated posititions (#400, thank you @mcarman8!)
(v1.4.8.03)
- `ff_scoring.mfl_conn()` now works better with new dplyr versions (#402) (v1.4.8.04)
- `ff_schedule.mfl_conn()` bug fixed re: removing bad spreads (#403) (v1.4.8.05)
- `ff_franchises.flea_conn` add season parameter to return franchises for other years
but current year (v1.4.8.06)
- `ff_playerscores.flea_conn` add season parameter to return player scores for other years
but current year (v1.4.8.06)
- `ff_rosters.flea_conn` add season parameter to return rosters for other years
but current year (v1.4.8.06)
- `ff_starters.flea_conn` expand starters to show injury data from box score and keep NA data
where a player is not in a slot. (v1.4.8.07)
- `ff_franchises()`, `ff_playerscores()`, `ff_rosters()` fleaflicker methods now
respect `season` in connection object (v1.4.8.06) (#408, thank you @RandalMorris!)
- `ff_rosters()` fleaflicker method now accepts `week` argument (v1.4.8.06)
- `ff_starters()` fleaflicker method expands to show injury data from box score
and keep NA data where a player is not in a slot. (v1.4.8.07)

# ffscrapr 1.4.8

Expand Down
25 changes: 17 additions & 8 deletions R/flea_franchises.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,40 @@
#' @export

ff_franchises.flea_conn <- function(conn) {
x <- fleaflicker_getendpoint("FetchLeagueStandings", league_id = conn$league_id, sport = "NFL") %>%
x <- fleaflicker_getendpoint(
"FetchLeagueStandings",
season = conn$season,
league_id = conn$league_id,
sport = "NFL"
) %>%
purrr::pluck("content", "divisions") %>%
tibble::tibble() %>%
tidyr::hoist(1, "division_id" = "id", "division_name" = "name", "teams") %>%
tidyr::unnest_longer("teams") %>%
tidyr::hoist("teams",
tidyr::hoist(
"teams",
"franchise_id" = "id",
"franchise_name" = "name",
"franchise_logo" = "logoUrl",
"franchise_abbrev" = "initials",
"owners"
) %>%
tidyr::unnest_longer("owners") %>%
tidyr::hoist("owners",
tidyr::hoist(
"owners",
"user_id" = "id",
"user_name" = "displayName",
"user_avatar" = "avatarUrl",
"user_lastlogin" = "lastSeen"
) %>%
dplyr::mutate_at("user_lastlogin", ~ (as.numeric(.x) / 1000) %>% .as_datetime()) %>%
dplyr::select(dplyr::any_of(c(
dplyr::starts_with("division"),
dplyr::starts_with("franchise"),
dplyr::starts_with("user")
)))
dplyr::select(
dplyr::any_of(c(
dplyr::starts_with("division"),
dplyr::starts_with("franchise"),
dplyr::starts_with("user")
))
)

return(x)
}
17 changes: 11 additions & 6 deletions R/flea_playerscores.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ ff_playerscores.flea_conn <- function(conn, page_limit = NULL, ...) {
endpoint = "FetchPlayerListing",
sport = "NFL",
league_id = conn$league_id,
sort_season = conn$season,
external_id_type = "SPORTRADAR",
result_offset = result_offset
) %>%
Expand Down Expand Up @@ -57,13 +58,15 @@ ff_playerscores.flea_conn <- function(conn, page_limit = NULL, ...) {

df_players <- players %>%
tibble::tibble() %>%
tidyr::hoist(1,
tidyr::hoist(
1,
"player" = "proPlayer",
"score_total" = "seasonTotal",
"score_avg" = "seasonAverage",
"score_sd" = "seasonsStandartDeviation"
) %>%
tidyr::hoist("player",
tidyr::hoist(
"player",
"player_id" = "id",
"player_name" = "nameFull",
"pos" = "position",
Expand All @@ -76,10 +79,12 @@ ff_playerscores.flea_conn <- function(conn, page_limit = NULL, ...) {
),
games = (.data$score_total / .data$score_avg) %>% round()
) %>%
dplyr::select(dplyr::any_of(c(
"player_id", "player_name", "pos", "team", "games",
"score_total", "score_avg", "score_sd"
)))
dplyr::select(
dplyr::any_of(c(
"player_id", "player_name", "pos", "team", "games",
"score_total", "score_avg", "score_sd"
))
)

return(df_players)
}
12 changes: 9 additions & 3 deletions R/flea_rosters.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#' Get a dataframe of roster data
#'
#' @param conn a conn object created by `ff_connect()`
#' @param week integer, optional: select week to return, otherwise returns latest
#' @param ... arguments passed to other methods (currently none)
#'
#' @examples
Expand All @@ -15,11 +16,14 @@
#' }
#' @describeIn ff_rosters Fleaflicker: Returns roster data (minus age as of right now)
#' @export
ff_rosters.flea_conn <- function(conn, ...) {
ff_rosters.flea_conn <- function(conn, week = NULL, ...) {

df_rosters <- fleaflicker_getendpoint("FetchLeagueRosters",
sport = "NFL",
external_id_type = "SPORTRADAR",
league_id = conn$league_id
league_id = conn$league_id,
season = conn$season,
scoring_period = week
) %>%
purrr::pluck("content", "rosters") %>%
tibble::tibble() %>%
Expand All @@ -35,7 +39,9 @@ ff_rosters.flea_conn <- function(conn, ...) {
"team" = "proTeamAbbreviation",
"externalIds"
) %>%
dplyr::mutate(sportradar_id = purrr::map_chr(.data$externalIds, purrr::pluck, 1, "id", .default = NA)) %>%
dplyr::mutate(
sportradar_id = purrr::map_chr(.data$externalIds, purrr::pluck, 1, "id", .default = NA)
) %>%
dplyr::select(dplyr::any_of(c(
"franchise_id",
"franchise_name",
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-ff_franchises.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ test_that("ff_franchises returns a tibble of franchises", {
expect_tibble(dlf_franchises, nrows = 16)
expect_tibble(jml_franchises, nrow = 12)
expect_tibble(dlp_franchises, nrow = 12)
expect_tibble(joe_franchises, nrow = 12)
expect_tibble(joe_franchises, nrow = 16)
expect_tibble(tony_franchises, nrow = 10)
})
6 changes: 3 additions & 3 deletions vignettes/fleaflicker_basics.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ knitr::opts_chunk$set(
options(dplyr.summarise.inform = FALSE,
rmarkdown.html_vignette.check_title = FALSE)
eval <- TRUE
eval <- FALSE
tryCatch(expr = {
download.file("https://github.com/ffverse/ffscrapr-tests/archive/1.4.7.zip","f.zip")
unzip('f.zip', exdir = ".")
httptest::.mockPaths(new = "ffscrapr-tests-1.4.7")},
warning = function(e) eval <<- FALSE,
error = function(e) eval <<- FALSE)
Expand Down
2 changes: 1 addition & 1 deletion vignettes/fleaflicker_getendpoint.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ knitr::opts_chunk$set(
options(dplyr.summarise.inform = FALSE,
rmarkdown.html_vignette.check_title = FALSE)
eval <- TRUE
eval <- FALSE
tryCatch(expr = {
Expand Down

0 comments on commit 0f07cbe

Please sign in to comment.