Skip to main content

Function: build_on_ice()

build_on_ice(pbp, shifts, goal_epsilon_s?): Row[]

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

Attach on_ice_home / on_ice_away (comma-joined player ids) to every event.

pbp carries integer period_of_game and time_s (seconds REMAINING). A player is on ice iff a shift in that period has start_s >= time_s > end_s (the end is EXCLUSIVE so a line-change instant belongs only to the incoming shift). Goals are evaluated goal_epsilon_s earlier, clamped to the period's first shift start (the shift chart is often already rolled to the post-goal deployment). Ids are the unique Int64s sorted AS STRINGS (so "10" < "9"), exactly as py. Returns the rows with goal time_s shifted (py leaves that column modified).

Parameters​

pbp​

Row[]

Event rows with integer period_of_game and time_s (seconds REMAINING in the period) and, for the goal adjustment, event.

shifts​

Row[]

Shift stints from parse_shifts: period, start_s, end_s (countdown seconds), player_id, home (1 / 0). Stints with a null period or clock are ignored.

goal_epsilon_s?​

number = GOAL_EPSILON_S

Seconds added to a goal's time_s (i.e. moved EARLIER on the countdown clock) before the lookup, clamped to the period's latest shift start. 0 disables the adjustment. Default GOAL_EPSILON_S (2).

Returns​

Row[]

A new array of copied rows with on_ice_home / on_ice_away appended: comma-joined, string-sorted unique player ids, null when no shift of that side matches (or when the event's period / time is unknown). Goal rows also carry the shifted time_s. With an empty pbp or shifts, every row gets null for both columns.

Example​

import { build_on_ice, parse_shifts } from "sportsdataverse/dist/analytics/hockeytech.js";
const shifts = parse_shifts(gameshiftsPayload, 42);
const rows = build_on_ice(eventsWithTimeS, shifts); // default 2 s goal epsilon
const atGoal = build_on_ice(eventsWithTimeS, shifts, 0); // evaluate at the goal instant

Remarks​

on_ice_* is null when NO stint of that side covers the instant; a side with covering stints whose ids are all unparseable gives ''. The id strings are String(toInt(player_id)), so '10' sorts before '9'.