sportowe_wizualizacja/11tegen11 position map.ipynb

473 lines
97 KiB
Plaintext
Raw Normal View History

{
"cells": [
{
"cell_type": "code",
2020-11-09 12:59:20 +01:00
"execution_count": 6,
"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",
"home_team = 'Espanyol'\n",
"away_team = 'Barcelona'"
]
},
{
"cell_type": "code",
2020-11-09 12:59:20 +01:00
"execution_count": 12,
"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",
"from functools import reduce\n",
2020-11-09 12:59:20 +01:00
"from pandas.io.json import json_normalize\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",
2020-11-09 12:59:20 +01: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",
" \n",
2020-11-09 12:59:20 +01:00
" df = json_normalize(data, sep = \"_\")\n",
" \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",
"Xg_req = Xg_req.append(df,ignore_index=True,sort=False)\n",
" #df.drop(df.index, inplace=True)\n",
" \n",
"print(\"done\")\n",
"df = Xg_req"
]
},
{
"cell_type": "code",
2020-11-09 12:59:20 +01:00
"execution_count": 13,
"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",
2020-11-09 12:59:20 +01:00
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['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"
]
}
],
"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",
2020-11-09 12:59:20 +01:00
"execution_count": 15,
"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": {},
"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",
" <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",
" <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",
" </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",
" <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",
" <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",
" <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",
" <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",
" <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",
"\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",
"\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",
"\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",
"\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",
"\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",
"\n",
"[5 rows x 122 columns]"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pass_home.head()"
]
},
{
"cell_type": "code",
2020-11-09 12:59:20 +01:00
"execution_count": 33,
"metadata": {},
2020-05-18 09:20:28 +02:00
"outputs": [
{
"data": {
2020-11-09 12:59:20 +01:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAlIAAAGACAYAAABmwYzKAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8li6FKAAAgAElEQVR4nOzdd2BN5//A8fe5NzsySBDE3jGDkNgrxKjYq6jWHjWrJTFqharZorRq/gil9o49khCJvanYOwgSSe74/XG5FRmS+0Woz6t/1D33Oef5nMO9+eQ5z/M5il6vRwghhBBCpJ8qowMQQgghhPhUSSIlhBBCCGEiSaSEEEIIIUwkiZQQQgghhIkkkRJCCCGEMJEkUkIIIYQQJjJL7c2c7S3uANk/UCxCCCGEEB+lW8vileS2v21ESpIoIYQQQogUyK09IYQQQggTSSIlhBBCCGGiVOdIvenqb1cBCLkQ8l6CEUKI1+XLmg+AyPuRGRqHEOLzsi5sHYEHAtPUVkakhBAfLRtLG2wsbTI6DCHEZ8TN1Q1fD980t0/XiNSrkai209qmLyohhDDB8oHLAfnOEUJ8OK++d9JKRqSEEEIIIUwkiZQQQgghhIkkkRJCCCGEMJEkUkIIIYQQJpJESg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YSJJpIQQQgghTCSJlBBCCCGEiSSREkIIIYQwkSRSQgghhBAmkkRKCCGEEMJEkkgJIYQQQphIEikhhBBCCBOZpadxvqz5sLG0YfnA5e8rns/WurB1BB4IzOgwhBBCfCLaVW2Hr4dvRofxn+Pm6kZMXEya28uI1EfAzdVNPgxCCCH
2020-05-18 09:20:28 +02:00
"text/plain": [
"<Figure size 748.8x489.6 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"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",
2020-11-09 12:59:20 +01:00
"plt.axis('off')\n",
"\n",
"for player in players:\n",
" x_avg = 0\n",
" y_avg = 0\n",
" touches = 0\n",
" 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",
" touches+=1\n",
2020-05-18 09:20:28 +02:00
" \n",
" #https://math.stackexchange.com/questions/1013230/how-to-find-coordinates-of-reflected-point\n",
" 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",
" 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",
2020-11-09 12:59:20 +01:00
" plt.gca().invert_yaxis()\n",
" plt.annotate(\"\", xy=(25, 75), xytext=(5, 75),\n",
" arrowprops=dict(arrowstyle=\"->\", linewidth=2))\n",
" plt.text(7,73,'Attack',fontsize=20,color = 'white')\n",
"plt.show()"
]
},
{
"cell_type": "code",
2020-11-09 12:59:20 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wdAInqRAYv7MHUPvOxsrAmLiGWLj7NiHml96pjnR5M6jWbuPgYkjRJfP5TH31o8g3awbxBS1h/JPVpvWTbT2zgmx4zqfZFcQAiYyJYfWAZ+2cGce/Jbc7fOJ3RtyBNyWOkUCiIiongqyWDX9v++w2T2DXZn3tP7nDp7t/YWtmn27ZGqTo8CA/l4bNQ/bQT/xzlp89X4JzTBYCI6Odsn3QYO2sHvvx1QKplTFzxJT8NWcEnzYaw+9QW/fQtx9ay/Kst/DU1gIu3z3P1/qXMbroQ2Yoira7XZPm7W6SYuW6E7nx313ld325VQgiB7jNn9R+bsVu0mjnpf1Sl8qUCllZQYldG9VbqqlC4Mt/1mk27yRm/95MQwjSkl3VC1ySkeY8V6ZESQmRrNrY2PFIC6fQwpeWREhTmb6eeIa1H0bvRQIYs6vN2ViCEMCkSpIQQ2VpVzwp8BsTzmtN7L4kDdgBWLm9nCOiPO2bx445Zb2XZQgjTI4PNhRDZWkG3/JjlVLA+g+3/BMxzKjCzT/9O50IIkVUkSAkhsr9KSoaq4J83NAsBhqp07YUQ4l2QTxshRLZn6axEVVVJDRWsQHf67mVx6KZ7qUBVVYmls3y0CSHeDRkjJYQwCVZFVMTbKRhxTsOQ51paA3k1uoHlO/j3dF4lCVFCiHdLgpQQwmRYOiuhiRJVlJadDzVoE3VX51m5KGVMlBDCKCRICSFMjpm9AjP7t3OPKCGEyAzpAxdCCCGEMJAEKSGEEEIIA0mQEkIIIYQwkAQpIYQQQggDSZASQgghhDCQBCkhhBBCCANJkBJCCCGEMJAEKSGEEEIIA0mQEkIIIYQwkAQpIYQQQggDSZASQgghhDCQBCkhhBBCCANJkBJCCCGEMJAEKSGEEEI
"text/plain": [
2020-05-18 09:20:28 +02:00
"<Figure size 748.8x489.6 with 1 Axes>"
]
},
2020-05-18 09:20:28 +02:00
"metadata": {
"needs_background": "light"
},
"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",
2020-11-09 12:59:20 +01:00
"plt.axis('off')\n",
"for player in players:\n",
" x_avg = 0\n",
" y_avg = 0\n",
" touches = 0\n",
" 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",
" touches+=1\n",
" 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",
" 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",
2020-11-09 12:59:20 +01:00
" plt.annotate(\"\", xy=(25, 75), xytext=(5, 75),\n",
" arrowprops=dict(arrowstyle=\"->\", linewidth=2))\n",
" plt.text(7,73,'Attack',fontsize=20,color = 'white')\n",
" plt.gca().invert_yaxis()\n",
"\n",
"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-11-09 12:59:20 +01:00
"version": "3.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}