Skip to content

Commit

Permalink
changing a few things in schedule pull
Browse files Browse the repository at this point in the history
  • Loading branch information
benny-dreyf committed Sep 8, 2023
1 parent ce74b34 commit 252fd37
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions R/nfl_season_schedule.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,34 @@
#' @example None
#'
#' @export
nfl_season_schedule<-function(year){
nfl_year<- paste('https://www.pro-football-reference.com/years/', year, '/games.htm', sep= '')
nfl_season_schedule<-function(season_year){
nfl_year<- paste('https://www.pro-football-reference.com/years/', season_year, '/games.htm', sep= '')
nfl_year
rvest::read_html(nfl_year) |>
rvest::html_elements('table') |>
rvest::html_table() |>
dplyr::bind_rows() |>
janitor::clean_names(case= 'snake') |>
rename(date= x3, ) |>
filter(week != 'Pre0' & week != 'Pre1' & week != 'Pre2' & week != 'Pre3' & week != 'Week' & date != 'Playoffs') |>
dplyr::filter(week != 'Week' & date != 'Playoffs') |>
dplyr::mutate(week= case_when(week == 'WildCard' ~ '19',
week == 'Division' ~ '20',
week == 'ConfChamp' ~ '21',
week == 'SuperBowl' ~ '22',
T ~ week),
week= as.numeric(week)) |>
dplyr::select(week, day, date, time, away= vis_tm, home= home_tm) |>
mutate(year= nfl_year) |>
dplyr::group_by(week) |>
dplyr::group_split() |>
purrr::map(dplyr::mutate, game_num= dplyr::row_number()) |>
dplyr::bind_rows() |>
tidyr::unite(col = 'game_time', date, year, time, sep= " ") |>
dplyr::mutate(game_time= lubridate::mdy_hm(game_time)) |>
tidyr::pivot_longer(cols= -c('week', 'day', 'game_time', 'game_num'), names_to = 'home_away', values_to = 'team') |>
dplyr::select(week, day, game_time, game_num, home_away, team) |>
dplyr::left_join(readr::read_csv('team_abbrev_match.csv'), by= 'team') |>
dplyr::rename(team_abbrev= abrev) |>
dplyr::select(week, day, game_time, game_num, team, team_abbrev, home_away)
rvest::read_html(nfl_year) |>
rvest::html_elements('table') |>
rvest::html_table() |>
dplyr::bind_rows() |>
janitor::clean_names(case= 'snake') |>
# rename(date= x3) |>
filter(week != 'Pre0' & week != 'Pre1' & week != 'Pre2' & week != 'Pre3' & week != 'Week' & date != 'Playoffs') |>
dplyr::filter(week != 'Week' & date != 'Playoffs') |>
dplyr::mutate(week= case_when(week == 'WildCard' ~ '19',
week == 'Division' ~ '20',
week == 'ConfChamp' ~ '21',
week == 'SuperBowl' ~ '22',
T ~ week),
week= as.numeric(week)) |>
dplyr::select(week, day, date, time, away= winner_tie, home= loser_tie) |>
mutate(year= season_year) |>
dplyr::group_by(week) |>
dplyr::group_split() |>
purrr::map(dplyr::mutate, game_num= dplyr::row_number()) |>
dplyr::bind_rows() |>
tidyr::unite(col = 'game_time', date, time, sep= " ") |>
dplyr::mutate(game_time= lubridate::ymd_hm(game_time)) |>
tidyr::pivot_longer(cols= -c('week', 'day', 'game_time', 'game_num', 'year'), names_to = 'home_away', values_to = 'team') |>
dplyr::select(week, day, game_time, game_num, home_away, team) |>
dplyr::left_join(readr::read_csv('team_abbrev_match.csv'), by= 'team') |>
dplyr::rename(team_abbrev= abrev) |>
dplyr::select(week, day, game_time, game_num, team, team_abbrev, home_away)
}

0 comments on commit 252fd37

Please sign in to comment.