Overview
TheGameStats model stores comprehensive match statistics for a team’s performance in a specific game. It includes advanced metrics such as expected goals (xG), passing statistics, defensive actions, possession data, and goalkeeping stats. Each game typically has two GameStats records (one per team).
Model Definition
Table Name:game_stats
Location: premier_league/data/models/game_stats.py:7
Primary Fields
Auto-incrementing primary key for the game stats record.
Foreign key reference to the game. Links to
game.id.Foreign key reference to the team. Links to
team.id.Relationships
SQLAlchemy relationship to the
Game object. Configured with uselist=False to return a single game object.SQLAlchemy relationship to the
Team object that these statistics belong to.Expected Goals and Assists
Expected goals - a measure of the quality of chances created by the team.
Expected assists - a measure of the quality of goal-scoring opportunities created for teammates.
Expected assisted goals - combines xG and xA for an overall attacking threat metric.
Shots Statistics
All shot statistics are broken down by position (FW=Forward, MF=Midfielder, DF=Defender):Total shots taken by forwards.
Total shots taken by midfielders.
Total shots taken by defenders.
Shots on target by forwards.
Shots on target by midfielders.
Shots on target by defenders.
Chance Creation
Actions by forwards that lead to a shot (pass, dribble, foul drawn, etc.).
Actions by midfielders that lead to a shot.
Actions by defenders that lead to a shot.
Actions by forwards that directly lead to a goal.
Actions by midfielders that directly lead to a goal.
Actions by defenders that directly lead to a goal.
Passing Statistics
Successful passes completed by forwards.
Successful passes completed by midfielders.
Successful passes completed by defenders.
Pass completion percentage for forwards.
Pass completion percentage for midfielders.
Pass completion percentage for defenders.
Passes that directly lead to a shot.
Completed passes into the attacking third of the pitch.
Completed passes into the opponent’s penalty area.
Crosses completed into the opponent’s penalty area.
Passes that move the ball significantly closer to the opponent’s goal.
Defensive Statistics
Successful tackles by forwards.
Successful tackles by midfielders.
Successful tackles by defenders.
Successful challenges against dribbling opponents by forwards.
Successful challenges against dribbling opponents by midfielders.
Successful challenges against dribbling opponents by defenders.
Blocked shots or passes by forwards.
Blocked shots or passes by midfielders.
Blocked shots or passes by defenders.
Interceptions by forwards.
Interceptions by midfielders.
Interceptions by defenders.
Clearances by forwards.
Clearances by midfielders.
Clearances by defenders.
Defensive errors that directly resulted in an opponent’s goal.
Possession Statistics
Ball possession percentage (0-100).
Total ball touches by forwards.
Total ball touches by midfielders.
Total ball touches by defenders.
Touches in the attacking penalty area by forwards.
Touches in the attacking penalty area by midfielders.
Touches in the attacking penalty area by defenders.
Attempted dribbles/take-ons by forwards.
Attempted dribbles/take-ons by midfielders.
Attempted dribbles/take-ons by defenders.
Successful dribbles/take-ons by forwards.
Successful dribbles/take-ons by midfielders.
Successful dribbles/take-ons by defenders.
Number of times forwards carried the ball.
Number of times midfielders carried the ball.
Number of times defenders carried the ball.
Ball carries that entered the opponent’s penalty area.
Total distance (in yards) the ball was carried by forwards.
Total distance (in yards) the ball was carried by midfielders.
Total distance (in yards) the ball was carried by defenders.
Times forwards lost possession to an opponent.
Times midfielders lost possession to an opponent.
Times defenders lost possession to an opponent.
Aerial duels won by forwards.
Aerial duels won by midfielders.
Aerial duels won by defenders.
Aerial duels lost by forwards.
Aerial duels lost by midfielders.
Aerial duels lost by defenders.
Poor ball controls by forwards.
Poor ball controls by midfielders.
Poor ball controls by defenders.
Goalkeeping Statistics
Percentage of shots on target that were saved by the goalkeeper.
Total number of saves made by the goalkeeper.
Post-shot expected goals - quality of shots faced by the goalkeeper.
Successful passes completed by the goalkeeper.
Crosses into the box stopped by the goalkeeper.
Long passes (40+ yards) completed by the goalkeeper.
Other Match Statistics
Number of yellow cards received.
Number of red cards received.
Penalties won by the team.
Penalties conceded by the team.
Fouls committed by forwards.
Fouls committed by midfielders.
Fouls committed by defenders.
Fouls drawn by forwards.
Fouls drawn by midfielders.
Fouls drawn by defenders.
Offside calls against forwards.
Offside calls against midfielders.
Offside calls against defenders.
Database Indexes
The GameStats model includes a unique composite index:idx_game_team_stats: Unique composite index on (game_id,team_id) ensuring each team has only one stats record per game
Methods
to_dict()
dict: Dictionary containing all statistics fields.