Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion soccerdata/fotmob.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ def read_team_match_stats(
* 'Top stats'
* 'Shots'
* 'Expected goals (xG)'
* 'Expected goals on target (xGOT)'
* 'Passes'
* 'Defence'
* 'Duels'
Expand Down Expand Up @@ -410,12 +411,25 @@ def read_team_match_stats(

# Get stats types
all_stats = game_data["content"]["stats"]["Periods"]["All"]["stats"]

# create an alias for nested stats
alias_map = {
"Expected goals on target (xGOT)": "Expected goals (xG)",
}
parent_type = alias_map.get(stat_type, stat_type)

try:
selected_stats = next(stat for stat in all_stats if stat["title"] == stat_type)
selected_stats = next(stat for stat in all_stats if stat["title"] == parent_type)
except StopIteration:
raise ValueError(f"Invalid stat type: {stat_type}")

df_raw_stats = pd.DataFrame(selected_stats["stats"])

# xGOT filter
if stat_type == "Expected goals on target (xGOT)":
title_filter = "Expected goals on target (xGOT)"
df_raw_stats = df_raw_stats[df_raw_stats["title"] == title_filter]

game_teams = [game.home_team, game.away_team]
for i, team in enumerate(game_teams):
df_team_stats = df_raw_stats.copy()
Expand Down
11 changes: 10 additions & 1 deletion tests/test_FotMob.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,16 @@ def test_read_schedule(fotmob_laliga: FotMob) -> None:
@pytest.mark.fails_gha()
@pytest.mark.parametrize(
"stat_type",
["Top stats", "Shots", "Expected goals (xG)", "Passes", "Defence", "Duels", "Discipline"],
[
"Top stats",
"Shots",
"Expected goals (xG)",
"Expected goals on target (xGOT)",
"Passes",
"Defence",
"Duels",
"Discipline",
],
)
def test_read_team_match_stats(fotmob_laliga: FotMob, stat_type: str) -> None:
assert isinstance(
Expand Down
Loading