Stats
Stats Class
Represents a statistical record for a player within a given season.
Attributes:
Name | Type | Description |
---|---|---|
stat_json |
dict
|
The raw JSON data containing the statistical information. |
espn_instance |
PYESPN
|
The ESPN API instance used for retrieving additional data. |
category |
str
|
The category of the stat (e.g., 'batting', 'pitching'). |
season |
int
|
The season in which the stats were recorded. |
player_id |
str
|
The unique ID of the player. |
stat_value |
float | int
|
The value of the stat. |
stat_type_abbreviation |
str
|
Abbreviation of the stat type. |
description |
str
|
A description of the stat. |
name |
str
|
The name of the stat (e.g., 'home runs', 'strikeouts'). |
type |
str
|
The type of stat (e.g., 'single', 'accumulated'). |
per_game_value |
float | None
|
The value per game, if available. |
rank |
int | None
|
The player's rank in the stat category. |
Methods:
Name | Description |
---|---|
__repr__ |
Returns a string representation of the Stat instance, including the stat name, season, and value. |
_set_stats_data |
Extracts and sets the statistical attributes from the provided JSON data. |
Source code in pyespn/classes/stat.py
espn_instance
property
PYESPN: the espn client instance associated with the class
__init__(stat_json, espn_instance)
Initializes a Stat instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stat_json
|
dict
|
The JSON object containing the stat data. |
required |
espn_instance
|
PYESPN
|
An instance of the ESPN API client. |
required |
Source code in pyespn/classes/stat.py
__repr__()
Returns a string representation of the Stat instance.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
A formatted string with the stat name, value, and season. |
to_dict()
Converts the Stat instance to its original JSON dictionary.
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
The stats's raw JSON data. |