Function: enrich_pbp()
enrich_pbp(
df,league,game_id,opts?):Row[]
Defined in: src/analytics/hockeytech.ts:1019
Enrich a parsed play-by-play (py enrich_pbp, league-generic): game-meta columns,
coordinate transforms, clock columns, power-play back-fill, shot geometry and
on-ice tracking from the shift chart. Pure: pass the payloads in (see module
header for the no-fetch deviation).
Parameters
df
Row[]
Rows from parse_pbp. [] returns [] (py raises here).
league
string
League slug (e.g. 'pwhl'). Accepted for py signature parity; unused.
game_id
unknown
Stamped into the shift rows parsed from shifts_payload (the pbp rows
already carry theirs from parse_pbp).
opts?
EnrichOptions = {}
The gc/gamesummary and modulekit/gameshifts payloads, see
EnrichOptions. Default {}: blank meta, null on-ice.
Returns
Row[]
A new array of copied rows, in input order, with — in this order — the meta
columns game_date, game_season (year from the date, or null), game_season_id,
home_team, home_team_id, away_team, away_team_id (strings, '' when the meta is
missing); the ten add_coord_transforms columns; the four
add_clock_columns columns; power_play / short_handed back-filled by
backfill_power_play; shot_distance, shot_angle, scoring_chance on the
rink-feet frame; and on_ice_home / on_ice_away from build_on_ice (null when
no shifts are given).
Example
import { enrich_pbp, parse_pbp } from "sportsdataverse/dist/analytics/hockeytech.js";
const parsed = parse_pbp(pbpPayload, "hockeytech_a", 42);
const rows = enrich_pbp(parsed, "pwhl", 42, { meta_payload: summary, shifts_payload: shifts });
Remarks
Meta fields resolve by first truthy value: team id from meta.home_team, then
home.id, then home.team_id; date from meta.date_played, game_date_iso_8601,
game_date. For on-ice lookup each period's length is the max shift start_s in that period
(OT is shorter), default 1200, and time_s = length - elapsed. Propagates the Error of
add_clock_columns when a time_of_period has no ':'. Ids stay as the feeds ship
them; the wrappers in hockeytech_family.ts convert them to decimal strings.