From 13485e385bb9899b16a854440ea6b7434d8d56f7 Mon Sep 17 00:00:00 2001 From: Scott Date: Wed, 22 Mar 2023 13:48:52 +0000 Subject: [PATCH 1/2] Speed up pluralisation --- setup.py | 4 +--- statsbombpy/helpers.py | 54 +++++++++++++++++++++++++++++------------- 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/setup.py b/setup.py index a93ddfa..55f533a 100755 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ setup( name="statsbombpy", - version="1.7.0", + version="1.7.1", description="easily stream StatsBomb data into Python", long_description=README, long_description_content_type="text/markdown", @@ -17,8 +17,6 @@ author_email="support@statsbombservices.com", packages=["statsbombpy"], install_requires=[ - "joblib", - "inflect", "nose2", "pandas", "requests", diff --git a/statsbombpy/helpers.py b/statsbombpy/helpers.py index c3c6dda..4862025 100755 --- a/statsbombpy/helpers.py +++ b/statsbombpy/helpers.py @@ -1,8 +1,42 @@ from collections import defaultdict -import inflect import pandas as pd -from joblib import Memory + +PLURALS = { + 'Starting XI': 'starting_xis', + 'Half Start': 'half_starts', + 'Pass': 'passes', + 'Ball Receipt*': 'ball_receipts', + 'Carry': 'carrys', + 'Pressure': 'pressures', + 'Foul Committed': 'foul_committeds', + 'Foul Won': 'foul_wons', + 'Duel': 'duels', + 'Interception': 'interceptions', + 'Block': 'blocks', + 'Referee Ball-Drop': 'referee_ball_drops', + 'Ball Recovery': 'ball_recoverys', + 'Dispossessed': 'dispossesseds', + 'Clearance': 'clearances', + 'Dribble': 'dribbles', + 'Miscontrol': 'miscontrols', + 'Shot': 'shots', + 'Goal Keeper': 'goal_keepers', + 'Dribbled Past': 'dribbled_pasts', + 'Injury Stoppage': 'injury_stoppages', + 'Half End': 'half_ends', + 'Substitution': 'substitutions', + 'Shield': 'shields', + 'Tactical Shift': 'tactical_shifts', + 'Own Goal Against': 'own_goal_againsts', + 'Own Goal For': 'own_goal_fors', + 'Bad Behaviour': 'bad_behaviours', + 'Player Off': 'player_offs', + 'Player On': 'player_ons', + '50/50': '50/50s', + 'Error': 'errors', + 'Offside': 'offsides' +} def flatten_event(event, flatten_attrs): @@ -25,7 +59,7 @@ def flatten_event(event, flatten_attrs): def filter_and_group_events(events, filters, fmt, flatten_attrs): events_ = defaultdict(list) for ev in events.values(): - ev_type = pluralize(ev["type"]["name"]) + ev_type = PLURALS.get(ev["type"]["name"]) if not is_relevant(ev, filters): continue if fmt == "dataframe": @@ -75,17 +109,3 @@ def merge_events_and_frames( return events -engine = inflect.engine() - -cachedir = ".cache/" -memory = Memory(cachedir, verbose=0) - - -@memory.cache -def pluralize(word): - word = engine.plural(word) - word = word.replace("*", "") - word = word.replace("-", "_") - word = word.replace(" ", "_") - word = word.lower() - return word From e1c481bf5b15c4f7529a37cad9a58562945b7c19 Mon Sep 17 00:00:00 2001 From: Scott Date: Tue, 28 Mar 2023 12:13:59 +0100 Subject: [PATCH 2/2] Add missing events and bump version number --- setup.py | 2 +- statsbombpy/helpers.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 55f533a..0e5aa22 100755 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ setup( name="statsbombpy", - version="1.7.1", + version="1.9.0", description="easily stream StatsBomb data into Python", long_description=README, long_description_content_type="text/markdown", diff --git a/statsbombpy/helpers.py b/statsbombpy/helpers.py index 4862025..679f1eb 100755 --- a/statsbombpy/helpers.py +++ b/statsbombpy/helpers.py @@ -5,6 +5,8 @@ PLURALS = { 'Starting XI': 'starting_xis', 'Half Start': 'half_starts', + 'Camera On': 'camera ons', + 'Camera off': 'camera offs', 'Pass': 'passes', 'Ball Receipt*': 'ball_receipts', 'Carry': 'carrys', @@ -59,7 +61,7 @@ def flatten_event(event, flatten_attrs): def filter_and_group_events(events, filters, fmt, flatten_attrs): events_ = defaultdict(list) for ev in events.values(): - ev_type = PLURALS.get(ev["type"]["name"]) + ev_type = PLURALS[ev["type"]["name"]] if not is_relevant(ev, filters): continue if fmt == "dataframe":