Closed py9mrg closed 3 years ago
Hi there, thank you for this comment, and I agree with the conceptual idea. I will include this in the next package update, likely ahead of the new season in August. Or, if you are willing, you can submit a pull request with the functionality, then I will review and merge. Thanks again.
Hello, thanks for the reply. Have had a quick look at the code and this seems pretty easy depending how much functionality you want to make inherent to the package. For example, in player_functions.R
the function get_player_id
has the line(s):
elements <- jsonlite::fromJSON("https://fantasy.premierleague.com/api/bootstrap-static/")$elements
I'm completely new to JSON and the FPL API so I didn't realise that that returns the info for all players for the current GW. That then means that nrow(elements)
will return the total number of players - and this can then be used in my example above. e.g. something like:
# I haven't actually run this so may not work as is, but roughly this:
max_id <- nrow(jsonlite::fromJSON("https://fantasy.premierleague.com/api/bootstrap-static/")$elements)
purrr::map_dfr(1:max_id, get_player_details)
As an aside - I really don't understand what FPL are doing as their API is confusing to me. For example, elements
above contains completely different columns as get_player_details
(which uses $history not $elements from the FPL API) - I mean, why don't they just include all columns in both so elements and history match? Aaaaanyway.
But this is where the questions come of how you want to do this.
get_player_ids
which literally returns the ids (of max id) for the players (maybe a data.frame of name and id?). Obviously this can change during the transfer window(s).get_all_player_details
.get_player_details
function itself. Something like an all_players = TRUE
argument.
What do you think?We are now live for the 21-22 season and the function update includes a new function - get_player_ids() - which returns a data frame of all player ids and names. Should make things easier to combine datasets and work with the API data. Thanks for the suggestion!
Hello,
Thanks for this terrific package. One small feature request - a function that can make a list of all player ids (or names - but these aren't always unique - e.g. Ben Davies) for the current season.
get_player_details
works great if you have the id or name, as doesget_player_id
if you know the player name - so what would be great is something likeget_player_ids
that returns all the player ids (or at least the maximum one, given they're assigned sequentially per season). Then we can do something like:to automatically get the details for all players at once. Currently, if I want to do that, I have to do a binary search on the player id until I get the maximum id
get_player_details
will accept without throwing an error.