valentinumbach / SoFIFA

SoFIFA API for R
MIT License
9 stars 3 forks source link

Fix scraping for player attributes #3

Open FranciscoDA opened 5 years ago

FranciscoDA commented 5 years ago

Updates the get_scores to work with the updated SoFIFA site Also retrieves: player_name, fifa_version, date Also adds other player scores: Preferred Foot, International_Reputation, Weak Foot and Body Type. Merging #4 as well would be ideal to ensure consistent results.

Added player historic data using get_player_history(player_ids), which will return a data.frame like so:

version exportdate date player_id
15 123456 16-08-2015 5
16 321456 13-05-2016 7

The user can filter using the $date and $player_ids fields. The $version and $exportdate fields are used to get the player scores like so:

get_player_history(2)     %$%
  .[date < '2010-01-01',] %$%
  get_player_scores(player_id, version, exportdate)

Progress messages now use message instead of cat (can be suppressed with suppressMessages())

Removed the max_results option as I think it can be made redundant. I suggest that users limit the amount of scraped pages by limiting the amount of ids requested in the first place:

get_leagues()                 %>% head(MAX_LEAGUES) %$%
  get_league_teams(league_id) %>% head(MAX_TEAMS)   %$%
  get_team_players(team_id)   %>% head(MAX_PLAYERS) %$%
  get_player_scores(player_id)

This has the added benefit of letting users choose whatever sampling method they want (head, tail, sample, etc.)