sportowe_wizualizacja/11tegen11 position map.ipynb

509 lines
54 KiB
Plaintext
Raw Normal View History

{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"#edit only this tab\n",
"#give the folder path of the match\n",
"path = \"\"\"C:\\\\Users\\\\koushik.r\\\\Documents\\\\open-data-master\\\\data\\\\events\\\\\"\"\"\n",
"home_team = 'Espanyol'\n",
"away_team = 'Barcelona'"
]
},
{
"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",
"from pandas.io.json import json_normalize\n",
"import numpy as np\n",
"#import seaborn as sns\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",
"#import squarify\n",
"from functools import reduce\n",
"\n",
"Xg_req = pd.DataFrame(data=None)\n",
"for filename in (os.listdir(path)):\n",
" #print(filename)\n",
"#filename = '69275.json' # remove the comment line to work for this match\n",
"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",
" 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",
"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": [
"['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",
"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": {},
"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",
" <th>50_50_outcome_id</th>\n",
" <th>50_50_outcome_name</th>\n",
" <th>bad_behaviour_card_id</th>\n",
" <th>bad_behaviour_card_name</th>\n",
" <th>ball_receipt_outcome_id</th>\n",
" <th>ball_receipt_outcome_name</th>\n",
" <th>ball_recovery_recovery_failure</th>\n",
" <th>block_deflection</th>\n",
" <th>block_offensive</th>\n",
" <th>carry_end_location</th>\n",
" <th>...</th>\n",
" <th>substitution_replacement_id</th>\n",
" <th>substitution_replacement_name</th>\n",
" <th>tactics_formation</th>\n",
" <th>tactics_lineup</th>\n",
" <th>team_id</th>\n",
" <th>team_name</th>\n",
" <th>timestamp</th>\n",
" <th>type_id</th>\n",
" <th>type_name</th>\n",
" <th>under_pressure</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>4</th>\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",
" <td>...</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>214</td>\n",
" <td>Espanyol</td>\n",
" <td>00:00:00.738</td>\n",
" <td>30</td>\n",
" <td>Pass</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\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",
" <td>...</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>214</td>\n",
" <td>Espanyol</td>\n",
" <td>00:00:02.511</td>\n",
" <td>30</td>\n",
" <td>Pass</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>16</th>\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",
" <td>...</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>214</td>\n",
" <td>Espanyol</td>\n",
" <td>00:00:09.581</td>\n",
" <td>30</td>\n",
" <td>Pass</td>\n",
" <td>True</td>\n",
" </tr>\n",
" <tr>\n",
" <th>20</th>\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",
" <td>...</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>214</td>\n",
" <td>Espanyol</td>\n",
" <td>00:00:18.784</td>\n",
" <td>30</td>\n",
" <td>Pass</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>24</th>\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",
" <td>...</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>214</td>\n",
" <td>Espanyol</td>\n",
" <td>00:00:20.122</td>\n",
" <td>30</td>\n",
" <td>Pass</td>\n",
" <td>True</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>5 rows × 122 columns</p>\n",
"</div>"
],
"text/plain": [
" 50_50_outcome_id 50_50_outcome_name bad_behaviour_card_id \\\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",
" bad_behaviour_card_name ball_receipt_outcome_id ball_receipt_outcome_name \\\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",
" ball_recovery_recovery_failure block_deflection block_offensive \\\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",
" carry_end_location ... substitution_replacement_id \\\n",
"4 NaN ... NaN \n",
"8 NaN ... NaN \n",
"16 NaN ... NaN \n",
"20 NaN ... NaN \n",
"24 NaN ... NaN \n",
"\n",
" substitution_replacement_name tactics_formation tactics_lineup team_id \\\n",
"4 NaN NaN NaN 214 \n",
"8 NaN NaN NaN 214 \n",
"16 NaN NaN NaN 214 \n",
"20 NaN NaN NaN 214 \n",
"24 NaN NaN NaN 214 \n",
"\n",
" team_name timestamp type_id type_name under_pressure \n",
"4 Espanyol 00:00:00.738 30 Pass NaN \n",
"8 Espanyol 00:00:02.511 30 Pass NaN \n",
"16 Espanyol 00:00:09.581 30 Pass True \n",
"20 Espanyol 00:00:18.784 30 Pass NaN \n",
"24 Espanyol 00:00:20.122 30 Pass True \n",
"\n",
"[5 rows x 122 columns]"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pass_home.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"def draw_pitch(ax):\n",
" # focus on only half of the pitch\n",
" #Pitch Outline & Centre Line\n",
" Pitch = Rectangle([0,0], width = 120, height = 80, fill = False)\n",
" #Left, Right Penalty Area and midline\n",
" LeftPenalty = Rectangle([0,22.3], width = 14.6, height = 35.3, fill = False)\n",
" RightPenalty = Rectangle([105.4,22.3], width = 14.6, height = 35.3, fill = False)\n",
" midline = ConnectionPatch([60,0], [60,80], \"data\", \"data\")\n",
"\n",
" #Left, Right 6-yard Box\n",
" LeftSixYard = Rectangle([0,32], width = 4.9, height = 16, fill = False)\n",
" RightSixYard = Rectangle([115.1,32], width = 4.9, height = 16, fill = False)\n",
"\n",
"\n",
" #Prepare Circles\n",
" centreCircle = plt.Circle((60,40),8.1,color=\"white\", fill = False)\n",
" centreSpot = plt.Circle((60,40),0.71,color=\"white\")\n",
" #Penalty spots and Arcs around penalty boxes\n",
" leftPenSpot = plt.Circle((9.7,40),0.71,color=\"white\")\n",
" rightPenSpot = plt.Circle((110.3,40),0.71,color=\"white\")\n",
" leftArc = Arc((9.7,40),height=16.2,width=16.2,angle=0,theta1=310,theta2=50,color=\"white\")\n",
" rightArc = Arc((110.3,40),height=16.2,width=16.2,angle=0,theta1=130,theta2=230,color=\"white\")\n",
" \n",
" element = [Pitch, LeftPenalty, RightPenalty, midline, LeftSixYard, RightSixYard, centreCircle, \n",
" centreSpot, rightPenSpot, leftPenSpot, leftArc, rightArc]\n",
" for i in element:\n",
" ax.add_patch(i)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"players = home_team_list\n",
"#['Thibaut Courtois','Jan Vertonghen','Vincent Kompany','Toby Albertine Maurits Alderweireld','Thomas Meunier','Nacer Chadli','Axel Witsel','Marouane Fellaini-Bakkioui','Eden Hazard','Kevin De Bruyne','Romelu Lukaku Menama']\n",
"fig=plt.figure() #set up the figures\n",
"from matplotlib import rcParams\n",
"plt.style.use('dark_background')\n",
"fig.set_size_inches(16, 9)\n",
"ax=fig.add_subplot(1,1,1)\n",
"draw_pitch(ax) #overlay our different objects on the pitch\n",
"plt.ylim(-2, 82)\n",
"plt.xlim(-2, 122)\n",
"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_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",
" y_loc = -2*(play_temp.iloc[i]['location'][1] - 40) + play_temp.iloc[i]['location'][1] # y - y' = -2(y' +c) reflection of a point\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",
" y_avg = y_avg + y_loc\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",
" ax.scatter(x_avg, y_avg, s= (3 * touches)) \n",
" ax.annotate(player, (x_avg, y_avg))\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA6IAAAIMCAYAAADvmRGtAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvIxREBQAAIABJREFUeJzs3XlcVXXi//H3vewiolKOSwlYpKOJ4EK5JLk30+ZWuGRYqeWUWWnLNDlktqltZjqZJa6Za/1Ex10UIgWFe+G6f1XUsVwyN9xQ8Pz+cDh5ZREbPZC9no/H55Gc8znn8znncui+z+csNkmGAAAAAACwiL2sOwAAAAAA+GMhiAIAAAAALEUQBQAAAABYiiAKAAAAALAUQRQAAAAAYCmCKAAAAADAUgRRAAAAAIClCKIAAAAAAEsRRAEAAAAAliKIAgAAAAAsRRAFAAAAAFiKIAoAAAAAsBRBFAAAAABgKYIoAAAAAMBSBFEAAAAAgKUIogAAAAAASxFEAQAAAACWIogCAAAAACxFEAUAAAAAWIogCgAAAACwFEE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lavvvqqBg4ceMXLWwEAuNa4RxQAAIvsylx31WeYbTabdjrXXpf+jBw5UiEhIUpJSbku6wcAoDgEUQAALPLLT3t0IHvbVS2zf9dWHdm/9zr1CACAskEQBQDAQsunfKJzuWdKVfd87lmtmDrmOvcIAADrEUQBALDQns3pWvivEVcMo+dyz2jB+Le
"text/plain": [
"<Figure size 1152x648 with 1 Axes>"
]
},
"metadata": {},
"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",
"fig=plt.figure() #set up the figures\n",
"from matplotlib import rcParams\n",
"plt.style.use('dark_background')\n",
"fig.set_size_inches(16,9)\n",
"ax=fig.add_subplot(1,1,1)\n",
"draw_pitch(ax) #overlay our different objects on the pitch\n",
"plt.ylim(-2, 82)\n",
"plt.xlim(-2, 122)\n",
"plt.axis('off')\n",
"y_loc =0\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",
" #y_loc = (play_temp.iloc[i]['location'][1] + 40 ) %80\n",
" y_loc = -2*(play_temp.iloc[i]['location'][1] - 40) + play_temp.iloc[i]['location'][1] \n",
" x_avg = x_avg + play_temp.iloc[i]['location'][0]\n",
" y_avg = y_avg + y_loc\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",
" ax.scatter(x_avg, y_avg, s= (3 *touches )) \n",
" ax.annotate(player, (x_avg, y_avg))\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",
"version": "3.7.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}