{ "cells": [ { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "application/mercury+json": { "allow_download": true, "code_uid": "App.0.40.25.15-randce520963", "continuous_update": true, "description": "", "full_screen": true, "model_id": "mercury-app", "notify": "{}", "output": "app", "schedule": "", "show_code": false, "show_prompt": false, "show_sidebar": true, "static_notebook": false, "stop_on_error": false, "title": "Sim (specific match)", "widget": "App" }, "text/html": [ "

Mercury Application

This output won't appear in the web app." ], "text/plain": [ "mercury.App" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import mercury as mr\n", "import sys\n", "\n", "from pathlib import Path\n", "\n", "# in jupyter (lab / notebook), based on notebook path\n", "module_path = str(Path.cwd())\n", "\n", "if module_path not in sys.path:\n", " sys.path.append(module_path)\n", "\n", "\n", "from common.shared import environment\n", "\n", "app = mr.App(title=\"Sim (specific match)\")" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "tags": [ "parameters" ] }, "outputs": [ { "data": { "application/mercury+json": { "code_uid": "Text.0.40.15.5.2-randb940103a", "disabled": false, "hidden": false, "label": "Match ID", "model_id": "68db6dea600b4609b40830d3eb22750c", "rows": 1, "url_key": "", "value": "M:T18p-IWGAFV-", "widget": "Text" }, "application/vnd.jupyter.widget-view+json": { "model_id": "68db6dea600b4609b40830d3eb22750c", "version_major": 2, "version_minor": 0 }, "text/plain": [ "mercury.Text" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from sim_match_analysis.form import match_id_input\n", "match_id = match_id_input()" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "from sim_match_analysis.data.match import get_match\n", "match = get_match(match_id.value)" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " FUTVERSOFC #5\n", " 0\n", " -\n", " 1\n", " Xeneize FC #12\n", " \n", "
\n" ], "text/plain": [ "" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from IPython.display import HTML\n", "\n", "# Assuming 'match' is a dictionary that contains the match data\n", "left_team_info = match['leftTeamInfo']\n", "right_team_info = match['rightTeamInfo']\n", "\n", "# Score information\n", "score = match['score']\n", "\n", "# Define the HTML structure with a container\n", "html_content = f'''\n", "
\n", " \n", " {left_team_info[\"name\"]}\n", " {score[0]}\n", " -\n", " {score[1]}\n", " {right_team_info[\"name\"]}\n", " \n", "
\n", "'''\n", "\n", "# Display the HTML\n", "HTML(html_content)" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [], "source": [ "import re\n", "\n", "METASOCCER_ATTRIBUTE_SECTION = {\n", " # condition\n", " 'agression': 'condition',\n", " 'concentration': 'condition',\n", " 'creativity': 'condition',\n", " 'fitness': 'condition',\n", " 'speed': 'condition',\n", " 'strength': 'condition',\n", " # goalkeeping\n", " 'diving': 'goalkeeping',\n", " 'handling': 'goalkeeping',\n", " 'kicking': 'goalkeeping',\n", " 'punching': 'goalkeeping',\n", " 'reflexes': 'goalkeeping',\n", " 'throwing': 'goalkeeping',\n", " # tactical\n", " 'bravery': 'tactical',\n", " 'marking': 'tactical',\n", " 'positioning': 'tactical',\n", " 'slidingTackle': 'tactical',\n", " 'standingTackle': 'tactical',\n", " 'vision': 'tactical',\n", " # technical\n", " 'crossing': 'technical',\n", " 'dribbling': 'technical',\n", " 'finishing': 'technical',\n", " 'heading': 'technical',\n", " 'passing': 'technical',\n", " 'shooting': 'technical',\n", "}\n", "\n", "FOOTBALL_METASOCCER_ATTRIBUTE_MAPPING_GK = {\n", " 'mental_calmness': ['concentration'],\n", " 'mental_resilience': ['concentration', 'strength'],\n", " 'mental_defensivepositioning': ['concentration', 'diving', 'handling'],\n", " 'mental_offensivepositioning': ['positioning'],\n", " 'mental_vision': ['vision', 'reflexes'],\n", " 'mental_workrate': ['concentration', 'fitness'],\n", " 'physical_acceleration': ['speed'],\n", " 'physical_agility': ['speed'],\n", " 'physical_balance': ['fitness'],\n", " 'physical_reaction': ['reflexes'],\n", " 'physical_shotpower': ['kicking', 'strength'],\n", " 'physical_velocity': ['speed'],\n", " 'physical_stamina': ['fitness'],\n", " 'technical_ballcontrol': ['kicking'],\n", " 'technical_dribble': ['creativity', 'dribbling'],\n", " 'technical_header': ['heading'],\n", " 'technical_highpass': ['passing', 'throwing'],\n", " 'technical_shot': ['shooting'],\n", " 'technical_shortpass': ['passing'],\n", " 'technical_slidingtackle': ['marking', 'slidingTackle'],\n", " 'technical_standingtackle': ['marking', 'standingTackle'],\n", " 'technical_volley': ['kicking', 'shooting'],\n", "}\n", "\n", "def convert_attribute_name(name):\n", " return re.sub('([a-z])([A-Z])', r'\\1 \\2', name).title()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Left team" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
#Player NameOVRAttributeFootball StatInitial Attribute(s)
Loading... (need help?)
\n", "\n", "\n", "
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import pandas as pd\n", "\n", "from itables import show\n", "\n", "# Assuming match_data is your JSON data\n", "players_left = match['leftInitialFieldEphereals']\n", "player_stats_left = match[\"leftFootballInfo\"][\"fieldEpherealsStatsByRole\"]\n", "\n", "data_left = []\n", "\n", "for i, player in enumerate(players_left):\n", " player_dorsal = player['dorsal']\n", " player_name = f\"{player['player']['name']} {player['player']['lastName']} #{player['player']['id']}\"\n", " player_ovr = player['player']['overall']\n", " for attribute, meta_soccer_attributes in FOOTBALL_METASOCCER_ATTRIBUTE_MAPPING_GK.items():\n", " initial_attributes = []\n", " total_initial_value = 0\n", " for meta_soccer_attribute in meta_soccer_attributes:\n", " initial_value = player['player']['sections'][METASOCCER_ATTRIBUTE_SECTION[meta_soccer_attribute]]['abilities'][convert_attribute_name(meta_soccer_attribute)]\n", " total_initial_value += initial_value\n", " initial_attributes.append(f\"{meta_soccer_attribute}: {(initial_value / 100)}\")\n", " value = player_stats_left[i][0][attribute]\n", " data_left.append([player_dorsal, player_name, player_ovr, attribute, value, '; '.join(initial_attributes)])\n", "\n", "df_left = pd.DataFrame(data_left, columns=['#', 'Player Name', 'OVR', 'Attribute', 'Football Stat', 'Initial Attribute(s)'])\n", "\n", "# Display the DataFrames as interactive tables\n", "show(df_left, style=\"width:100%\")" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
\n", "
\n", " \n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from IPython.display import HTML\n", "\n", "from sim_match_analysis.utils import render_pitch_html\n", "\n", "fuchsia_scale = ['#FF77FF', '#CF40CF', '#8B008B']\n", "\n", "passes_fuchsia = {\n", " 'shortPasses': fuchsia_scale[0],\n", " 'longPasses': fuchsia_scale[1],\n", " 'highPasses': fuchsia_scale[2]\n", "}\n", "\n", "pass_positions = []\n", "\n", "for player in match['matchStats']['leftFieldEphereals']:\n", " for pass_type in ['shortPasses', 'longPasses', 'highPasses']:\n", " if pass_type in player:\n", " for pass_info in player[pass_type]:\n", " # Adding player ID and pass position to the list\n", " pass_positions.append({\n", " 'player_id': player['epherealId'],\n", " 'type': pass_type,\n", " 'position': pass_info\n", " })\n", "\n", "HTML(render_pitch_html(list([item[\"position\"][0], item[\"position\"][1], passes_fuchsia[item[\"type\"]], item[\"player_id\"]] for item in pass_positions)))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Right team" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
#Player NameOVRAttributeFootball StatInitial Attribute(s)
Loading... (need help?)
\n", "\n", "\n", "
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import pandas as pd\n", "\n", "from itables import show\n", "\n", "# Assuming match_data is your JSON data\n", "players_right = match['rightInitialFieldEphereals']\n", "player_stats_right = match[\"rightFootballInfo\"][\"fieldEpherealsStatsByRole\"]\n", "\n", "data_right = []\n", "\n", "for i, player in enumerate(players_right):\n", " player_dorsal = player['dorsal']\n", " player_name = f\"{player['player']['name']} {player['player']['lastName']} #{player['player']['id']}\"\n", " player_ovr = player['player']['overall']\n", " for attribute, meta_soccer_attributes in FOOTBALL_METASOCCER_ATTRIBUTE_MAPPING_GK.items():\n", " initial_attributes = []\n", " total_initial_value = 0\n", " for meta_soccer_attribute in meta_soccer_attributes:\n", " initial_value = player['player']['sections'][METASOCCER_ATTRIBUTE_SECTION[meta_soccer_attribute]]['abilities'][convert_attribute_name(meta_soccer_attribute)]\n", " total_initial_value += initial_value\n", " initial_attributes.append(f\"{meta_soccer_attribute}: {(initial_value / 100)}\")\n", " value = player_stats_right[i][0][attribute]\n", " data_right.append([player_dorsal, player_name, player_ovr, attribute, value, '; '.join(initial_attributes)])\n", "\n", "df_right = pd.DataFrame(data_right, columns=['#', 'Player Name', 'OVR', 'Attribute', 'Football Stat', 'Initial Attribute(s)'])\n", "\n", "# Display the DataFrames as interactive tables\n", "show(df_right, style=\"width:100%\")" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
\n", "
\n", " \n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from IPython.display import HTML\n", "\n", "from sim_match_analysis.utils import render_pitch_html\n", "\n", "cyan_scale = ['#8FFFFF', '#40CFCF', '#008B8B']\n", "\n", "passes_cyan = {\n", " 'shortPasses': cyan_scale[0],\n", " 'longPasses': cyan_scale[1],\n", " 'highPasses': cyan_scale[2]\n", "}\n", "\n", "pass_positions = []\n", "\n", "for player in match['matchStats']['rightFieldEphereals']:\n", " for pass_type in ['shortPasses', 'longPasses', 'highPasses']:\n", " if pass_type in player:\n", " for pass_info in player[pass_type]:\n", " # Adding player ID and pass position to the list\n", " pass_positions.append({\n", " 'player_id': player['epherealId'],\n", " 'type': pass_type,\n", " 'position': pass_info\n", " })\n", "\n", "HTML(render_pitch_html(list([item[\"position\"][0], item[\"position\"][1], passes_cyan[item[\"type\"]], item[\"player_id\"]] for item in pass_positions)))" ] } ], "metadata": { "colab": { "provenance": [], "toc_visible": true }, "kernelspec": { "display_name": "Python 3", "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.11.6" } }, "nbformat": 4, "nbformat_minor": 0 }