Skip to content

Commit

Permalink
background functionality to download 2021 games that have not been pl…
Browse files Browse the repository at this point in the history
…ayed yet within nba_travel()
  • Loading branch information
Jose Fernandez committed Dec 26, 2020
1 parent f4c9ec8 commit 7bb81e8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
14 changes: 7 additions & 7 deletions R/NBA_travel.R
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ nba_travel <- function(start_season = 2018,
matrix(ncol = length(col_names) - 2, byrow = TRUE)

month_df <- as.data.frame(cbind(game_id, dates, data), stringsAsFactors = FALSE) %>%
mutate(dates = lubridate::mdy(dates))
dplyr::mutate(dates = lubridate::mdy(dates))
names(month_df) <- col_names

month_h <- month_df %>% dplyr::select(Date = date_game, Team = home_team_name, Opponent = visitor_team_name) %>% dplyr::mutate(Location = "H")
Expand All @@ -165,11 +165,11 @@ nba_travel <- function(start_season = 2018,
feb <- future_games(year = 2021, month = "february")
mar <- future_games(year = 2021, month = "march")

future <- full_join(dec, jan, by = c("Date", "Team", "Opponent", "Location", "Season", "W/L", "Phase")) %>%
full_join(feb, by = c("Date", "Team", "Opponent", "Location", "Season", "W/L", "Phase")) %>%
full_join(mar, by = c("Date", "Team", "Opponent", "Location", "Season", "W/L", "Phase")) %>%
arrange(Team, Date) %>%
filter(Date >= Sys.Date())
future <- dplyr::full_join(dec, jan, by = c("Date", "Team", "Opponent", "Location", "Season", "W/L", "Phase")) %>%
dplyr::full_join(feb, by = c("Date", "Team", "Opponent", "Location", "Season", "W/L", "Phase")) %>%
dplyr::full_join(mar, by = c("Date", "Team", "Opponent", "Location", "Season", "W/L", "Phase")) %>%
dplyr::arrange(Team, Date) %>%
dplyr::filter(Date >= Sys.Date())

##

Expand Down Expand Up @@ -346,7 +346,7 @@ nba_travel <- function(start_season = 2018,
dplyr::mutate(`W/L` = ifelse(is.na(`W/L`), "-", `W/L`)) %>%
dplyr::filter(Phase %in% phase) %>%
dplyr::group_by(Season, Team) %>%
dplyr::mutate(Rem = ifelse(!is.na(lag(Date)) & lag(Date) == Date, "1", "")) %>%
dplyr::mutate(Rem = ifelse(!is.na(dplyr::lag(Date)) & dplyr::lag(Date) == Date, "1", "")) %>%
dplyr::filter(Rem != "1") %>% dplyr::select(-Rem)

if(missing(team)) return(final)
Expand Down
6 changes: 5 additions & 1 deletion R/global.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,8 @@ utils::globalVariables(c("%>%",
"urlPlayerStats",
"urlPlayerThumbnail",
"urlTeamSeasonLogo",
"yearSeason"))
"yearSeason",
"date_game",
"home_team_name",
"visitor_team_name",
"Rem"))

0 comments on commit 7bb81e8

Please sign in to comment.