Skip to content

Commit

Permalink
Add roster_moves()
Browse files Browse the repository at this point in the history
Progress towards #24
  • Loading branch information
k5cents committed Sep 13, 2021
1 parent f0b5790 commit 2d8a6eb
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export(league_size)
export(league_teams)
export(player_info)
export(pro_schedule)
export(roster_moves)
export(roster_settings)
export(schedule_settings)
export(score_settings)
Expand Down
46 changes: 46 additions & 0 deletions R/moves.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#' Roster moves
#'
#' The individual proposed and executed transactions, trades, and waiver moves.
#'
#' @inheritParams ffl_api
#' @return A data frame of transactions and roster moves.
#' @examples
#' roster_moves(leagueId = "42654852")
#' @export
roster_moves <- function(leagueId = ffl_id(), leagueHistory = FALSE, ...) {
dat <- ffl_api(
leagueId = leagueId,
leagueHistory = leagueHistory,
view = "mTransactions2",
...
)
if (leagueHistory) {
stop("not currently supported for past seasons")
} else {
t <- as_tibble(dat$transactions)
for (i in seq_along(t$items)) {
if (!is.null(t$items[[i]])) {
if (is.matrix(t$items[[i]])) {

}
t$items[[i]] <- cbind(id = t$id[i], t$items[[i]])
}
}
i <- do.call("rbind", t$items)[, -c(4, 5)]
i$fromLineupSlotId[i$fromLineupSlotId == -1L] <- NA_integer_
i$fromLineupSlotId <- slot_abbrev(i$fromLineupSlotId)
i$toLineupSlotId <- slot_abbrev(i$toLineupSlotId)
i$fromTeamId[i$fromTeamId == 0] <- NA_integer_
i$toLineupSlotId[i$toLineupSlotId == -1L] <- NA_integer_
i$toLineupSlotId[i$toLineupSlotId == 0] <- NA_integer_

t$seaonId <- dat$seasonId
t$bidAmount[t$bidAmount == 0] <- NA_integer_
t$proposedDate = ffl_date(t$proposedDate)
t <- t[, c(16, 10, 1, 11, 8, 12, 3)]

t <- merge(t, i, by = "id")
t$id <- substr(t$id, start = 1, stop = 8)
as_tibble(t)
}
}
27 changes: 27 additions & 0 deletions man/roster_moves.Rd

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

0 comments on commit 2d8a6eb

Please # to comment.