Skip to content

Commit

Permalink
hot fix for team_logos call and to fix season_type in game_info
Browse files Browse the repository at this point in the history
  • Loading branch information
danmorse314 committed Nov 14, 2023
1 parent 3552409 commit 8a3049c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
11 changes: 10 additions & 1 deletion R/get_game_info.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,16 @@ get_game_info <- function(game_id){
away_abbr = site$awayTeam$abbrev,
home_id = site$homeTeam$id,
away_id = site$awayTeam$id
)
) %>%
dplyr::mutate(
season_type = dplyr::case_when(
season_type == 1 ~ "PRE",
season_type == 2 ~ "REG",
season_type == 3 ~ "POST",
season_type == 4 ~ "ALLSTAR",
TRUE ~ NA_character_
)
)

return(game_info)

Expand Down
8 changes: 4 additions & 4 deletions R/scrape_game.R
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
scrape_game <- function(game_id){

# load team abbreviations
team_info <- team_logos_colors
team_info <- hockeyR::team_logos_colors

# get game url
url <- glue::glue("https://api-web.nhle.com/v1/gamecenter/{game_id}/play-by-play")
Expand Down Expand Up @@ -836,7 +836,7 @@ scrape_game <- function(game_id){
# ie preseason

pbp_full <- pbp %>%
dplyr::select(-event_id,-event_code) %>%
dplyr::select(-event_id) %>%
# add fixed x & y coordinates so home team shoots right, away shoots left
dplyr::group_by(event_team, period, game_id) %>%
# find median x shot coordinate to tell us which side teams are shooting on
Expand Down Expand Up @@ -929,7 +929,7 @@ scrape_game <- function(game_id){
# "event_player_3_name","event_goalie_name"),
# ~stringr::str_replace_all(.x, c(" " = ".", "-" = "."))
#) %>%
dplyr::select(-event_id,-event_code) %>%
dplyr::select(-event_id) %>%
dplyr::mutate(
event_team_type = dplyr::case_when(
event_team == home_name ~ "home",
Expand All @@ -950,7 +950,7 @@ scrape_game <- function(game_id){
# "event_goalie_name"),
# ~stringr::str_replace_all(.x, c(" " = ".", "-" = "."))
#) %>%
dplyr::select(-event_id,-event_code) %>%
dplyr::select(-event_id) %>%
dplyr::mutate(
event_team_type = dplyr::case_when(
event_team == home_name ~ "home",
Expand Down

0 comments on commit 8a3049c

Please sign in to comment.