|
| 1 | +# We test the output of nflseedR::nfl_regular_season in a snapshot test |
| 2 | +# This file hosts code to verify that the current state is correct, and therefore |
| 3 | +# the snapshot is correct. |
| 4 | + |
| 5 | +# We want to verify that our functions does all rotations correctly. So we have |
| 6 | +# to compute matchups of 8 seasons, including at least two seasons with 17 games. |
| 7 | + |
| 8 | +# We do it for the 2017:2024 seasons, which means we need standings of the |
| 9 | +# 2016:2023 seasons |
| 10 | +games <- nflreadr::load_schedules(2016:2024) |> |
| 11 | + dplyr::mutate( |
| 12 | + # can't compute neutral site games so we overwrite them here |
| 13 | + location = "home" |
| 14 | + ) |
| 15 | + |
| 16 | +# to compare 2017:2024 season matchups, we need 2016:2023 standings |
| 17 | +standings <- games |> |
| 18 | + dplyr::filter(dplyr::between(season, 2016, 2023)) |> |
| 19 | + nflseedR::nfl_standings(ranks = "DIV") |> |
| 20 | + dplyr::mutate( |
| 21 | + team = nflreadr::clean_team_abbrs(team) |
| 22 | + ) |
| 23 | +actual_matchups <- games |> |
| 24 | + dplyr::filter(game_type == "REG", season >= 2017) |> |
| 25 | + nflreadr::clean_homeaway() |> |
| 26 | + dplyr::mutate( |
| 27 | + # we need standardized team names for later comparison |
| 28 | + team = nflreadr::clean_team_abbrs(team), |
| 29 | + opponent = nflreadr::clean_team_abbrs(opponent) |
| 30 | + ) |> |
| 31 | + dplyr::select(season, team, opp = opponent, location) |> |
| 32 | + dplyr::arrange(season, team, opp) |
| 33 | + |
| 34 | +# nflseedR::nfl_regular_season is designed to work with one season only |
| 35 | +# there is no point in vectorizing it across seasons |
| 36 | +regular_seasons <- lapply( |
| 37 | + sort(unique(standings$season)), |
| 38 | + function(year, standings) { |
| 39 | + s <- standings[season == year] |
| 40 | + nflseedR::nfl_regular_season(s) |
| 41 | + }, |
| 42 | + standings = standings |
| 43 | +) |> |
| 44 | + data.table::rbindlist() |
| 45 | + |
| 46 | +# now we make an anti join. All matches in both tables will be removed |
| 47 | +# ideally this has 0 rows which means we've done perfect |
| 48 | +# In reality this has two lines. It's the 2022 W17 Bills at Bengals matchup |
| 49 | +# that got cancelled (he Damar Hamlin game) |
| 50 | +mismatches <- regular_seasons |> |
| 51 | + dplyr::anti_join(actual_matchups) |
0 commit comments