Skip to main content

Function: helper_nba_player_box()

helper_nba_player_box(final): Row[]

Defined in: src/producers/espn_basketball_box.ts:593

NBA player box (sdv-py nba_player_box.helper_nba_player_box, hoopR helper_espn_nba_player_box): one row per athlete from an ESPN Site v2 summary payload; has plus_minus; lax gate.

Parameters​

final​

any

The ESPN summary payload (final.json) of one game. Reads header.id, header.season.{year,type}, header.competitions[0].{date,competitors} and boxscore.players[].{team,statistics[0].{keys,athletes}}.

Returns​

Row[]

Row[]: one row per athlete, played athletes (with stats) then did-not-play ones, sorted by home_away ("away" before "home", null last); [] when the payload has no usable boxscore.

Throws​

TypeError when header.competitions[0].date is not a string.

Throws​

Error when that date does not parse as %Y-%m-%dT%H:%M[:%S] (a trailing Z is stripped first).

Throws​

RangeError when an id or score is a float inf string (Python int(float("inf"))).

Example​

const summary = await sdv.nba.espnNbaSummary({ event_id: 401360428 });
const box = sdv.nba.helper_nba_player_box(summary);
typeof box[0].athlete_id; // "string" (ids are decimal strings)

Remarks​

Shared by all four leagues (the others @see this block):

  • Column order is WBB's canonical dplyr::select order; NBA / WNBA insert plus_minus right after fouls (kept a string such as "+16"); MBB moves active LAST. Only the columns present in the payload are emitted.
  • Id columns are decimal strings; Int32 stat columns parse only an ASCII [+-]digits string in range (anything else is null); minutes and the *_pct columns are numbers; game_date / game_date_time are Dates (see the module header).
  • Gate: the first team's first athlete must have a stats vector longer than 6 whose 7th entry parses as a float; a stats / athletes count mismatch, a ragged stats vector or missing keys returns [] (R's tryCatch skip). The STRICT gate (MBB, WBB) also requires the second team to ship athletes; the LAX gate (NBA, WNBA) publishes the first team's rows regardless.
  • "M-A" pair stats (fieldGoalsMade-fieldGoalsAttempted etc.) are split in place.
  • reason is emitted only when some athlete entry carries that key.