Graphing the Premier League
This article is a part of a series intended to show users how to use Memgraph on real-world data and, by doing so, retrieve some interesting and useful information.
We highly recommend checking out the other articles from this series which are listed in our tutorial overview section.
#
IntroductionFootball is a team sport played between two teams of eleven players with a spherical ball. The game is played on a rectangular pitch with a goal at each and. The object of the game is to score by moving the ball beyond the goal line into the opposing goal. The game is played by more than 250 million players in over 200 countries, making it the world's most popular sport.
In this article, we will present a graph model of a reasonably sized dataset of football matches across world's most popular leagues.
#
Data modelIn essence, we are trying to model a set of football matches. All information
about a single match is going to be contained in three nodes and two edges.
Two of the nodes will represent the teams that have played the match, while the
third node will represent the game itself. Both edges are directed from the
team nodes to the game node and are labeled as :Played
.
Every bit of information regarding the data model is nicely condensed in the following visual representation.
#
Exploring the datasetYou have two options for exploring this dataset.
If you just want to take a look at the dataset and try out a few queries, open
Memgraph Playground and continue with
the tutorial there. Note that you will not be able to execute write
operations.
On the other hand, if you would like to add changes to the dataset, download the
Memgraph Lab desktop application and navigate
to the Datasets
tab in the sidebar. From there, choose the dataset
Football Premier league games
and continue with the tutorial.
#
Example queries1) You might wonder, what leagues are supported?
2) We have stored a certain number of seasons for each league. What is the oldest/newest season we have included?
3) You have already seen one game between Chelsea and Arsenal, let's list all of them in chronological order.
4) How about filtering games in which Chelsea won?
5) Home field advantage is a thing in football. Let's list the number of home defeats for each Premier League team in the 2016/2017 season.
6) At the end of the season the team with the most points wins the league. For each victory, a team is awarded 3 points and for each draw it is awarded 1 point. Let's find out how many points did reigning champions (Chelsea) have at the end of 2016/2017 season.
7) In fact, why not retrieve the whole table?
8) People have always debated which of the major leagues is the most exciting. One basic metric is the average number of goals per game. Let's see the results at the end of the 2016/2017 season. WARNING: This might shock you.
9) Another metric might be the number of comebacks—games where one side was winning at half time but were overthrown by the other side by the end of the match. Let's count such occurrences during all supported seasons across all supported leagues.
10) Exciting leagues also tend to be very unpredictable. On that note, let's list all triplets of teams where, during the course of one season, team A won against team B, team B won against team C and team C won against team A.