{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "name": "11tegen11gif.ipynb", "provenance": [], "collapsed_sections": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3" } }, "cells": [ { "cell_type": "code", "metadata": { "id": "9PUEaHPDlLi5", "colab_type": "code", "outputId": "10d7d0a5-2b22-4100-90bf-fbb43744fb85", "colab": { "base_uri": "https://localhost:8080/", "height": 153 } }, "source": [ "!git clone https://github.com/statsbomb/open-data.git" ], "execution_count": 1, "outputs": [ { "output_type": "stream", "text": [ "Cloning into 'open-data'...\n", "remote: Enumerating objects: 600, done.\u001b[K\n", "remote: Counting objects: 100% (600/600), done.\u001b[K\n", "remote: Compressing objects: 100% (271/271), done.\u001b[K\n", "remote: Total 6950 (delta 519), reused 407 (delta 326), pack-reused 6350\u001b[K\n", "Receiving objects: 100% (6950/6950), 729.86 MiB | 24.95 MiB/s, done.\n", "Resolving deltas: 100% (6161/6161), done.\n", "Checking out files: 100% (1273/1273), done.\n" ], "name": "stdout" } ] }, { "cell_type": "code", "metadata": { "id": "p_6BurGVpHeE", "colab_type": "code", "colab": {} }, "source": [ "#edit only this tab\n", "#give the folder path of the match\n", "path = \"/content/open-data/data/events/\"\n", "home_team = 'Espanyol'\n", "away_team = 'Barcelona'" ], "execution_count": 0, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "HaXB1D8ipuyY", "colab_type": "code", "outputId": "6bc862c3-96e4-4650-a1f3-544cd0916661", "colab": { "base_uri": "https://localhost:8080/", "height": 34 } }, "source": [ "import PIL\n", "import imageio\n", "from IPython import display\n", "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" ], "execution_count": 85, "outputs": [ { "output_type": "stream", "text": [ "done\n" ], "name": "stdout" } ] }, { "cell_type": "code", "metadata": { "id": "Hs2plpAcqXNm", "colab_type": "code", "colab": {} }, "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" ], "execution_count": 0, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "lJEuZAIfqcbR", "colab_type": "code", "outputId": "826f8fd3-1399-4f2f-bcda-0e9bd77f85ee", "colab": { "base_uri": "https://localhost:8080/", "height": 51 } }, "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)" ], "execution_count": 87, "outputs": [ { "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" ], "name": "stdout" } ] }, { "cell_type": "code", "metadata": { "id": "EcI20iZJqd67", "colab_type": "code", "colab": {} }, "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]" ], "execution_count": 0, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "lzKdQhmSqfnn", "colab_type": "code", "outputId": "e1700207-3fd6-4234-e6ec-2c4f4d6efcb0", "colab": { "base_uri": "https://localhost:8080/", "height": 457 } }, "source": [ "pass_home.head()" ], "execution_count": 89, "outputs": [ { "output_type": "execute_result", "data": { "text/html": [ "
\n", " | 50_50_outcome_id | \n", "50_50_outcome_name | \n", "bad_behaviour_card_id | \n", "bad_behaviour_card_name | \n", "ball_receipt_outcome_id | \n", "ball_receipt_outcome_name | \n", "ball_recovery_recovery_failure | \n", "block_deflection | \n", "block_offensive | \n", "carry_end_location | \n", "clearance_aerial_won | \n", "clearance_body_part_id | \n", "clearance_body_part_name | \n", "clearance_head | \n", "clearance_left_foot | \n", "clearance_right_foot | \n", "counterpress | \n", "dribble_nutmeg | \n", "dribble_outcome_id | \n", "dribble_outcome_name | \n", "dribble_overrun | \n", "duel_outcome_id | \n", "duel_outcome_name | \n", "duel_type_id | \n", "duel_type_name | \n", "duration | \n", "foul_committed_advantage | \n", "foul_committed_card_id | \n", "foul_committed_card_name | \n", "foul_committed_offensive | \n", "foul_committed_type_id | \n", "foul_committed_type_name | \n", "foul_won_advantage | \n", "foul_won_defensive | \n", "goalkeeper_body_part_id | \n", "goalkeeper_body_part_name | \n", "goalkeeper_end_location | \n", "goalkeeper_outcome_id | \n", "goalkeeper_outcome_name | \n", "goalkeeper_position_id | \n", "... | \n", "period | \n", "play_pattern_id | \n", "play_pattern_name | \n", "player_id | \n", "player_name | \n", "position_id | \n", "position_name | \n", "possession | \n", "possession_team_id | \n", "possession_team_name | \n", "related_events | \n", "second | \n", "shot_aerial_won | \n", "shot_body_part_id | \n", "shot_body_part_name | \n", "shot_end_location | \n", "shot_first_time | \n", "shot_freeze_frame | \n", "shot_key_pass_id | \n", "shot_one_on_one | \n", "shot_outcome_id | \n", "shot_outcome_name | \n", "shot_redirect | \n", "shot_statsbomb_xg | \n", "shot_technique_id | \n", "shot_technique_name | \n", "shot_type_id | \n", "shot_type_name | \n", "substitution_outcome_id | \n", "substitution_outcome_name | \n", "substitution_replacement_id | \n", "substitution_replacement_name | \n", "tactics_formation | \n", "tactics_lineup | \n", "team_id | \n", "team_name | \n", "timestamp | \n", "type_id | \n", "type_name | \n", "under_pressure | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
4 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "0.606100 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "... | \n", "1 | \n", "9 | \n", "From Kick Off | \n", "26609.0 | \n", "Pablo Daniel Osvaldo | \n", "23.0 | \n", "Center Forward | \n", "2 | \n", "214 | \n", "Espanyol | \n", "[ca57ebcb-f65d-4d0c-b54d-c2ea0ccb8553] | \n", "0 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "214 | \n", "Espanyol | \n", "00:00:00.738 | \n", "30 | \n", "Pass | \n", "NaN | \n", "
8 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "1.776163 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "... | \n", "1 | \n", "9 | \n", "From Kick Off | \n", "26211.0 | \n", "Joan Verdú Fernández | \n", "21.0 | \n", "Left Wing | \n", "2 | \n", "214 | \n", "Espanyol | \n", "[cb6b2c06-a935-4588-b7cb-e1e952c9ddbe] | \n", "2 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "214 | \n", "Espanyol | \n", "00:00:02.511 | \n", "30 | \n", "Pass | \n", "NaN | \n", "
16 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "1.242900 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "... | \n", "1 | \n", "9 | \n", "From Kick Off | \n", "7029.0 | \n", "José María Callejón Bueno | \n", "17.0 | \n", "Right Wing | \n", "2 | \n", "214 | \n", "Espanyol | \n", "[34e65d1a-4eca-4b55-8340-d125a8a32808, a6aedc7... | \n", "9 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "214 | \n", "Espanyol | \n", "00:00:09.581 | \n", "30 | \n", "Pass | \n", "True | \n", "
20 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "1.298500 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "... | \n", "1 | \n", "4 | \n", "From Throw In | \n", "6886.0 | \n", "Dídac Vilá Rosselló | \n", "6.0 | \n", "Left Back | \n", "3 | \n", "214 | \n", "Espanyol | \n", "[98eb8c82-78c5-4c62-8c1b-02f5194eec55] | \n", "18 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "214 | \n", "Espanyol | \n", "00:00:18.784 | \n", "30 | \n", "Pass | \n", "NaN | \n", "
24 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "0.950262 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "... | \n", "1 | \n", "4 | \n", "From Throw In | \n", "24783.0 | \n", "Javier Márquez Moreno | \n", "13.0 | \n", "Right Center Midfield | \n", "3 | \n", "214 | \n", "Espanyol | \n", "[1323492f-0fdc-4df7-bfd2-1a3f8c7b63e5, e27e148... | \n", "20 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "214 | \n", "Espanyol | \n", "00:00:20.122 | \n", "30 | \n", "Pass | \n", "True | \n", "
5 rows × 122 columns
\n", "