Skip to main content

Function: parse_pbp()

parse_pbp(payload, pbp_style?, game_id?): Row[]

Defined in: src/analytics/hockeytech.ts:385

Parse a gameCenterPlayByPlay payload (a list of {event, details}) into one row per event (py parse_pbp). Dialects a/b share one wire format. The feed emits two rows per goal (the goal event + a twin shot with is_goal_twin = true).

Parameters​

payload​

unknown

The raw feed body: an array of { event, details } objects. A non-array yields []; non-object entries are skipped.

pbp_style?​

string = "hockeytech_a"

Coordinate-canvas dialect, 'hockeytech_a' (≈ 850x400, PWHL / AHL) or 'hockeytech_b' (≈ 600x300, OHL / WHL / ...). Default 'hockeytech_a'. Accepted for parity only: both dialects parse identically (py _parse_pbp_b delegates to _parse_pbp_a).

game_id?​

unknown = null

Stamped verbatim into the game_id column. Default null.

Returns​

Row[]

One row per event. Every row carries game_id, event, team_id (string or null), period_of_game, time_of_period (elapsed 'M:SS'), raw x_coord / y_coord, the player_* / goalie_* columns, goal and is_goal_twin. Event-specific columns are added for shot / blocked_shot (event_type, shot_quality, player_team_id), goal (empty_net, game_winner, power_play, assists as player_two_* / player_three_*, plus_player_<one..five>_* / minus_player_*), faceoff (home_win), penalty (penalty_length, event_type, power_play '1'/'0', player_two_* = takenBy) and goalie_change; a column absent on a row is null. Feed order is kept.

Example​

import { parse_pbp } from "sportsdataverse/dist/analytics/hockeytech.js";
const rows = parse_pbp(pbpPayload, "hockeytech_a", 42);
const goals = rows.filter((r) => r.event === "goal");

Remarks​

For a penalty, servedBy is the primary player (player_id) and takenBy the secondary (player_two_*), as in fastRhockey. Never throws.