Skip to main content

Function: backfill_power_play()

backfill_power_play(df): Row[]

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

Back-fill power_play / short_handed ("1"/"0") on shot and faceoff events inside a power-play window: from each PP penalty (power_play == "1") for penalty_length minutes, truncated at the first goal in the window. The first matching window wins; rows outside any window are untouched. Requires sec_from_start (run add_clock_columns first). Quirk kept from py: the "previous window" lookup uses the penalty's index into the (skipping) interval list.

Parameters​

df​

Row[]

Event rows with event, team_id, home_team_id, away_team_id, sec_from_start and, on penalties, power_play ('1' marks a PP penalty) and penalty_length (minutes).

Returns​

Row[]

The rows with power_play / short_handed set to '1' / '0' on every shot or faceoff inside a window (the advantaged team gets power_play = '1', the other short_handed = '1'). Both columns are added (as null) when missing. Rows outside every window, and non-shot / non-faceoff rows, are returned as-is. [] in, [] out.

Example​

import { add_clock_columns, backfill_power_play } from "sportsdataverse/dist/analytics/hockeytech.js";
const rows = backfill_power_play(add_clock_columns(pbpWithTeams));
rows.filter((r) => r.event === "shot" && r.power_play === "1").length;

Remarks​

Row objects outside a window are the SAME objects as the input (not copied); rows inside a window are new objects. The advantaged team is away_team_id when the penalised team_id equals home_team_id, else home_team_id. A penalty without a parsable time or length is skipped, which is what makes the previous-window index lookup a quirk.