Skip to content

Commit

Permalink
add interface to raw jsons
Browse files Browse the repository at this point in the history
  • Loading branch information
FranGoitia committed Sep 10, 2020
1 parent b11440f commit de32c70
Show file tree
Hide file tree
Showing 17 changed files with 30 additions and 18 deletions.
22 changes: 20 additions & 2 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#### Support: [email protected]

#### Updated January 15, 2020.
#### Updated September 10, 2020.

This repository is a Python package to easily stream StatsBomb data into Python using your log in credentials for the API or free data from our GitHub page. **API access is for paying customers only**

Expand Down Expand Up @@ -491,7 +491,6 @@ grouped_events["dribbles"]
</table>

```
# if you want to store all events in a given competition on a single non tidy dataframe
events = sb.competition_events(
country="Germany",
Expand Down Expand Up @@ -648,3 +647,22 @@ grouped_events["dribbles"]
</table>


```
# alternatively, entities can be accessed as python dictionaries serving as an interface to raw jsons and without performing any preprocessing
sb.competitions(fmt="dict")
sb.matches(competition_id=9, season_id=42, fmt="dict")
sb.lineups(match_id=303299, fmt="dict")
sb.events(303299, fmt="dict")
sb.competition_events(
country="Germany",
division= "1. Bundesliga",
season="2019/2020",
gender="male",
fmt="dict"
)
```
Empty file modified doc/LICENSE.pdf
100644 → 100755
Empty file.
Empty file modified doc/Open Data Competitions v2.0.0.pdf
100644 → 100755
Empty file.
Empty file modified doc/Open Data Events v4.0.0.pdf
100644 → 100755
Empty file.
Empty file modified doc/Open Data Lineups v2.0.0.pdf
100644 → 100755
Empty file.
Empty file modified doc/Open Data Matches v3.0.0.pdf
100644 → 100755
Empty file.
Empty file modified doc/StatsBomb Open Data Specification v1.1.pdf
100644 → 100755
Empty file.
Empty file modified setup.py
100644 → 100755
Empty file.
Empty file modified statsbombpy/__init__.py
100644 → 100755
Empty file.
Empty file modified statsbombpy/api_client.py
100644 → 100755
Empty file.
Empty file modified statsbombpy/config.py
100644 → 100755
Empty file.
Empty file modified statsbombpy/entities.py
100644 → 100755
Empty file.
Empty file modified statsbombpy/helpers.py
100644 → 100755
Empty file.
Empty file modified statsbombpy/public.py
100644 → 100755
Empty file.
18 changes: 9 additions & 9 deletions statsbombpy/sb.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ def events(
events = api_client.events(match_id, creds)
else:
events = public.events(match_id)
events = filter_and_group_events(events, filters, fmt, flatten)

if fmt == "dataframe":
events = filter_and_group_events(events, filters, fmt, flatten)
for ev_type, evs in events.items():
events[ev_type] = pd.DataFrame(evs)
if split is False:
Expand All @@ -97,18 +97,18 @@ def competition_events(

c = competitions(creds)[country, division, season, gender]

events_call = partial(
events,
split=True,
filters=filters,
fmt="json",
flatten=fmt == "dataframe",
creds=creds,
)
events_call = partial(events, fmt="json", creds=creds,)
with Pool(PARALLELL_CALLS_NUM) as p:
matches_events = p.map(
events_call, matches(c["competition_id"], c["season_id"], creds)
)
matches_events = map(
lambda events: filter_and_group_events(
events, filters, fmt, fmt == "dataframe"
),
matches_events,
)

competition_events = reduce_events(matches_events, fmt)
if fmt == "dataframe" and split is False:
competition_events = pd.concat(
Expand Down
Empty file modified tests/__init__.py
100644 → 100755
Empty file.
8 changes: 1 addition & 7 deletions tests/statsbombpy_test/test_sb.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@ def test_events(self):
self.assertIsInstance(events["shots"], pd.DataFrame)

events = sb.events(match_id=7562, fmt="json")
self.assertIsInstance(events["shots"], list)
self.assertIsInstance(events["shots"][0], dict)

shots = sb.events(match_id=7562, filters={"type": "Shot"}, fmt="json")["shots"]
self.assertSetEqual({"Shot"}, set(map(lambda s: s["type"]["name"], shots)))
self.assertIsInstance(events, dict)

events = sb.events(match_id=7562, creds={})
self.assertIsInstance(events, pd.DataFrame)
Expand All @@ -79,8 +75,6 @@ def test_competition_events(self):
season="2019/2020",
fmt="json",
)
self.assertIsInstance(events["shots"], list)
self.assertIsInstance(events["shots"][0], dict)


if __name__ == "__main__":
Expand Down

0 comments on commit de32c70

Please sign in to comment.