pyhockey.goalie_games

Main module for returning game-by-game statistics for each goalie.

 1"""
 2Main module for returning game-by-game statistics for each goalie.
 3"""
 4import polars as pl
 5
 6from pyhockey.util.query_table import query_table
 7from pyhockey.util.data_disclaimer import print_data_disclaimer
 8
 9
10# Define custom type for inputs into our queries
11type QueryValue = str | int | float | list[str] | list[int] | list[float]
12
13
14def goalie_games(season: int | list[int] | None = None,
15                 name: str | list[str] | None = None,
16                 team: str | list[str] = 'ALL',
17                 start_date: str | None = None,
18                 end_date: str | None = None,
19                 situation: str | None = None,
20                 quiet: bool = False) -> pl.DataFrame:
21    """ Return goalie-level game-by-game statistics.
22
23    Primary function for returning game-by-game goalie statistics. Accepts one or multiple teams, 
24    one or multiple goalie names, one or multiple seasons, or alternatively, a start- and end-date
25    for which to return game-by-game metrics.
26
27    Args:
28
29        season: 
30            Either one or a list of seasons for which to return all games. Disregarded if both
31            start_date and end_date are also provided, defaults to None
32        name: 
33            Either one or a list of names for which to return stats. Can be a full name, partial
34            name, or just first/last name, defaults to None
35        team: 
36            Either one or a list of teams, provided in 3-letter acronyms, defaults to 'ALL'
37        start_date: 
38            A date from which to return all games on and after that date, in YYYY-MM-DD format, 
39            defaults to None
40        end_date: 
41            A date from which to return all games before and on that date, in YYYY-MM-DD format,
42            defaults to None
43        situation: 
44            Either None (so return everything), or one of 'all', '5on5', '4on5', or '5on4',
45            defaults to None
46        quiet: 
47            If set to True, don't print the data disclaimer, defaults to False
48    
49    Returns:
50
51        A polars DataFrame containing all of the requested data.
52
53    Raises:
54
55        ValueError: An input of either incorrect value or type was provided.
56    """
57
58    if not season and not start_date and not end_date:
59        raise ValueError("No values provided for 'season', 'start_date', or 'end_date'. Must "\
60                         "provide value for at least one of these.")
61
62    qualifers: dict[str, str] = {}
63
64    if start_date:
65        qualifers['start_date'] = start_date
66    if end_date:
67        qualifers['end_date'] = end_date
68
69    column_mapping: dict[str, QueryValue] = {
70        'season': season,
71        'name': name,
72        'team': team,
73        'situation': situation
74    }
75
76    results: pl.DataFrame = query_table(table='goalie_games', column_mapping=column_mapping,
77                                        qualifiers=qualifers, order_by=['team', 'gameDate'])
78
79    if not quiet:
80        print_data_disclaimer(source='NaturalStatTrick')
81
82    return results
type QueryValue = str | int | float | list[str] | list[int] | list[float]
def goalie_games( season: int | list[int] | None = None, name: str | list[str] | None = None, team: str | list[str] = 'ALL', start_date: str | None = None, end_date: str | None = None, situation: str | None = None, quiet: bool = False) -> polars.dataframe.frame.DataFrame:
16def goalie_games(season: int | list[int] | None = None,
17                 name: str | list[str] | None = None,
18                 team: str | list[str] = 'ALL',
19                 start_date: str | None = None,
20                 end_date: str | None = None,
21                 situation: str | None = None,
22                 quiet: bool = False) -> pl.DataFrame:
23    """ Return goalie-level game-by-game statistics.
24
25    Primary function for returning game-by-game goalie statistics. Accepts one or multiple teams, 
26    one or multiple goalie names, one or multiple seasons, or alternatively, a start- and end-date
27    for which to return game-by-game metrics.
28
29    Args:
30
31        season: 
32            Either one or a list of seasons for which to return all games. Disregarded if both
33            start_date and end_date are also provided, defaults to None
34        name: 
35            Either one or a list of names for which to return stats. Can be a full name, partial
36            name, or just first/last name, defaults to None
37        team: 
38            Either one or a list of teams, provided in 3-letter acronyms, defaults to 'ALL'
39        start_date: 
40            A date from which to return all games on and after that date, in YYYY-MM-DD format, 
41            defaults to None
42        end_date: 
43            A date from which to return all games before and on that date, in YYYY-MM-DD format,
44            defaults to None
45        situation: 
46            Either None (so return everything), or one of 'all', '5on5', '4on5', or '5on4',
47            defaults to None
48        quiet: 
49            If set to True, don't print the data disclaimer, defaults to False
50    
51    Returns:
52
53        A polars DataFrame containing all of the requested data.
54
55    Raises:
56
57        ValueError: An input of either incorrect value or type was provided.
58    """
59
60    if not season and not start_date and not end_date:
61        raise ValueError("No values provided for 'season', 'start_date', or 'end_date'. Must "\
62                         "provide value for at least one of these.")
63
64    qualifers: dict[str, str] = {}
65
66    if start_date:
67        qualifers['start_date'] = start_date
68    if end_date:
69        qualifers['end_date'] = end_date
70
71    column_mapping: dict[str, QueryValue] = {
72        'season': season,
73        'name': name,
74        'team': team,
75        'situation': situation
76    }
77
78    results: pl.DataFrame = query_table(table='goalie_games', column_mapping=column_mapping,
79                                        qualifiers=qualifers, order_by=['team', 'gameDate'])
80
81    if not quiet:
82        print_data_disclaimer(source='NaturalStatTrick')
83
84    return results

Return goalie-level game-by-game statistics.

Primary function for returning game-by-game goalie statistics. Accepts one or multiple teams, one or multiple goalie names, one or multiple seasons, or alternatively, a start- and end-date for which to return game-by-game metrics.

Args:

season: 
    Either one or a list of seasons for which to return all games. Disregarded if both
    start_date and end_date are also provided, defaults to None
name: 
    Either one or a list of names for which to return stats. Can be a full name, partial
    name, or just first/last name, defaults to None
team: 
    Either one or a list of teams, provided in 3-letter acronyms, defaults to 'ALL'
start_date: 
    A date from which to return all games on and after that date, in YYYY-MM-DD format, 
    defaults to None
end_date: 
    A date from which to return all games before and on that date, in YYYY-MM-DD format,
    defaults to None
situation: 
    Either None (so return everything), or one of 'all', '5on5', '4on5', or '5on4',
    defaults to None
quiet: 
    If set to True, don't print the data disclaimer, defaults to False

Returns:

A polars DataFrame containing all of the requested data.

Raises:

ValueError: An input of either incorrect value or type was provided.