Skip to content

Commit

Permalink
World Cup example patch (#427)
Browse files Browse the repository at this point in the history
Co-authored-by: maximlt <mliquet@anaconda.com>
  • Loading branch information
Azaya89 and maximlt authored Oct 29, 2024
1 parent 0419694 commit 77c6ecd
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 31 deletions.
1 change: 0 additions & 1 deletion test_data/world_cup/events/events_England.json

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion test_data/world_cup/events/events_France.json

This file was deleted.

1 change: 0 additions & 1 deletion test_data/world_cup/events/events_Germany.json

This file was deleted.

1 change: 0 additions & 1 deletion test_data/world_cup/events/events_Italy.json

This file was deleted.

1 change: 0 additions & 1 deletion test_data/world_cup/events/events_Spain.json

This file was deleted.

2 changes: 1 addition & 1 deletion test_data/world_cup/events/events_World_Cup.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test_data/world_cup/players.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion world_cup/anaconda-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ description: Analysis of key events in the 2018 FIFA World Cup
examples_config:
created: 2024-06-24
maintainers:
- maximlt
- azaya89
categories:
- Sports
labels:
- hvplot
- holoviews
- panel
title: "FIFA World Cup 2018"
deployments:
Expand Down
56 changes: 34 additions & 22 deletions world_cup/world_cup.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"metadata": {},
"outputs": [],
"source": [
"events_df.head()"
"events_df.head(2)"
]
},
{
Expand All @@ -71,7 +71,7 @@
"metadata": {},
"outputs": [],
"source": [
"players_df.tail()"
"players_df.tail(2)"
]
},
{
Expand All @@ -94,8 +94,10 @@
"outputs": [],
"source": [
"event_type_count = events_df['eventName'].value_counts()\n",
"event_type_distribution = event_type_count.hvplot.bar(title='Distribution of Event Types', height=400,\n",
" responsive=True, rot=45)\n",
"event_type_distribution = event_type_count.hvplot.bar(\n",
" title='Distribution of Event Types', height=400,\n",
" responsive=True, rot=45,\n",
")\n",
"event_type_distribution"
]
},
Expand Down Expand Up @@ -180,9 +182,11 @@
" hv.Text(10, 6, 'Attack', 11) # attack text\n",
" ]\n",
" \n",
" field = hv.Overlay(pitch_elements).opts(frame_width=pitch_plot_width, frame_height=pitch_plot_height,\n",
" xlim=(-5, field_length + 5), ylim=(-5, field_width + 5),\n",
" xaxis=None, yaxis=None)\n",
" field = hv.Overlay(pitch_elements).opts(\n",
" frame_width=pitch_plot_width, frame_height=pitch_plot_height,\n",
" xlim=(-5, field_length + 5), ylim=(-5, field_width + 5),\n",
" xaxis=None, yaxis=None\n",
" )\n",
" return field"
]
},
Expand Down Expand Up @@ -235,7 +239,7 @@
"outputs": [],
"source": [
"events_df = transform_positions(events_df, field_length, field_width)\n",
"events_df.head()"
"events_df.head(2)"
]
},
{
Expand Down Expand Up @@ -286,9 +290,10 @@
" \n",
" event_heatmap = event_df.hvplot.hexbin(x='x', y='y', cmap=cmap, min_count=1, title=title)\n",
" \n",
" event_heatmap_plot = (event_heatmap * pitch).opts(frame_width=pitch_plot_width, frame_height=pitch_plot_height,\n",
" xlim=(-5, 110), ylim=(-5, 73),\n",
" xaxis=None, yaxis=None)\n",
" event_heatmap_plot = (event_heatmap * pitch).opts(\n",
" frame_width=pitch_plot_width, frame_height=pitch_plot_height,\n",
" xlim=(-5, 110), ylim=(-5, 73), xaxis=None, yaxis=None\n",
" )\n",
"\n",
" return event_heatmap_plot"
]
Expand Down Expand Up @@ -434,12 +439,14 @@
" \"\"\"\n",
" top_players = find_top_players(events_df, players_df, event_type, top_n)\n",
" event_type = event_type.lower()\n",
" \n",
"\n",
" title = f'Top {top_n} Players for {event_type.capitalize()}'\n",
" \n",
" bar_plot = top_players.hvplot.bar(title=title, x='shortName', y=f'{event_type} count',\n",
" xlabel='', ylabel=f'Number of {event_type}', rot=45)\n",
" \n",
"\n",
" bar_plot = top_players.hvplot.bar(\n",
" title=title, x='shortName', y=f'{event_type} count',\n",
" xlabel='', ylabel=f'Number of {event_type}', rot=45\n",
" )\n",
"\n",
" return bar_plot"
]
},
Expand Down Expand Up @@ -473,7 +480,7 @@
"top_n_selector = pn.widgets.IntSlider(name='Top', start=1, end=20, value=10)\n",
"\n",
"bar_chart = pn.bind(plot_top_players, events_df=events_df, players_df=players_df,\n",
" event_type=event_type_selector, top_n=top_n_selector)\n",
" event_type=event_type_selector, top_n=top_n_selector)\n",
"\n",
"pn.Column(pn.Row(top_n_selector, event_type_selector), bar_chart)"
]
Expand Down Expand Up @@ -563,12 +570,14 @@
"metadata": {},
"outputs": [],
"source": [
"player_name_selector = pn.widgets.AutocompleteInput(name='Player Name', options=list(players_df['shortName']),\n",
" placeholder='Type player name...', case_sensitive=False,\n",
" search_strategy='includes', value='L. Messi')\n",
"player_name_selector = pn.widgets.AutocompleteInput(\n",
" name='Player Name', options=list(players_df['shortName']),\n",
" placeholder='Type player name...', case_sensitive=False,\n",
" search_strategy='includes', value='L. Messi'\n",
")\n",
"\n",
"player_events = pn.bind(plot_player_events, events_df=events_df,\n",
" players_df=players_df, player_name=player_name_selector)\n",
" players_df=players_df, player_name=player_name_selector)\n",
"\n",
"pn.Column(player_name_selector, player_events, sizing_mode='stretch_width')"
]
Expand Down Expand Up @@ -608,7 +617,10 @@
" pass_positions = [(pos[0]['x'], pos[0]['y']) for pos in passes['positions'] if len(pos) > 1]\n",
" pass_df = pd.DataFrame(pass_positions, columns=['x', 'y'])\n",
" \n",
" pass_scatter = pass_df.hvplot.points(x='x', y='y', color='#1D78B4', title=f\"Click for Pass Trajectories of {player_name}\")\n",
" pass_scatter = pass_df.hvplot.points(\n",
" x='x', y='y', color='#1D78B4',\n",
" title=f\"Click for Pass Trajectories of {player_name}\"\n",
" )\n",
" total_passes = hv.Text(75, 70, f'Total number of passes: {len(pass_df)}', halign='center', fontsize=12)\n",
" \n",
" # Callback to filter passes based on click location\n",
Expand Down

0 comments on commit 77c6ecd

Please sign in to comment.