-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Export NFL schedule data and functions
- Loading branch information
Showing
7 changed files
with
108 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#' Professional schedule | ||
#' | ||
#' The opponents each team faces every week in a regular season. | ||
#' | ||
#' @param seasonId Season schedule (2004-present), defaults to [ffl_year()]. | ||
#' @return Data frame of team opponents by week. | ||
#' @examples | ||
#' pro_schedule(seasonId = ffl_year(-2)) | ||
#' @importFrom tibble tibble | ||
#' @export | ||
pro_schedule <- function(seasonId = ffl_year()) { | ||
dat <- try_json( | ||
url = sprintf("https://fantasy.espn.com/apis/v3/games/ffl/seasons/%i", seasonId), | ||
query = list(view = "proTeamSchedules_wl") | ||
) | ||
p <- dat$settings$proTeams$proGamesByScoringPeriod | ||
tm <- data.frame( | ||
stringsAsFactors = FALSE, | ||
team = dat$settings$proTeams$id, | ||
abbrev = dat$settings$proTeams$abbrev | ||
) | ||
sched <- rep(list(NA), length(p)) | ||
for (i in seq_along(p)) { | ||
x <- unique(do.call("rbind", p[[i]])) | ||
x <- data.frame( | ||
seasonId = as.integer(seasonId), | ||
scoringPeriodId = unique(x$scoringPeriodId), | ||
proTeam = pro_abbrev(c(x$homeProTeamId, x$awayProTeamId)), | ||
opponent = pro_abbrev(c(x$awayProTeamId, x$homeProTeamId)), | ||
isHome = c(rep(TRUE, nrow(x)), rep(FALSE, nrow(x))), | ||
date = ffl_date(rep(x$date, 2)) | ||
) | ||
sched[[i]] <- x[order(x$proTeam), ] | ||
} | ||
sched <- do.call("rbind", sched) | ||
as_tibble(sched) | ||
} |
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.