File size: 1,437 Bytes
d6ea71e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
import os
from datetime import datetime
import pandas as pd
from pytest import fixture
from socceraction.data.opta import OptaCompetitionSchema, OptaGameSchema
from socceraction.data.opta.parsers import F1JSONParser
@fixture()
def f1json_parser() -> F1JSONParser:
path = os.path.join(
os.path.dirname(__file__),
os.pardir,
os.pardir,
os.pardir,
"datasets",
"opta",
"tournament-2017-8.json",
)
return F1JSONParser(str(path))
def test_extract_competitions(f1json_parser: F1JSONParser) -> None:
competitions = f1json_parser.extract_competitions()
assert len(competitions) == 1
assert competitions[(8, 2017)] == {
"competition_id": 8,
"season_id": 2017,
"competition_name": "English Premier League",
"season_name": "2017",
}
OptaCompetitionSchema.validate(pd.DataFrame.from_dict(competitions, orient="index"))
def test_extract_games(f1json_parser: F1JSONParser) -> None:
games = f1json_parser.extract_games()
assert len(games) == 1
assert games[918893] == {
"game_id": 918893,
"season_id": 2017,
"competition_id": 8,
"game_day": 1,
"game_date": datetime(2017, 8, 11, 19, 45),
"home_team_id": 3,
"away_team_id": 13,
"home_score": 4,
"away_score": 3,
}
OptaGameSchema.validate(pd.DataFrame.from_dict(games, orient="index"))
|