2019-06-19 06:45:57 +02:00
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"#edit only this tab\n",
"#give the folder path of the match\n",
2020-05-18 09:20:28 +02:00
"path = \"/home/kirugulige/Documents/Football-Analytics/open-data-master/data/events/\"\n",
2019-07-26 17:44:28 +02:00
"home_team = 'Espanyol'\n",
"away_team = 'Barcelona'"
2019-06-19 06:45:57 +02:00
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"done\n"
]
}
],
"source": [
"import json\n",
"import os\n",
"import codecs\n",
"import numpy as np\n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"from matplotlib.patches import Arc, Rectangle, ConnectionPatch\n",
"from matplotlib.offsetbox import OffsetImage\n",
2020-05-18 09:20:28 +02:00
"import StatsbombPitch as sb\n",
2019-06-19 06:45:57 +02:00
"from functools import reduce\n",
"\n",
"Xg_req = pd.DataFrame(data=None)\n",
2020-05-18 09:20:28 +02:00
"\n",
"filename = '69275.json' # remove the comment line to work for this match\n",
2019-07-26 17:44:28 +02:00
"with codecs.open(\"%s\" % path + filename,encoding='utf-8') as data_file: \n",
" data = json.load(data_file)\n",
" df = pd.DataFrame(data=None)\n",
2019-06-19 06:45:57 +02:00
" \n",
2020-05-18 09:20:28 +02:00
" df = pd.json_normalize(data, sep = \"_\")\n",
2019-06-19 06:45:57 +02:00
" \n",
" #df = df[(df['type_name'] == \"Shot\")]\n",
" #df = df.loc[:,['location','shot_body_part_id','shot_end_location','shot_one_on_one','shot_technique_id','shot_type_id','under_pressure','shot_outcome_id']]\n",
" #print(df.shape)\n",
2019-07-26 17:44:28 +02:00
"Xg_req = Xg_req.append(df,ignore_index=True,sort=False)\n",
2019-06-19 06:45:57 +02:00
" #df.drop(df.index, inplace=True)\n",
" \n",
"print(\"done\")\n",
"df = Xg_req"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"#type_id=30 is pass event AND type_id=19 is substitution event\n",
"\n",
"pass_m = df.query('type_id == 30')\n",
"substitution = df.query('type_id == 19')\n",
"#pass_m = df.query('type_name == pass')\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2019-07-26 17:44:28 +02:00
"['Javier Alejandro Mascherano' 'Seydou Kéita' 'Bojan Krkíc Pérez']\n",
"['Jesús Alberto Dátolo' 'Jordi Amat Maas' 'David García De La Cruz']\n"
2019-06-19 06:45:57 +02:00
]
}
],
"source": [
"#this cell is WIP\n",
"substitution_home = set()\n",
"substitution_home = substitution[substitution.team_name == home_team]\n",
"substitution_home = substitution_home['substitution_replacement_name'].unique()\n",
"substitution_away = set()\n",
"substitution_away = substitution[substitution.team_name == away_team]\n",
"substitution_away = substitution_away['substitution_replacement_name'].unique()\n",
"print(substitution_away)\n",
"print(substitution_home)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"# to get \n",
"\n",
"home_player = pass_m[(pass_m.team_name == home_team)] \n",
"home_team_list = set()\n",
"home_team_list = home_player['player_name'].unique()\n",
"#print(substitution_belgium)\n",
"#belgium_list = [player for player in belgium_list if player not in substitution_belgium]\n",
"#belgium_list.remove([x for x in substitution_belgium])#belgium_list - substitution_belgium\n",
"home_player =pass_m['player_name'].isin(home_team_list)\n",
"pass_home = pass_m[home_player] #contains 11 players of home team\n",
"\n",
"away_player = pass_m[(pass_m.team_name == away_team)] \n",
"away_list = away_player['player_name'].unique()\n",
"#away_list = away_list - substitution_brazil\n",
"away_player = pass_m['player_name'].isin(away_list)\n",
"pass_away = pass_m[away_player]"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
2019-07-26 17:44:28 +02:00
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
2020-05-18 09:20:28 +02:00
" <th>id</th>\n",
" <th>index</th>\n",
" <th>period</th>\n",
2019-07-26 17:44:28 +02:00
" <th>timestamp</th>\n",
2020-05-18 09:20:28 +02:00
" <th>minute</th>\n",
" <th>second</th>\n",
" <th>possession</th>\n",
" <th>duration</th>\n",
2019-07-26 17:44:28 +02:00
" <th>type_id</th>\n",
" <th>type_name</th>\n",
2020-05-18 09:20:28 +02:00
" <th>...</th>\n",
" <th>pass_cut_back</th>\n",
" <th>substitution_outcome_id</th>\n",
" <th>substitution_outcome_name</th>\n",
" <th>substitution_replacement_id</th>\n",
" <th>substitution_replacement_name</th>\n",
" <th>injury_stoppage_in_chain</th>\n",
" <th>foul_committed_offensive</th>\n",
" <th>pass_deflected</th>\n",
" <th>block_deflection</th>\n",
" <th>goalkeeper_punched_out</th>\n",
2019-07-26 17:44:28 +02:00
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>4</th>\n",
2020-05-18 09:20:28 +02:00
" <td>d6406089-778b-49e0-a70a-ade4788cf911</td>\n",
" <td>5</td>\n",
" <td>1</td>\n",
" <td>00:00:00.738</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>2</td>\n",
" <td>0.606100</td>\n",
" <td>30</td>\n",
" <td>Pass</td>\n",
" <td>...</td>\n",
2019-07-26 17:44:28 +02:00
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
2020-05-18 09:20:28 +02:00
" <td>73d8e43f-8e84-4b5d-88cc-9423278134d5</td>\n",
" <td>9</td>\n",
" <td>1</td>\n",
" <td>00:00:02.511</td>\n",
" <td>0</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>1.776163</td>\n",
" <td>30</td>\n",
" <td>Pass</td>\n",
" <td>...</td>\n",
2019-07-26 17:44:28 +02:00
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>16</th>\n",
2020-05-18 09:20:28 +02:00
" <td>8e47d35d-ab38-4419-a991-efe7105dec56</td>\n",
" <td>17</td>\n",
" <td>1</td>\n",
" <td>00:00:09.581</td>\n",
" <td>0</td>\n",
" <td>9</td>\n",
" <td>2</td>\n",
" <td>1.242900</td>\n",
" <td>30</td>\n",
" <td>Pass</td>\n",
" <td>...</td>\n",
2019-07-26 17:44:28 +02:00
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>20</th>\n",
2020-05-18 09:20:28 +02:00
" <td>a449bfa2-7bd9-4f94-8e13-595620c9bcee</td>\n",
" <td>21</td>\n",
" <td>1</td>\n",
" <td>00:00:18.784</td>\n",
" <td>0</td>\n",
" <td>18</td>\n",
" <td>3</td>\n",
" <td>1.298500</td>\n",
" <td>30</td>\n",
" <td>Pass</td>\n",
" <td>...</td>\n",
2019-07-26 17:44:28 +02:00
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>24</th>\n",
2020-05-18 09:20:28 +02:00
" <td>77f45a53-2eab-4ee5-bfbd-ad39d20a36cb</td>\n",
" <td>25</td>\n",
" <td>1</td>\n",
" <td>00:00:20.122</td>\n",
" <td>0</td>\n",
" <td>20</td>\n",
" <td>3</td>\n",
" <td>0.950262</td>\n",
" <td>30</td>\n",
" <td>Pass</td>\n",
" <td>...</td>\n",
2019-07-26 17:44:28 +02:00
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>5 rows × 122 columns</p>\n",
"</div>"
],
"text/plain": [
2020-05-18 09:20:28 +02:00
" id index period timestamp minute \\\n",
"4 d6406089-778b-49e0-a70a-ade4788cf911 5 1 00:00:00.738 0 \n",
"8 73d8e43f-8e84-4b5d-88cc-9423278134d5 9 1 00:00:02.511 0 \n",
"16 8e47d35d-ab38-4419-a991-efe7105dec56 17 1 00:00:09.581 0 \n",
"20 a449bfa2-7bd9-4f94-8e13-595620c9bcee 21 1 00:00:18.784 0 \n",
"24 77f45a53-2eab-4ee5-bfbd-ad39d20a36cb 25 1 00:00:20.122 0 \n",
2019-07-26 17:44:28 +02:00
"\n",
2020-05-18 09:20:28 +02:00
" second possession duration type_id type_name ... pass_cut_back \\\n",
"4 0 2 0.606100 30 Pass ... NaN \n",
"8 2 2 1.776163 30 Pass ... NaN \n",
"16 9 2 1.242900 30 Pass ... NaN \n",
"20 18 3 1.298500 30 Pass ... NaN \n",
"24 20 3 0.950262 30 Pass ... NaN \n",
2019-07-26 17:44:28 +02:00
"\n",
2020-05-18 09:20:28 +02:00
" substitution_outcome_id substitution_outcome_name \\\n",
"4 NaN NaN \n",
"8 NaN NaN \n",
"16 NaN NaN \n",
"20 NaN NaN \n",
"24 NaN NaN \n",
2019-07-26 17:44:28 +02:00
"\n",
2020-05-18 09:20:28 +02:00
" substitution_replacement_id substitution_replacement_name \\\n",
"4 NaN NaN \n",
"8 NaN NaN \n",
"16 NaN NaN \n",
"20 NaN NaN \n",
"24 NaN NaN \n",
2019-07-26 17:44:28 +02:00
"\n",
2020-05-18 09:20:28 +02:00
" injury_stoppage_in_chain foul_committed_offensive pass_deflected \\\n",
"4 NaN NaN NaN \n",
"8 NaN NaN NaN \n",
"16 NaN NaN NaN \n",
"20 NaN NaN NaN \n",
"24 NaN NaN NaN \n",
2019-07-26 17:44:28 +02:00
"\n",
2020-05-18 09:20:28 +02:00
" block_deflection goalkeeper_punched_out \n",
"4 NaN NaN \n",
"8 NaN NaN \n",
"16 NaN NaN \n",
"20 NaN NaN \n",
"24 NaN NaN \n",
2019-07-26 17:44:28 +02:00
"\n",
"[5 rows x 122 columns]"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
2019-06-19 06:45:57 +02:00
"source": [
2019-07-26 17:44:28 +02:00
"pass_home.head()"
2019-06-19 06:45:57 +02:00
]
},
2019-07-26 17:44:28 +02:00
{
"cell_type": "code",
2020-05-18 09:20:28 +02:00
"execution_count": 14,
2019-06-19 06:45:57 +02:00
"metadata": {},
2020-05-18 09:20:28 +02:00
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAmsAAAGUCAYAAABqYGW1AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAIABJREFUeJzs3Xd8TecfwPHPuTc7kpBBSNQejZWQIFZrhJhB7VarZlta60djVxWhWrQ2VaqEUiVqxp6JEHtX7b0iQSS5957fH4lUy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rgUn7FdV1Tuz9chjUCFEjjDLDY/MIfWh+P/ZQWI5s9w5EZUQQpg+SdaEEDlCURQUDw09tfAojTKPgF5aUDw0yTsYCCHE206SNSFEjrEuoeFyAYWqWthO4iNPkv7eBlTVwmU3BesS8tEkhBBPyAQDIUSOURQFy+paLp4x0Oy4AesEcFXgupr46FPx0GBdQnrVhBDiaZKsCSFylKIo2JTUopbQoIuCi/EqGgsFm9xIkiaEEKmQZE0IYRSKomCeB9KfGyqEECLDgSGKosxVFOWmoihHnzrmqChKqKIoZ5L+zvNqwxRCCCGEeDtlZhTvPMD/mWOBwCZVVUsAm5JeCyGEEEKIbJZhsqaq6nbg7jOHA4D5SV/PB5pnc1xCCCGEEIIXX7ojn6qq15K+vg7ky6Z4hBBCCCHEU156goGqqqqiKGnuWaUoSnegO4DW5mVbE0IIIYR4u7xoz9oNRVHyAyT9fTOtgqqqzlJV1VtVVW+Nlcz6EkIIIYTIihdN1kKAT5K+/gRYmT3hCCGEEEKIp2Vm6Y5gYA9QSlGUy4qidAGCAD9FUc4A9ZJ
"text/plain": [
"<Figure size 748.8x489.6 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
2019-06-19 06:45:57 +02:00
"source": [
"players = home_team_list\n",
2020-05-18 09:20:28 +02:00
"#fig=plt.figure() #set up the figures\n",
"sb.sb_pitch(\"#195905\",\"#faf0e6\",\"horizontal\",\"full\")\n",
"plt.axis('on')\n",
"plt.gca().invert_yaxis()\n",
2019-06-19 06:45:57 +02:00
"for player in players:\n",
" x_avg = 0\n",
" y_avg = 0\n",
2019-07-26 17:44:28 +02:00
" touches = 0\n",
2019-06-19 06:45:57 +02:00
" if player not in substitution_home: \n",
" play_temp = pass_home[(pass_home.player_name == player)]\n",
" #print(play_temp.location, players[player])\n",
" for i in range(len(play_temp)):\n",
2019-07-26 17:44:28 +02:00
" touches+=1\n",
2020-05-18 09:20:28 +02:00
" \n",
2019-07-26 17:44:28 +02:00
" #https://math.stackexchange.com/questions/1013230/how-to-find-coordinates-of-reflected-point\n",
2019-06-19 06:45:57 +02:00
" x_avg = x_avg + play_temp.iloc[i]['location'][0]\n",
2020-05-18 09:20:28 +02:00
" y_avg = y_avg + play_temp.iloc[i]['location'][1]\n",
2019-06-19 06:45:57 +02:00
" x_avg = x_avg/len(play_temp)\n",
" y_avg = y_avg/len(play_temp)\n",
" #print(x_avg,y_avg,players[player])\n",
2020-05-18 09:20:28 +02:00
" plt.scatter(x_avg, y_avg, s= (3 *touches ),color=\"red\",edgecolors=\"black\",zorder = 15) \n",
" plt.annotate(player, (x_avg, y_avg),zorder = 20,color = 'white')\n",
2019-06-19 06:45:57 +02:00
"plt.show()"
]
},
{
"cell_type": "code",
2020-05-18 09:20:28 +02:00
"execution_count": 13,
2019-06-19 06:45:57 +02:00
"metadata": {},
"outputs": [
{
"data": {
2020-05-18 09:20:28 +02:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAmsAAAGUCAYAAABqYGW1AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAIABJREFUeJzs3XVcVfcbwPHPuZdGQFEUG7s7sNthd7upm7nZ09kx50R0zticPX9zbna3InYhiM7ubixA+t57fn9cvMIkFeVOn/dee8k98T3POZcLD99UVFVFCCGEEEKYJ01aByCEEEIIIRImyZoQQgghhBmTZE0IIYQQwoxJsiaEEEIIYcYkWRNCCCGEMGOSrAkhhBBCmDFJ1oQQQgghzJgka0IIIYQQZkySNSGEEEIIM2bxQS9mq1E1dh/yikIIIYQQ5iX6mfpEVVWX5B6frGRNUZTBQA9ABc4AXwJZgRVARuAE8IWqqlGJlaOxg0weHzQ/FEIIIYQwKw+WR99KyfFJNoMqipIdGACUV1W1OKAFOgBTgBmqquYHngPdUx6uEEIIIYRITHL7rFkAtoqiWAB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mvShAFwBftcYzxNCiORKSc1aQyBAVdVXE9M8UhQlK0DMv4/jO0lV1QWqqpZXVbW8xkb+khRCfDwsHBQsy2iooU06YbsK1NSCZRkNFg7ys1AIkXwpSdY68roJFGAT0DXm667AxjfOEEKIj5xtAS3hZTSU1sJA5c0+bNcwbi+thfAyGmwLSK2aECJlkjWxj6Io9kB9oHeszV7AKkVRugO3gHapH54QQpg/2wJaLF01LLmsZ+F1FRfAQYEQ1TiYwDq
2019-06-19 06:45:57 +02:00
"text/plain": [
2020-05-18 09:20:28 +02:00
"<Figure size 748.8x489.6 with 1 Axes>"
2019-06-19 06:45:57 +02:00
]
},
2020-05-18 09:20:28 +02:00
"metadata": {
"needs_background": "light"
},
2019-06-19 06:45:57 +02:00
"output_type": "display_data"
}
],
"source": [
"players = away_list #['Alisson Ramsés Becker','Fágner Conserva Lemos','Fernando Luiz Rosa','Gabriel Fernando de Jesus','João Miranda de Souza Filho','José Paulo Bezzera Maciel Júnior','Marcelo Vieira da Silva Júnior','Neymar da Silva Santos Junior','Philippe Coutinho Correia','Thiago Emiliano da Silva','Willian Borges da Silva']\n",
2020-05-18 09:20:28 +02:00
"sb.sb_pitch(\"#195905\",\"#faf0e6\",\"horizontal\",\"full\")\n",
"plt.axis('on')\n",
2019-06-19 06:45:57 +02:00
"for player in players:\n",
" x_avg = 0\n",
" y_avg = 0\n",
2019-07-26 17:44:28 +02:00
" touches = 0\n",
2019-06-19 06:45:57 +02:00
" if player not in substitution_away:\n",
" #print(players[player])\n",
" play_temp = pass_away[(pass_away.player_name == player)]\n",
" #print(play_temp.location, players[player])\n",
" for i in range(len(play_temp)):\n",
2019-07-26 17:44:28 +02:00
" touches+=1\n",
2019-06-19 06:45:57 +02:00
" x_avg = x_avg + play_temp.iloc[i]['location'][0]\n",
2020-05-18 09:20:28 +02:00
" y_avg = y_avg + play_temp.iloc[i]['location'][1]\n",
2019-06-19 06:45:57 +02:00
" x_avg = x_avg/len(play_temp)\n",
" y_avg = y_avg/len(play_temp)\n",
" #print(x_avg,y_avg,players[player])\n",
2020-05-18 09:20:28 +02:00
" plt.scatter(x_avg, y_avg, s= (3 *touches ),color=\"red\",edgecolors=\"black\",zorder = 15) \n",
" plt.annotate(player, (x_avg, y_avg),zorder = 20,color = 'white')\n",
2019-06-19 06:45:57 +02:00
"plt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
2020-05-18 09:20:28 +02:00
"version": "3.6.9"
2019-06-19 06:45:57 +02:00
}
},
"nbformat": 4,
"nbformat_minor": 2
}