From 8a3049cb3e4c484003dd328d17e5996bd9df1ad9 Mon Sep 17 00:00:00 2001 From: Dan Morse Date: Mon, 13 Nov 2023 19:36:13 -0800 Subject: [PATCH] hot fix for team_logos call and to fix season_type in game_info --- R/get_game_info.R | 11 ++++++++++- R/scrape_game.R | 8 ++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/R/get_game_info.R b/R/get_game_info.R index f8edcbb..0c5360d 100644 --- a/R/get_game_info.R +++ b/R/get_game_info.R @@ -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) diff --git a/R/scrape_game.R b/R/scrape_game.R index e21c218..96bb4ed 100644 --- a/R/scrape_game.R +++ b/R/scrape_game.R @@ -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") @@ -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 @@ -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", @@ -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",