A new series of functions designed to work with stored data for a specific league
Data are pulled back from the Fantasy Premierleague site and stored in a mysql database. Once available a number of functions can be applied to the data.
initialize_database(db, leagueID)
Initialize a mysql database for the league.db
is the database object.add_to_database(db, leagueID, stats=FALSE, league=FALSE, weeks=c(), all=FALSE, progressbar=FALSE)
Add data from Fantasy Premierleague site to the database.db
is the database object and leagueID is the league number from the Fantasy Premierleague site. ifstats
orleague
are true then the stats and league tables are updated. Data are downloaded from the Fantasy Premierleague site by setting values for theweeks
variable or settingall
to true for all weeks.fpl(db)
Return an fpl object from the database. The fpl object contains all tables for subsequent functions (assigned to f for the functions that follow)fpl_league_weekly(f, weeks)
Return weekly scores for weeksweeks
fpl_league(f, max_week = 0, out_type = 'total')
Return the league table (cumulative) for up tomax_week
. The output can be total tomax_week
or cumulativesquad_by_week(f, week, teams)
Return a manager's squad for a specific week.teams
is a list of identifiers which can be manager names, manager IDs or team namescaptainChoice(f, weeks, managers)
Determine if the best captain was chosen for a number of weeksplayedFormation(f, weeks, managers)
Return the formation played for a number of weeksbestFormation(f, weeks, managers)
Return the optimum formation for a number of weeksuse_chip(f, managers)
List chip usagesubstitutions(f, weeks, managers)
Return tables containing substitution informationsubstitution_analysis(f, start_week, number_weeks, managers)
Analyze substitutions - how advantageous were the substitutions? Take the substitutions applied in weekstart_week
and project outnumber_weeks
to determine the points differential between the added player and the dropped player.substitution_analysis_all(f, managers)
Analyze substitutions - how advantageous were the substitutions? This function assesses points differential from when a player was substituted in to when the same player was dropped (or to the maximum number of weeks if the player was not dropped).points_on_bench(f, weeks, managers)
Return tables of points left on the benchkeeperChoice(f, weeks, managers)
Assessment of keeper choice
Functions to assist scraping data from Fantasy Premierleague Site.
This repository contains a simple series of functions to aid in scraping data from the new format Fantasy Premierleague site.
-
getFPLData()
Return a list of 7 components containing all the juicy data (phases, elements, game-settings, total-players, teams, element_types and events). -
getEntry(entry)
Return entry details and historical information. -
getEvent(week)
Return data relating to a specific week. Output is a list with two elements (fixtures and elements). -
getTeam(entry, wk)
Get team data (week specified). -
getLeagueTable(leagueID, wk)
Return a league table for a classic league (week specified). If week isNULL
then return the most current table. -
getLeagueEntries(leagueID, wk, fpl)
Return the teams in a league table for a classic league (week specified).fpl
is the output returned bygetFPLData()
. -
playerCount(l.teams, fpl)
Return a data frame containing all players and their frequency in a particular league.fpl
is the output returned bygetFPLData()
.l.teams
is the list of teams returned bygetLeagueEntries(leagueID, wk, fpl)
. The resulting data frame can be effectively sliced and diced usingdplyr
, for example the following code returns all unselected midfielders ordered by total points:playerCount(l.teams, fpl) %>% filter(count == 0 & element_type == 'MID') %>% arrange(-total_points)
-
pointsFrame(fpl, maxWeek)
Return a data frame containing id, first name, second name points scored for all weeks up tomaxWeek
.fpl
is the output returned bygetFPLData()
. IfmaxWeek
is NULL then the current game week is assumed.