KYRIAKOS GEORGIOU

Engineer @Instacart

 

VIS: Fantasy Premier League

Few weeks ago the 2015/16 Premier League concluded. It was the first season that I managed to keep up with my Fantasy Premier League team all the way through the end.

Unfortunately I lost the 1st place in my private league by 4 points, literally in the last minute of the season due to Smalling's own goal against Bournemouth at 90' + 3'.

It was an exciting season for the Premier League and for my FPL league and I was eager to start building tools to enhance the FPL experience.

Data Science and Machine Learning are the two prominent topics that come to mind when thinking of ways to incorporate Computer Science skills with FPL.

In this article I'll demonstrate a simple, interactive, visualization from the data gathered from my private FPL League, The League of Sirs.

The legend on the top is clickable and it's useful for focusing on a specific team's progress and hovering over a data point displays its value.

On the technical side of things, below are the two main libraries I've used to build the above visualization - along with some sample code snippets.

1. Cheerio for scrapping the FPL website.

var cheerio = require('cheerio');

// Scrapping every player's info from the HTML table at
// fantasy.premierleague.com/my-leagues/92278/standings/

var players = [];

var $ = cheerio.load(html);

$('.ismTable.ismStandingsTable tr')
  .slice(1).each(function (i, row) {

    var playerId = '',
        teamName = '',
        playerName = '';

    $(this)
    .find('td').each(function (n, td) {

      if (n === 2) {
          playerId = $(this)
                    .find('a').attr('href').split("/")[2];
          teamName = $(this).find('a').text();
      } else if (n === 3) {
          playerName = $(this).text();
      }
    });

    players.push({
      entry: playerId,
      pname: playerName,
      tname: teamName
    });
});

2. Plottable.js for plotting the bump chart.

// Rendering plot as a table of components
var table = new Plottable.Components.Table([
  [null, title],
  [null, legend],
  [null, labelOp],
  [yAxisOp, opPlots],
  [null, xAxisOp],
  [null, labelTv],
  [yAxisTv, tvPlots],
  [null, xAxisTv]
]);

table.renderTo("svg#fpl-plot");

Shortcomings:

Finally, credit must be given where it is due. Congratulations to Leicester City FC for winning the Premier League and to Unpezable FC for winning the prestigious League of Sirs!