Closed logan-888 closed 1 year ago
Nice find - and thank you for the reprex + proposed fix! Looks good, my only modifications are to extract the statSourceId first and then pass the index into the retrieval function.
... %>%
tidyr::hoist("player",
"eligible_lineup_slots" = "eligibleSlots",
"player_name" = "fullName",
"pos" = "defaultPositionId",
"team" = "proTeamId",
"stats" = "stats"
) %>%
dplyr::mutate(
which_source_is_projection = purrr::map(
.data$stats,
# projections are statSourceId == 1
# per <https://github.com/ffverse/ffscrapr/issues/397>
~ which(purrr::map(.x, "statSourceId") == 1)
),
projected_score = purrr::map2_dbl(
.data$stats,
.data$which_source_is_projection,
~ {if(length(.y)==0) return(NA_real_) else purrr::pluck(.x, .y, "appliedTotal", .default = NA_real_)}),
player = NULL,
stats = NULL,
which_source_is_projection = NULL
)
If you reinstall from github, this should now be resolved - feel free to reopen/open a new issue otherwise!
Describe the bug In ff_starters(), for espn leagues the projected player score is the same as the actual player score about 23% of the time due to the assumption "assume stats list col returns actual as first list and projected as second" written in the .espn_week_starter function in espn_starters.R
Funnily enough, you predicted this being an issue when it was first implemented https://github.com/ffverse/ffscrapr/issues/323#issuecomment-902679640
Reprex
Expected behavior The projected score to be correct, such as below
Session information
Screenshots
Current code that causes the issue:![current_error](https://github.com/ffverse/ffscrapr/assets/128932728/917462f0-67ab-4489-ba16-ce69dd8304b9)
Additional context
My current solution to the issue: