Skip to content

Commit

Permalink
Add moves_summary()
Browse files Browse the repository at this point in the history
Progress towards #24
  • Loading branch information
k5cents committed Sep 13, 2021
1 parent 2d8a6eb commit 6423aad
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
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_name)
export(league_size)
export(league_teams)
export(moves_summary)
export(player_info)
export(pro_schedule)
export(roster_moves)
Expand Down
43 changes: 43 additions & 0 deletions R/transactions.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#' League transactions
#'
#' Summary of transactions and roster changes made during a season by team.
#'
#' @inheritParams ffl_api
#' @return A data frame of transaction counts by team.
#' @examples
#' moves_summary(leagueId = "42654852")
#' @importFrom tibble as_tibble
#' @export
moves_summary <- function(leagueId = ffl_id(), leagueHistory = FALSE, ...) {
dat <- ffl_api(leagueId, leagueHistory, view = "mTeam", ...)
if (leagueHistory) {
out <- rep(list(NA), length(dat$teams))
for (i in seq_along(dat$members)) {
out[[i]] <- out_trans(
teams = dat$teams[[i]],
y = dat$seasonId[i],
w = dat$scoringPeriodId[i]
)
}
} else {
out <- out_trans(
teams = dat$teams,
y = dat$seasonId,
w = dat$scoringPeriodId
)
}
return(out)
}

out_trans <- function(teams, y = NULL, w = NULL) {
teams$transactionCounter$matchupAcquisitionTotals <- NULL
x <- data.frame(
seasonId = y,
scoringPeriodId = w,
teamId = teams$id,
abbrev = factor(teams$abbrev, levels = teams$abbrev),
waiverRank = teams$waiverRank,
teams$transactionCounter
)
as_tibble(x)
}
27 changes: 27 additions & 0 deletions man/moves_summary.Rd

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

0 comments on commit 6423aad

Please # to comment.