-
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.
Progress towards #24
- Loading branch information
Showing
3 changed files
with
76 additions
and
0 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
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), ] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.