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

Add Season Inputs to flea api calls #408

Merged
merged 10 commits into from
Aug 13, 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
2 changes: 1 addition & 1 deletion 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.8.05
Version: 1.4.8.06
Authors@R:
c(person(given = "Tan",
family = "Ho",
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ 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()`, `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)

# 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually explains a pesky problem as to why the number of franchises had changed in this test: the league originally had 16 in 2020 but now has 12, and I couldn't figure out why this wasn't working before 😅 1a47994

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
Loading