Skip to content

Commit

Permalink
update mbb loader tests and reducing seasons in vignette
Browse files Browse the repository at this point in the history
  • Loading branch information
saiemgilani committed Apr 5, 2023
1 parent bb73995 commit 6746ae4
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 70 deletions.
42 changes: 23 additions & 19 deletions tests/testthat/test-load_mbb_pbp.R
Expand Up @@ -4,49 +4,53 @@ test_that("hoopR Loader MBB Play-by-Play", {


cols <- c(
"game_id",
"season",
"season_type",
"game_date",
"game_date_time",
"id",
"sequence_number",
"period_display_value",
"clock_display_value",
"away_team_abbrev",
"home_team_abbrev",
"text",
"type_id",
"type_text",
"text",
"team_id",
"athlete_id_1",
"athlete_id_2",
"away_score",
"home_score",
"period_number",
"period_display_value",
"clock_display_value",
"shooting_play",
"scoring_play",
"score_value",
"team_id",
"participants_0_athlete_id",
"coordinate_x_raw",
"coordinate_y_raw",
"coordinate_x",
"coordinate_y",
"clock_minutes",
"clock_seconds",
"period_number",
"wallclock",
"shooting_play",
"participants_1_athlete_id",
"season",
"season_type",
"away_team_id",
"away_team_name",
"away_team_mascot",
"away_team_abbrev",
"away_team_name_alt",
"home_team_id",
"home_team_name",
"home_team_mascot",
"home_team_abbrev",
"home_team_name_alt",
"home_team_spread",
"game_spread",
"home_favorite",
"game_spread_available",
"game_id",
"qtr",
"time",
"clock_minutes",
"clock_seconds",
"half",
"game_half",
"lag_qtr",
"lead_qtr",
"lag_game_half",
"lead_game_half",
"start_quarter_seconds_remaining",
"start_half_seconds_remaining",
Expand All @@ -56,8 +60,8 @@ test_that("hoopR Loader MBB Play-by-Play", {
"end_half_seconds_remaining",
"end_game_seconds_remaining",
"period",
"coordinate_x",
"coordinate_y",
"lag_qtr",
"lag_game_half",
"media_id"
)

Expand Down
62 changes: 41 additions & 21 deletions tests/testthat/test-load_mbb_player_box.R
Expand Up @@ -4,40 +4,60 @@ test_that("hoopR Loader MBB Player Box", {


cols <- c(
"game_id",
"season",
"season_type",
"game_date",
"game_date_time",
"athlete_id",
"athlete_display_name",
"team_id",
"team_name",
"team_location",
"team_short_display_name",
"min",
"fg",
"fg3",
"ft",
"oreb",
"dreb",
"reb",
"ast",
"stl",
"blk",
"to",
"pf",
"pts",
"minutes",
"field_goals_made",
"field_goals_attempted",
"three_point_field_goals_made",
"three_point_field_goals_attempted",
"free_throws_made",
"free_throws_attempted",
"offensive_rebounds",
"defensive_rebounds",
"rebounds",
"assists",
"steals",
"blocks",
"turnovers",
"fouls",
"points",
"starter",
"ejected",
"did_not_play",
"active",
"athlete_jersey",
"athlete_id",
"athlete_short_name",
"athlete_headshot_href",
"athlete_position_name",
"athlete_position_abbreviation",
"team_name",
"team_display_name",
"team_uid",
"team_slug",
"team_logo",
"team_id",
"team_abbreviation",
"team_color",
"game_id",
"season",
"season_type",
"game_date"
"team_alternate_color",
"home_away",
"team_winner",
"team_score",
"opponent_team_id",
"opponent_team_name",
"opponent_team_location",
"opponent_team_display_name",
"opponent_team_abbreviation",
"opponent_team_logo",
"opponent_team_color",
"opponent_team_alternate_color",
"opponent_team_score"
)

expect_equal(sort(colnames(x)), sort(cols))
Expand Down
4 changes: 3 additions & 1 deletion tests/testthat/test-load_mbb_schedule.R
Expand Up @@ -75,7 +75,9 @@ test_that("hoopR Loader MBB Schedule", {
"tournament_id",
"PBP",
"team_box",
"player_box"
"player_box",
"game_date",
"game_date_time"
)

expect_equal(sort(colnames(x)), sort(cols))
Expand Down
58 changes: 36 additions & 22 deletions tests/testthat/test-load_mbb_team_box.R
Expand Up @@ -4,6 +4,11 @@ test_that("hoopR Loader MBB Team Box", {


cols <- c(
"game_id",
"season",
"season_type",
"game_date",
"game_date_time",
"team_id",
"team_uid",
"team_slug",
Expand All @@ -15,35 +20,44 @@ test_that("hoopR Loader MBB Team Box", {
"team_color",
"team_alternate_color",
"team_logo",
"field_goals_made_field_goals_attempted",
"team_home_away",
"team_score",
"team_winner",
"assists",
"blocks",
"defensive_rebounds",
"field_goal_pct",
"three_point_field_goals_made_three_point_field_goals_attempted",
"three_point_field_goal_pct",
"free_throws_made_free_throws_attempted",
"field_goals_made",
"field_goals_attempted",
"flagrant_fouls",
"fouls",
"free_throw_pct",
"total_rebounds",
"free_throws_made",
"free_throws_attempted",
"largest_lead",
"offensive_rebounds",
"defensive_rebounds",
"assists",
"steals",
"blocks",
"turnovers",
"team_turnovers",
"total_turnovers",
"technical_fouls",
"three_point_field_goal_pct",
"three_point_field_goals_made",
"three_point_field_goals_attempted",
"total_rebounds",
"total_technical_fouls",
"flagrant_fouls",
"fouls",
"largest_lead",
"home_away",
"opponent_id",
"opponent_name",
"opponent_mascot",
"opponent_abbrev",
"game_id",
"season",
"season_type",
"game_date"
"total_turnovers",
"turnovers",
"opponent_team_id",
"opponent_team_uid",
"opponent_team_slug",
"opponent_team_location",
"opponent_team_name",
"opponent_team_abbreviation",
"opponent_team_display_name",
"opponent_team_short_display_name",
"opponent_team_color",
"opponent_team_alternate_color",
"opponent_team_logo",
"opponent_team_score"
)

expect_equal(sort(colnames(x)), sort(cols))
Expand Down
14 changes: 7 additions & 7 deletions vignettes/getting-started-hoopR.Rmd
Expand Up @@ -79,13 +79,13 @@ There are generally speaking **six** men's basketball data sources accessed from

## **Quick Start**

For the sake of your R session, we will only look at the previous 5 years of data, but I have indicated the years to which the data goes back to.
For the sake of your R session, we will only look at the previous 3 years of data, but I have indicated the years to which the data goes back to.

### **NBA play-by-plays (2002-`r hoopR::most_recent_nba_season()`) ~ 60-120 seconds**
```{r load_nba_pbp_gs, warning = FALSE}
tictoc::tic()
progressr::with_progress({
nba_pbp <- hoopR::load_nba_pbp(2018:hoopR::most_recent_nba_season())
nba_pbp <- hoopR::load_nba_pbp(2021:hoopR::most_recent_nba_season())
})
tictoc::toc()
glue::glue("{nrow(nba_pbp)} rows of nba play-by-play data from {length(unique(nba_pbp$game_id))} games.")
Expand All @@ -96,7 +96,7 @@ dplyr::glimpse(nba_pbp)
```{r load_nba_team_gs, warning = FALSE}
tictoc::tic()
progressr::with_progress({
nba_team_box <- hoopR::load_nba_team_box(2018:hoopR::most_recent_nba_season())
nba_team_box <- hoopR::load_nba_team_box(2021:hoopR::most_recent_nba_season())
})
tictoc::toc()
Expand All @@ -109,7 +109,7 @@ dplyr::glimpse(nba_team_box)
```{r load_nba_player_gs, warning = FALSE}
tictoc::tic()
progressr::with_progress({
nba_player_box <- hoopR::load_nba_player_box(2018:hoopR::most_recent_nba_season())
nba_player_box <- hoopR::load_nba_player_box(2021:hoopR::most_recent_nba_season())
})
tictoc::toc()
Expand All @@ -123,7 +123,7 @@ dplyr::glimpse(nba_player_box)
```{r load_mbb_pbp_gs, warning = FALSE}
tictoc::tic()
progressr::with_progress({
mbb_pbp <- hoopR::load_mbb_pbp(2018:hoopR::most_recent_mbb_season())
mbb_pbp <- hoopR::load_mbb_pbp(2021:hoopR::most_recent_mbb_season())
})
tictoc::toc()
glue::glue("{nrow(mbb_pbp)} rows of men's college basketball play-by-play data from {length(unique(mbb_pbp$game_id))} games.")
Expand All @@ -135,7 +135,7 @@ dplyr::glimpse(mbb_pbp)
```{r load_mbb_team_gs, warning = FALSE}
tictoc::tic()
progressr::with_progress({
mbb_team_box <- hoopR::load_mbb_team_box(2018:hoopR::most_recent_mbb_season())
mbb_team_box <- hoopR::load_mbb_team_box(2021:hoopR::most_recent_mbb_season())
})
tictoc::toc()
glue::glue("{nrow(mbb_team_box)} rows of men's college basketball team boxscore data from {length(unique(mbb_team_box$game_id))} games.")
Expand All @@ -147,7 +147,7 @@ dplyr::glimpse(mbb_team_box)
```{r load_mbb_player_gs, warning = FALSE}
tictoc::tic()
progressr::with_progress({
mbb_player_box <- hoopR::load_mbb_player_box(2018:hoopR::most_recent_mbb_season())
mbb_player_box <- hoopR::load_mbb_player_box(2021:hoopR::most_recent_mbb_season())
})
tictoc::toc()
Expand Down

0 comments on commit 6746ae4

Please sign in to comment.