Skip to content

Commit

Permalink
Add player_acquire()
Browse files Browse the repository at this point in the history
Progress towards #24
  • Loading branch information
k5cents committed Sep 14, 2021
1 parent 7c13297 commit a3fda1c
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export(league_status)
export(league_teams)
export(live_scoring)
export(moves_summary)
export(player_acquire)
export(player_info)
export(player_news)
export(player_outlook)
Expand Down
48 changes: 48 additions & 0 deletions R/acquire.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#' Roster acquisition history
#'
#' The date and method of each player's acquisition onto a fantasy roster.
#'
#' @inheritParams draft_picks
#' @return A data frame of roster players with acquisition method and date.
#' @examples
#' player_acquire(leagueId = "42654852")
#' @importFrom tibble tibble
#' @export
player_acquire <- function(leagueId = ffl_id(), leagueHistory = FALSE, ...) {
dat <- ffl_api(leagueId, leagueHistory, view = c("mRoster", "mTeam"), ...)
if (leagueHistory | length(list(...) > 0)) {
stop("Acqusition data is only available for current season and period")
}
tm <- out_team(dat$teams)
e <- dat$teams$roster$entries
out <- rep(list(NA), length(e))
names(out) <- tm$abbrev
for (i in seq_along(e)) {
out[[i]] <- parse_acquire(
entry = e[[i]],
t = tm,
y = dat$seasonId,
w = dat$scoringPeriodId
)
out[[i]]$onTeamId <- tm$abbrev[i]
}
return(out)
}

parse_acquire <- function(entry, t, y, w) {
player <- entry$playerPoolEntry$player
x <- tibble::tibble(
seasonId = y,
scoringPeriodId = w,
onTeamId = entry$playerPoolEntry$onTeamId,
lineupSlotId = slot_abbrev(entry$lineupSlotId),
id = player$id,
firstName = player$firstName,
lastName = player$lastName,
proTeamId = pro_abbrev(player$proTeamId),
defaultPositionId = pos_abbrev(player$defaultPositionId),
acquisitionType = entry$acquisitionType,
acquisitionDate = ffl_date(entry$acquisitionDate)
)
x[order(x$lineupSlotId), ]
}
27 changes: 27 additions & 0 deletions man/player_acquire.Rd

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

0 comments on commit a3fda1c

Please # to comment.