-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f6d330f
commit f73ebd6
Showing
7 changed files
with
3,108 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import os | ||
|
||
import pandas as pd | ||
from pytest import fixture | ||
|
||
from socceraction.data.opta import OptaPlayerSchema | ||
from socceraction.data.opta.parsers import MA12JSONParser | ||
|
||
|
||
@fixture() | ||
def ma12json_parser() -> MA12JSONParser: | ||
path = os.path.join( | ||
os.path.dirname(__file__), | ||
os.pardir, | ||
os.pardir, | ||
os.pardir, | ||
"datasets", | ||
"opta", | ||
"ma12_drnl1etmyzjz088y0bb4kh4pg.json", | ||
) | ||
return MA12JSONParser(str(path)) | ||
|
||
|
||
def test_extract_players(ma12json_parser: MA12JSONParser) -> None: | ||
players = ma12json_parser.extract_players() | ||
assert len(players) == 40 | ||
assert players[("drnl1etmyzjz088y0bb4kh4pg", "4iijb6llnz28unsz4rirr3umt")] == { | ||
"game_id": "drnl1etmyzjz088y0bb4kh4pg", | ||
"player_id": "4iijb6llnz28unsz4rirr3umt", | ||
"player_name": "David Raya", | ||
"team_id": "7yx5dqhhphyvfisohikodajhv", | ||
"jersey_number": 1, | ||
"minutes_played": 90, | ||
"starting_position": "Goalkeeper", | ||
"is_starter": True, | ||
"position_side": "Centre", | ||
"xG_non_penalty": 0.0, | ||
} | ||
# red card | ||
assert ( | ||
players[("drnl1etmyzjz088y0bb4kh4pg", "ds1wjqejslhsbcvzaufxubey2")]["minutes_played"] == 10 | ||
) | ||
assert ( | ||
players[("drnl1etmyzjz088y0bb4kh4pg", "2o5etqath4k9qaliho4op0hd5")]["minutes_played"] == 0 | ||
) | ||
OptaPlayerSchema.validate(pd.DataFrame.from_dict(players, orient="index")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import os | ||
from datetime import datetime | ||
|
||
import pandas as pd | ||
from pytest import fixture | ||
|
||
from socceraction.data.opta import OptaGameSchema | ||
from socceraction.data.opta.parsers import MA5JSONParser | ||
|
||
|
||
@fixture() | ||
def ma5json_parser() -> MA5JSONParser: | ||
path = os.path.join( | ||
os.path.dirname(__file__), | ||
os.pardir, | ||
os.pardir, | ||
os.pardir, | ||
"datasets", | ||
"opta", | ||
"ma5_drnl1etmyzjz088y0bb4kh4pg.json", | ||
) | ||
return MA5JSONParser(str(path)) | ||
|
||
|
||
def test_extract_games(ma5json_parser: MA5JSONParser) -> None: | ||
games = ma5json_parser.extract_games() | ||
assert len(games) == 1 | ||
assert games["drnl1etmyzjz088y0bb4kh4pg"] == { | ||
"game_id": "drnl1etmyzjz088y0bb4kh4pg", | ||
"season_id": "8l3o9v8n8tva0bb2cds2dhatw", | ||
"competition_id": "2kwbbcootiqqgmrzs6o5inle5", | ||
"game_day": 1, | ||
"game_date": datetime(2021, 8, 13, 19, 0), | ||
"home_team_id": "7yx5dqhhphyvfisohikodajhv", | ||
"away_team_id": "4dsgumo7d4zupm2ugsvm4zm4d", | ||
"away_possession": 64.7, | ||
"home_possession": 35.3, | ||
} | ||
OptaGameSchema.validate(pd.DataFrame.from_dict(games, orient="index")) |
Oops, something went wrong.