Skip to content

Commit

Permalink
Merge pull request #125 from sportsdataverse/issue-124/schedule_endpoint
Browse files Browse the repository at this point in the history
Issue 124/schedule endpoint
  • Loading branch information
rossdrucker committed Oct 11, 2023
2 parents 37cf5ba + 04c1f02 commit 6f7536e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
19 changes: 16 additions & 3 deletions R/nba_stats_scoreboard.R
Expand Up @@ -98,9 +98,22 @@ nba_schedule <- function(
games <- league_sched %>%
purrr::pluck("gameDates") %>%
tidyr::unnest("games") %>%
tidyr::unnest("awayTeam", names_sep = "_") %>%
tidyr::unnest("homeTeam", names_sep = "_") %>%
dplyr::select(-dplyr::any_of(c("broadcasters", "pointsLeaders"))) %>%
dplyr::bind_cols(
league_sched %>%
purrr::pluck("gameDates") %>%
tidyr::unnest("games") %>%
purrr::pluck("homeTeam") %>%
dplyr::rename_with(~paste0("home_team_", .x))
) %>%
dplyr::bind_cols(
league_sched %>%
purrr::pluck("gameDates") %>%
tidyr::unnest("games") %>%
purrr::pluck("awayTeam") %>%
dplyr::rename_with(~paste0("away_team_", .x))
) %>%
select(-homeTeam, -awayTeam) %>%
janitor::clean_names()
colnames(games) <- gsub('team_team', 'team', colnames(games))
games$game_id <- unlist(purrr::map(games$game_id,function(x){
Expand All @@ -117,7 +130,7 @@ nba_schedule <- function(
.data$season_type_id == 3 ~ "All-Star",
.data$season_type_id == 4 ~ "Playoffs",
.data$season_type_id == 5 ~ "Play-In Game"),
game_date = lubridate::mdy(substring(.data$game_date,1,10)))
game_date = lubridate::mdy(substring(.data$game_date, 1, 10)))

},
error = function(e) {
Expand Down
4 changes: 3 additions & 1 deletion tests/testthat/test-nba_schedule.R
Expand Up @@ -51,7 +51,9 @@ test_that("NBA Schedule", {
"away_team_score",
"away_team_seed",
"season",
"league_id"
"league_id",
"season_type_id",
"season_type_description"
)

expect_equal(sort(colnames(x)), sort(cols_x1))
Expand Down

0 comments on commit 6f7536e

Please sign in to comment.