Skip to content

Commit

Permalink
Add docs for formation statebuilder, add contributors and bump versio…
Browse files Browse the repository at this point in the history
…n to 3.1.0
  • Loading branch information
koenvo committed Jan 28, 2022
1 parent 336454a commit 4007668
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 3 deletions.
8 changes: 8 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

Find out all changes between different kloppy versions

## 3.1.0 (2022-01-28)

Pull requests merged:

- Improve contribution guide ([#123](https://github.com/PySport/kloppy/pull/123))
- Fix extraction of foul committed events ([#126](https://github.com/PySport/kloppy/pull/126))
- Add formation statebuilder + read opta/statsbomb formation events ([#125](https://github.com/PySport/kloppy/pull/125))

## 3.0.0 (2021-12-21)

Pull request merged:
Expand Down
2 changes: 2 additions & 0 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,12 @@ style#two-columns-ul + ul {
- [Eujern Lim](https://github.com/eujern)
- [Felix Schmidt](https://github.com/schmidtfx)
- [Ingmar van Dijk](https://github.com/ivd-git)
- [Jan van Haaren](https://github.com/JanVanHaaren)
- [Joe Mulberry](https://github.com/joemulberry)
- [Koen Vossen](https://github.com/koenvo)
- [Marcelo Trylesinski](https://github.com/Kludex)
- [Matias Bordese](https://github.com/matiasb)
- [Milan Klaasman](https://github.com/MKlaasman)
- [Pratik Thanki](https://github.com/pratikthanki)
- [Ricardo Tavares](https://github.com/rjtavares)
- [Thomas Seidl](https://github.com/ThomasSeidl)
Expand Down
156 changes: 154 additions & 2 deletions docs/examples/state.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1235,13 +1235,165 @@
"dataframe['percentage'] = dataframe['sum'] / dataframe['count'] * 100\n",
"dataframe"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Add state - formation"
]
},
{
"cell_type": "code",
"execution_count": 63,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/koen/Developer/Projects/PySport/kloppy/.venv/lib/python3.8/site-packages/kloppy-3.1.0-py3.8.egg/kloppy/_providers/statsbomb.py:46: UserWarning: \n",
"\n",
"You are about to use StatsBomb public data.\n",
"By using this data, you are agreeing to the user agreement. \n",
"The user agreement can be found here: https://github.com/statsbomb/open-data/blob/master/LICENSE.pdf\n",
"\n",
" warnings.warn(\n"
]
}
],
"source": [
"from kloppy import statsbomb\n",
"from kloppy.domain import EventType\n",
"\n",
"\n",
"dataset = statsbomb.load_open_data()\n",
"\n",
"dataframe = (\n",
" dataset\n",
" .add_state('formation')\n",
" .filter(\n",
" lambda event: event.event_type == EventType.SHOT\n",
" )\n",
" .to_pandas(additional_columns={\n",
" 'Team': lambda event: str(event.team),\n",
" 'Formation': lambda event: str(\n",
" event.state['formation'].home \n",
" if event.team == dataset.metadata.teams[0] \n",
" else event.state['formation'].away\n",
" )\n",
" })\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 65,
"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></th>\n",
" <th>Goals</th>\n",
" <th>Shots</th>\n",
" <th>Percentage</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Team</th>\n",
" <th>Formation</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th rowspan=\"2\" valign=\"top\">Barcelona</th>\n",
" <th>4-3-3</th>\n",
" <td>3</td>\n",
" <td>14</td>\n",
" <td>21.428571</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4-4-2</th>\n",
" <td>0</td>\n",
" <td>11</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th rowspan=\"2\" valign=\"top\">Deportivo Alavés</th>\n",
" <th>4-1-4-1</th>\n",
" <td>0</td>\n",
" <td>2</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4-4-2</th>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Goals Shots Percentage\n",
"Team Formation \n",
"Barcelona 4-3-3 3 14 21.428571\n",
" 4-4-2 0 11 0.000000\n",
"Deportivo Alavés 4-1-4-1 0 2 0.000000\n",
" 4-4-2 0 1 0.000000"
]
},
"execution_count": 65,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dataframe_stats = dataframe.groupby(['Team', 'Formation'])['success'].agg(['sum', 'count'])\n",
"dataframe_stats['Percentage'] = dataframe_stats['sum'] / dataframe_stats['count'] * 100\n",
"dataframe_stats.rename(\n",
" columns={\n",
" 'sum': 'Goals',\n",
" 'count': 'Shots'\n",
" }\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "kloppy-venv",
"language": "python",
"name": "python3"
"name": "kloppy-venv"
},
"language_info": {
"codemirror_mode": {
Expand Down
2 changes: 1 addition & 1 deletion kloppy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
# )
# from .domain.services.state_builder import add_state

__version__ = "3.0.0"
__version__ = "3.1.0"

0 comments on commit 4007668

Please sign in to comment.