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.dbis 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.dbis the database object and leagueID is the league number from the Fantasy Premierleague site. ifstatsorleagueare true then the stats and league tables are updated. Data are downloaded from the Fantasy Premierleague site by setting values for theweeksvariable or settingallto 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 weeksweeksfpl_league(f, max_week = 0, out_type = 'total')Return the league table (cumulative) for up tomax_week. The output can be total tomax_weekor cumulativesquad_by_week(f, week, teams)Return a manager's squad for a specific week.teamsis 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_weekand project outnumber_weeksto 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 isNULLthen return the most current table. -
getLeagueEntries(leagueID, wk, fpl)Return the teams in a league table for a classic league (week specified).fplis the output returned bygetFPLData(). -
playerCount(l.teams, fpl)Return a data frame containing all players and their frequency in a particular league.fplis the output returned bygetFPLData().l.teamsis 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.fplis the output returned bygetFPLData(). IfmaxWeekis NULL then the current game week is assumed.