Skip to content

Commit

Permalink
HTTPError and doc string reference
Browse files Browse the repository at this point in the history
  • Loading branch information
UnravelSports [JB] committed Nov 28, 2024
1 parent baf16e5 commit 835b4f7
Showing 1 changed file with 43 additions and 15 deletions.
58 changes: 43 additions & 15 deletions kloppy/_providers/sportec.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
from kloppy.io import open_as_file, FileLike
from kloppy.utils import deprecated

from requests.exceptions import HTTPError


def load_event(
event_data: FileLike,
Expand Down Expand Up @@ -121,19 +123,32 @@ def load_open_event_data(
coordinates: Optional[str] = None,
event_factory: Optional[EventFactory] = None,
) -> EventDataset:
"""
Data associated with research paper:
Bassek, M., Weber, H., Rein, R., & Memmert, D. (2024).
"An integrated dataset of synchronized spatiotemporal and event data in elite soccer." In Submission.
"""

if not META_DATA_MAP.get(match_id):
raise ValueError(
f"This match_id is not available, please select from {list(META_DATA_MAP.keys())}"
)

return load_event(
event_data=DATA_URL.format(file_id=EVENT_DATA_MAP[match_id]),
meta_data=DATA_URL.format(file_id=META_DATA_MAP[match_id]),
event_types=event_types,
coordinates=coordinates,
event_factory=event_factory,
)
try:
return load_event(
event_data=DATA_URL.format(file_id=EVENT_DATA_MAP[match_id]),
meta_data=DATA_URL.format(file_id=META_DATA_MAP[match_id]),
event_types=event_types,
coordinates=coordinates,
event_factory=event_factory,
)
except HTTPError as e:
raise HTTPError(
"Unable to retrieve data. The dataset archive location may have changed. "
"Please verify the `kloppy.sportec.DATA_URL` and file mappings. "
"This issue might be resolved by updating to the latest version of kloppy. "
"Original error: {}".format(e)
)


def load_open_tracking_data(
Expand All @@ -143,17 +158,30 @@ def load_open_tracking_data(
coordinates: Optional[str] = None,
only_alive: Optional[bool] = True,
) -> EventDataset:
"""
Data associated with research paper:
Bassek, M., Weber, H., Rein, R., & Memmert, D. (2024).
"An integrated dataset of synchronized spatiotemporal and event data in elite soccer." In Submission.
"""

if not META_DATA_MAP.get(match_id):
raise ValueError(
f"This match_id is not available, please select from {list(META_DATA_MAP.keys())}"
)

return load_tracking(
raw_data=DATA_URL.format(file_id=TRACKING_DATA_MAP[match_id]),
meta_data=DATA_URL.format(file_id=META_DATA_MAP[match_id]),
sample_rate=sample_rate,
limit=limit,
coordinates=coordinates,
only_alive=only_alive,
)
try:
return load_tracking(
raw_data=DATA_URL.format(file_id=TRACKING_DATA_MAP[match_id]),
meta_data=DATA_URL.format(file_id=META_DATA_MAP[match_id]),
sample_rate=sample_rate,
limit=limit,
coordinates=coordinates,
only_alive=only_alive,
)
except HTTPError as e:
raise HTTPError(
"Unable to retrieve data. The dataset archive location may have changed. "
"Please verify the `kloppy.sportec.DATA_URL` and file mappings. "
"This issue might be resolved by updating to the latest version of kloppy. "
"Original error: {}".format(e)
)

0 comments on commit 835b4f7

Please sign in to comment.