Skip to main content

Function: player_toi()

player_toi(shifts): Row[]

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

Per-player time on ice from a parsed shifts frame: toi_seconds (sum of start_s - end_s, a countdown clock), num_shifts and avg_shift_s, sorted by toi_seconds descending (ties keep first-seen order; py's tie order is undefined).

Parameters​

shifts​

Row[]

Shift stints from parse_shifts; grouped on (player_id, first_name, last_name).

Returns​

Row[]

One row per player: player_id, first_name, last_name (as in the input), toi_seconds (sum over stints with both start_s and end_s non-null), num_shifts (ALL stints, including ones with a null clock) and avg_shift_s (toi_seconds over the counted stints; null if none). [] for an empty input.

Example​

import { parse_shifts, player_toi } from "sportsdataverse/dist/analytics/hockeytech.js";
const toi = player_toi(parse_shifts(gameshiftsPayload, 42));
toi[0]; // the player with the most ice time

Remarks​

num_shifts and the avg_shift_s denominator differ when a stint has an unparseable start_time / end_time.