wsba_hockey.tools package
Submodules
wsba_hockey.tools.agg module
wsba_hockey.tools.globals module
wsba_hockey.tools.http module
- class wsba_hockey.tools.http.Response(response: Response)[source]
Bases:
objectThe response surface used by wsba_hockey’s synchronous functions.
- property encoding
- property text
- class wsba_hockey.tools.http.ScrapySession[source]
Bases:
objectSynchronous, reusable Scrapy-backed session for package requests.
- wsba_hockey.tools.http.get(url, session=None, **kwargs)[source]
GET through Scrapy, preserving the package’s synchronous API.
- wsba_hockey.tools.http.get_json(url, session=None, **kwargs)[source]
GET and decode JSON, preserving useful upstream error context.
- wsba_hockey.tools.http.make_pooled_session() ScrapySession[source]
Create a reusable Scrapy-backed session.
The session is safe to pass to multiple package scraping functions and can be used as a context manager. Scrapy’s remote-control extension is disabled because this client does not use it.
- wsba_hockey.tools.http.pooled_session() ScrapySession[source]
Return the session cached for the current thread.
wsba_hockey.tools.plotting module
- class wsba_hockey.tools.plotting.WSBAPlot(display_range: str = 'full', rotation: int | None = 0, figsize=(10, 12), facecolor='w', edgecolor='k')[source]
Bases:
object
- wsba_hockey.tools.plotting.apply_primary_colors(df: DataFrame, color_map: dict[str, str], *, team_abbr_col: str = 'event_team_abbr', season_col: str = 'season', out_col: str = 'color', fallback: str = '#1f77b4') DataFrame[source]
- wsba_hockey.tools.plotting.load_teaminfo(info_path: str = '/home/runner/work/wsba_hockey/wsba_hockey/src/wsba_hockey/tools/teaminfo/nhl_teaminfo.csv') DataFrame[source]
- wsba_hockey.tools.plotting.plot_events(pbp: DataFrame, events: list[str], title: str | None = None, marker_dict: dict | None = None, legend: bool = False, display_range: str = 'full', rotation: int | None = 0, figsize=(6.4, 4.8))[source]
- wsba_hockey.tools.plotting.prep_plot_data(pbp, strengths, season_types=2, marker_dict={'blocked-shot': 'v', 'faceoff': 'X', 'giveaway': '1', 'goal': '*', 'hit': 'P', 'missed-shot': 'o', 'shot-on-goal': 'D', 'takeaway': '2'})[source]
wsba_hockey.tools.scraping module
- wsba_hockey.tools.scraping.normalize_json_text(value)[source]
Return a JSON string for a JSON/nested value stored in a text column.
This also upgrades schedule files written by older releases, where a nested Polars value was persisted as its human-readable
Seriesoutput.
- wsba_hockey.tools.scraping.parse_event_sprite(frames: list[dict], home_team_id, away_team_id) DataFrame[source]
- wsba_hockey.tools.scraping.stringify_nested(df: DataFrame) DataFrame[source]
Encode nested columns as JSON strings for portable table exports.
Polars cannot write list or struct columns to CSV, and some Parquet readers handle those types inconsistently. JSON preserves the complete value while keeping the returned frame usable by both formats. Scalar columns are returned unchanged.
wsba_hockey.tools.xg_model module
- wsba_hockey.tools.xg_model.nhl_apply_xG(pbp: DataFrame, states: bool = False) DataFrame[source]
Given play-by-play data, return this data with xG-related columns.
- Parameters:
pbp (pl.DataFrame) – A DataFrame containing play-by-play data generated within the WBSA Hockey package.
states (bool, optional) – If True, recalculate score, Corsi, Fenwick, and penalty states before applying xG. Defaults to False, matching the previous xG module behavior.
- Returns:
A DataFrame containing input play-by-play data with xG column.
- Return type:
pl.DataFrame