Skip to content

Commit

Permalink
Add league_status()
Browse files Browse the repository at this point in the history
Progress towards #24
  • Loading branch information
k5cents committed Sep 14, 2021
1 parent d3a9fbf commit 1223b3b
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 1 deletion.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export(league_members)
export(league_messages)
export(league_name)
export(league_size)
export(league_status)
export(league_teams)
export(moves_summary)
export(player_info)
Expand Down
42 changes: 42 additions & 0 deletions R/status.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#' League status
#'
#' Current information about a league: the date activated, current week,
#' starting week, final week, past seasons, teams joined, and waiver status.
#'
#' @inheritParams draft_picks
#' @return A data frame of league status by season.
#' @examples
#' league_status(leagueId = "42654852")
#' @importFrom tibble tibble
#' @export
league_status <- function(leagueId = ffl_id(), leagueHistory = FALSE, ...) {
dat <- ffl_api(leagueId, leagueHistory, view = "mStatus", ...)
if (leagueHistory) {
waiver_status <- rep(list(NA), nrow(dat$status$waiverProcessStatus))
for (i in seq(nrow(dat$status$waiverProcessStatus))) {
waiver_status[[i]] <- data.frame(
date = as.POSIXct(names(dat$status$waiverProcessStatus[i, ])),
status = unname(unlist(dat$status$waiverProcessStatus[i, ]))
)
}
} else {
waiver_status <- data.frame(
date = as.POSIXct(names(dat$status$waiverProcessStatus)),
status = unname(unlist(dat$status$waiverProcessStatus))
)
}
tibble::tibble(
year = dat$seasonId,
isActive = dat$status$isActive,
activatedDate = ffl_date(dat$status$activatedDate),
scoringPeriodId = dat$scoringPeriodId,
firstScoringPeriod = dat$status$firstScoringPeriod,
finalScoringPeriod = dat$status$finalScoringPeriod,
previousSeasons = list(dat$status$previousSeasons),
standingsUpdateDate = ffl_date(dat$status$standingsUpdateDate),
teamsJoined = dat$status$teamsJoined,
waiverLastExecutionDate = ffl_date(dat$status$waiverLastExecutionDate),
waiverNextExecutionDate = ffl_date(dat$status$waiverNextExecutionDate),
waiverProcessStatus = list_ifnot(waiver_status)
)
}
6 changes: 5 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
ffl_date <- function(date) {
as.POSIXct(date/1000, origin = "1970-01-01")
if (is.null(date)) {
as.POSIXct(NA_real_)
} else {
as.POSIXct(date/1000, origin = "1970-01-01")
}
}

as_tibble <- function(x) {
Expand Down
28 changes: 28 additions & 0 deletions man/league_status.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1223b3b

Please # to comment.