Blog of Random Thoughts and Pictures

Handling StatsBomb Event Data

February 7th, 2021

Yes I did have a blog post back in September 2020, highlighting that I was undertaking the Uppsala University course “Mathematical Modelling of Football” which overtook my time and life in Q4 2020. In completing the course I’m finally getting my head up in 2021 to record all my notes and code and to take a journey to share those notes as I go down through each section and sub-section of the course.

So here’s the first of hopefully many notes from the course, which were originally written in Asciidoc.

 

Purpose of Handling Event Data

The first element to work on via this course is Handling Event Data and the purpose is to learn how to :-

  • Download code and data
  • Organise working folder
  • Load in data from a json file.
  • Using ‘for’ loops and ‘if’ statements
  • Identify specific matches in Statsbomb data

The code needed for this lecture is available at the Github SoccermaticsForPython repo.

Set up

Created a new organisation on Github called mmoffoot standing for Mathematical Modelling of Football. The purpose is to fork the Github projects used in the course to track my own changes to those repos.

First up is a fork of the SoccermaticsForPython repo into the mmoffoot area.

Then created a branch called ‘week1’ covering the changes I had made as of week1 of the course.

The next little hurdle here is the loading of the Statsbomb data. It’s really in another repo on Github called statsbomb / open-data and in order to always have access to the StatsBomb data within this repo was going to set up a git submodule for this repo. This means that any time in the future when this repo is cloned (new) then it has to be done with the recursive command switch.

However then I noted that the StatsBomb data is over 3Gb in size and that it doesn’t really make sense have a couple of copies of this data on the one machine so I just placed it in a directory higher.I then just add a soft link to the source data within the ‘Statsbomb’ folder.

ln -s ../../statsbomb-opendata/data .

Also modified the README file to point this out.

What was coded

The first exercise is to

  1. Edit the code to print out the result list for the Mens World cup
  2. Edit the code to find the ID for England vs. Sweden
  3. Write new code to write out a list of just Sweden’s results in the tournament.

I made the code changes to 1LoadInData.py and run the code as

python3 1LoadInData.py

The output reads

The match between Croatia and Denmark finished 1 : 1
The match between Australia and Peru finished 0 : 2
.........
.........
The match between Spain and Russia finished 1 : 1
The match between Croatia and England finished 2 : 1
The Sweden match between Mexico and Sweden finished 0 : 3
The Sweden match between Sweden and South Korea finished 1 : 0
The Sweden match between Sweden and Switzerland finished 1 : 0
Sweden vs England has id:8651
The Sweden match between Sweden and England finished 0 : 2
The Sweden match between Germany and Sweden finished 2 : 1

I think the exercise is complete.

What was learned

Learning how to extract match results from the StatsBomb open data is important, and being able to read in the StatsBomb open data is great because at the time of writing it has a number of competitions covered in it.

  • International Mens FIFA World Cup 2018 (competition_id=43)
  • Europe Champions League 2018/2019
  • Europe Champions League 2017/2018
  • Europe Champions League 2016/2017
  • Europe Champions League 2015/2016
  • Europe Champions League 2014/2015
  • Europe Champions League 2013/2014
  • Europe Champions League 2012/2013
  • Europe Champions League 2011/2012
  • Europe Champions League 2010/2011
  • Europe Champions League 2009/2010
  • Europe Champions League 2008/2009
  • Europe Champions League 2006/2007
  • Europe Champions League 2004/2005
  • Europe Champions League 2003/2004
  • Europe Champions League 1999/2000
  • Spain La Liga 2018/2019
  • Spain La Liga 2017/2018
  • Spain La Liga 2016/2017
  • Spain La Liga 2015/2016
  • Spain La Liga 2014/2015
  • Spain La Liga 2013/2014
  • Spain La Liga 2012/2013
  • Spain La Liga 2011/2012
  • Spain La Liga 2010/2011
  • Spain La Liga 2009/2010
  • Spain La Liga 2008/2009
  • Spain La Liga 2007/2008
  • Spain La Liga 2006/2007
  • Spain La Liga 2005/2006
  • Spain La Liga 2004/2005
  • England Premier League 2003/2004
  • International Women’s World Cup 2019 (competition_id=72)
  • United States of America NWSL (Female) 2018
  • England FA Women’s Super League 2019/2020
  • England FA Women’s Super League 2018/2019