Skip to content

Commit

Permalink
Update more from 2023 to 2024
Browse files Browse the repository at this point in the history
  • Loading branch information
k5cents committed Aug 26, 2024
1 parent 385130c commit 45dd53d
Show file tree
Hide file tree
Showing 19 changed files with 68 additions and 41 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# fflr 2.3.1

* Update `nfl_players` and `nfl_schedule` for 2024 season.
* Continue updates to switch from 2023 to 2024.

# fflr 2.3.0

Expand Down
2 changes: 1 addition & 1 deletion R/api.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#' be called? If `TRUE`, a list of results is returned, with one element for
#' each historical year of the league.
#' @param seasonId Integer year of NFL season. By default, the season is
#' currently set to 2023. Use a recent year or set `leagueHistory` to `TRUE`
#' currently set to 2024. Use a recent year or set `leagueHistory` to `TRUE`
#' to obtain all past data.
#' @param scoringPeriodId Integer week of NFL season. By default, `NULL` will
#' use the current week (see [ffl_week()]). Scoring periods are always one
Expand Down
5 changes: 4 additions & 1 deletion R/corrections.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ stat_corrections <- function(date = Sys.Date(), limit = 100) {
dat <- try_json(
url = paste0(
"https://sports.core.api.espn.com",
"/v2/sports/football/leagues/nfl/seasons/2021/corrections"
"/v2/sports/football/leagues/nfl/seasons/2024/corrections"
),
query = list(
limit = limit,
Expand Down Expand Up @@ -54,3 +54,6 @@ stat_corrections <- function(date = Sys.Date(), limit = 100) {
out <- cbind(date = date, out)
as_tibble(out[order(out$playerId), ])
}

# 2023 --------------------------------------------------------------------

18 changes: 9 additions & 9 deletions R/data.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' 2023 NFL Players
#' 2024 NFL Players
#'
#' All available ESPN fantasy football players as of the 2023 season, week 1.
#' All available ESPN fantasy football players as of the 2024 season, week 1.
#'
#' @format A data frame with 1,102 rows and 11 variables:
#' \describe{
Expand All @@ -19,12 +19,12 @@
#' \item{draftSelection}{Overall pick number in the NFL draft}
#' ...
#' }
#' @source \url{http://sports.core.api.espn.com/v2/sports/football/leagues/nfl/seasons/2023/athletes/}
#' @source \url{http://sports.core.api.espn.com/v2/sports/football/leagues/nfl/seasons/2024/athletes/}
"nfl_players"

#' 2023 NFL Teams
#' 2024 NFL Teams
#'
#' The 32 professional NFL teams as of the 2023 season.
#' The 32 professional NFL teams as of the 2024 season.
#'
#' @format A data frame with 33 rows and 6 columns:
#' \describe{
Expand All @@ -36,12 +36,12 @@
#' \item{conference}{NFL conference}
#' ...
#' }
#' @source \url{https://lm-api-reads.fantasy.espn.com/apis/v3/games/ffl/seasons/2023?view=proTeamSchedules_wl}
#' @source \url{https://lm-api-reads.fantasy.espn.com/apis/v3/games/ffl/seasons/2024?view=proTeamSchedules_wl}
"nfl_teams"

#' 2023 NFL Schedule
#' 2024 NFL Schedule
#'
#' The 2023 NFL season schedule by team, as of September 10th.
#' The 2024 NFL season schedule by team, as of September 10th.
#'
#' @format A data frame with 544 rows and 6 variables:
#' \describe{
Expand All @@ -54,5 +54,5 @@
#' \item{date}{Matchup start date and time}
#' ...
#' }
#' @source \url{https://lm-api-reads.fantasy.espn.com/apis/v3/games/ffl/seasons/2023?view=proTeamSchedules_wl}
#' @source \url{https://lm-api-reads.fantasy.espn.com/apis/v3/games/ffl/seasons/2024?view=proTeamSchedules_wl}
"nfl_schedule"
2 changes: 1 addition & 1 deletion R/fflr-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#'
#' The fflr package parses the JSON data returned by the ESPN v3 API into tidy
#' data frames for easy analysis. The package also includes data objects for the
#' NFL with players, teams, and the 2023 schedule. The league must first be made
#' NFL with players, teams, and the 2024 schedule. The league must first be made
#' viewable to the public by the league manager, which can be done on the basic
#' settings page on the ESPN website. Functions can then take the numeric league
#' ID found in the URL to return data from the API. This league ID can be set as
Expand Down
18 changes: 9 additions & 9 deletions R/players.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ list_players <- function(leagueId = ffl_id(),
verb = "GET",
url = paste0(
"https://lm-api-reads.fantasy.espn.com",
"/apis/v3/games/ffl/seasons/2023/segments/0/leagues/",
"/apis/v3/games/ffl/seasons/2024/segments/0/leagues/",
leagueId
),
query = list(view = "kona_player_info"),
Expand Down Expand Up @@ -260,11 +260,11 @@ fantasy_filter <- function(sort, position, status, injured, scoringPeriodId,
filterStatsForTopScoringPeriodIds = list(
value = U(2),
additionalValue = c(
"002023",
"102023",
"002024",
"102024",
"002020",
paste0("112023", scoringPeriodId),
"022023"
paste0("112024", scoringPeriodId),
"022024"
)
)
)
Expand Down Expand Up @@ -314,7 +314,7 @@ filter_sort <- function(sort = "ROST", scoringPeriodId) {
sortAppliedStatTotal = list( # PROJ
sortAsc = FALSE,
sortPriority = 1,
value = paste0("112023", scoringPeriodId)
value = paste0("112024", scoringPeriodId)
),
sortAppliedStatTotalForScoringPeriodId = list( # SCORE
sortAsc = FALSE,
Expand Down Expand Up @@ -346,12 +346,12 @@ filter_sort <- function(sort = "ROST", scoringPeriodId) {
sortAppliedStatTotal = list( # FPTS
sortAsc = FALSE,
sortPriority = 1,
value = "002023"
value = "002024"
),
sortAppliedStatAverage = list( # AVG
sortAsc = FALSE,
sortPriority = 1,
value = "002023"
value = "002024"
),
sortAppliedStatTotalForScoringPeriodId = list( # LAST
sortAsc = FALSE,
Expand Down Expand Up @@ -400,7 +400,7 @@ player_info <- function(playerId) {
dat <- try_json(
url = paste0(
"http://sports.core.api.espn.com/",
"v2/sports/football/leagues/nfl/seasons/2023/athletes/", playerId
"v2/sports/football/leagues/nfl/seasons/2024/athletes/", playerId
)
)
out <- list(
Expand Down
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ If a function doesn't work as intended, please file an [issue on GitHub][iss].
> [!IMPORTANT]
> As of 2024-05-17, fflr was removed from [CRAN][cran] for failure to comply
with the policy on internet resources. This issue arose when ESPN changed their
API format and adjusted andpoints to account for the end of the 2023 NFL season.
API format and adjusted endpoints to account for the end of the 2023 NFL season.
I hope to work with CRAN to get the package published again before the 2024
season, but it may not be possible.

Expand Down
24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ on GitHub](https://github.com/k5cents/fflr/issues).
> As of 2024-05-17, fflr was removed from
> [CRAN](https://cran.r-project.org/package=fflr) for failure to comply
> with the policy on internet resources. This issue arose when ESPN
> changed their API format and adjusted andpoints to account for the end
> changed their API format and adjusted endpoints to account for the end
> of the 2023 NFL season. I hope to work with CRAN to get the package
> published again before the 2024 season, but it may not be possible.
Expand All @@ -47,7 +47,7 @@ remotes::install_github("k5cents/fflr")
``` r
library(fflr)
packageVersion("fflr")
#> [1] '2.3.0'
#> [1] '2.3.1'
```

Data is only available for public leagues. See [this help
Expand Down Expand Up @@ -93,7 +93,25 @@ The `scoringPeriodId` argument can be used to get data from past weeks.
``` r
all_rost <- team_roster(scoringPeriodId = 1)
all_rost$CHI[, 5:13][-7]
#> NULL
#> # A tibble: 16 × 8
#> lineupSlot playerId firstName lastName proTeam position projectedScore actualScore
#> <fct> <int> <chr> <chr> <fct> <fct> <dbl> <dbl>
#> 1 QB 3918298 Josh Allen Buf QB 23.6 NA
#> 2 RB 4430807 Bijan Robinson Atl RB 18.6 NA
#> 3 RB 4239996 Travis Etienne Jr. Jax RB 14.3 NA
#> 4 WR 4262921 Justin Jefferson Min WR 18.1 NA
#> 5 WR 4569618 Garrett Wilson NYJ WR 16.4 NA
#> 6 TE 3116365 Mark Andrews Bal TE 13.1 NA
#> 7 FLEX 4426515 Puka Nacua LAR WR 17.1 NA
#> 8 D/ST -16033 Ravens D/ST Bal D/ST 3.94 NA
#> 9 K 15683 Justin Tucker Bal K 8.23 NA
#> 10 BE 4432708 Marvin Harrison Jr. Ari WR 15.4 NA
#> 11 BE 4429160 De'Von Achane Mia RB 13.9 NA
#> 12 BE 4258173 Nico Collins Hou WR 14.4 NA
#> 13 BE 4360438 Brandon Aiyuk SF WR 13.5 NA
#> 14 BE 4567048 Kenneth Walker III Sea RB 16.0 NA
#> 15 BE 3042519 Aaron Jones Min RB 13.7 NA
#> 16 BE 4429615 Zay Flowers Bal WR 14.8 NA
```

There are included objects for NFL teams and players.
Expand Down
2 changes: 1 addition & 1 deletion man/ffl_api.Rd

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

2 changes: 1 addition & 1 deletion man/fflr-package.Rd

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

6 changes: 3 additions & 3 deletions man/nfl_players.Rd

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

6 changes: 3 additions & 3 deletions man/nfl_schedule.Rd

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

6 changes: 3 additions & 3 deletions man/nfl_teams.Rd

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

2 changes: 2 additions & 0 deletions tests/testthat/test-best.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ test_that("calculate best possible past roster", {
b1 <- b[[1]]
expect_s3_class(b1, "data.frame")
expect_length(b1, 17)
skip_if(all(is.na(b1$actualScore)))

start_rb <- b1$actualScore[b1$lineupSlot == "RB"]
bench_rb <- b1$actualScore[b1$lineupSlot == "BE" & b1$position == "RB"]
Expand All @@ -24,6 +25,7 @@ test_that("calculate best possible future roster", {
b2 <- b[[2]]
expect_s3_class(b2, "data.frame")
expect_length(b2, 17)
skip_if(all(is.na(b2$actualScore)))

start_wr <- b2$projectedScore[b2$lineupSlot == "WR"]
bench_wr <- b2$projectedScore[b2$lineupSlot == "BE" & b2$position == "WR"]
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-corrections.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
test_that("state corrections", {
skip_if(Sys.Date() < "2024-09-12")
c <- stat_corrections(date = "2021-09-13")
expect_s3_class(c, "data.frame")
expect_s3_class(c$date, "Date")
expect_length(c, 5)
})

test_that("state corrections errors", {
skip_if(Sys.Date() < "2024-09-12")
expect_error(stat_corrections(date = 1))
})
4 changes: 2 additions & 2 deletions tests/testthat/test-history.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ test_that("historical data can be returned", {

test_that("historical data can be combined", {
h <- combine_history(
fun = league_simulation,
fun = league_standings,
leagueId = "42654852"
)
expect_s3_class(h, "data.frame")
expect_length(h, 6)
expect_length(h, 17)
})
2 changes: 1 addition & 1 deletion tests/testthat/test-live.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ test_that("live scoring returns 1 row per team", {
skip_empty(l)
expect_s3_class(l, "data.frame")
# expect_true("toPlay" %in% names(l))
expect_length(l, 7)
expect_length(l, 8)
expect_equal(nrow(l), 4)
})
3 changes: 2 additions & 1 deletion tests/testthat/test-settings.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ Sys.sleep(runif(1, 1, 2))
test_that("schedule settings for a single season", {
s <- schedule_settings("42654852", leagueHistory = FALSE)
expect_s3_class(s, "data.frame")
expect_length(s, 12)
expect_length(s, 13)
skip_empty(s)
expect_s3_class(s$matchupPeriods[[1]], "data.frame")
expect_s3_class(s$divisions[[1]], "data.frame")
})
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-simulation.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ test_that("get simulated season projections", {
leagueId = "42654852"
)
expect_s3_class(s, "data.frame")
expect_length(s, 5)
expect_length(s, 11)
})

0 comments on commit 45dd53d

Please sign in to comment.