Skip to main content

Men's college basketball — additional Python functions — Models and calculators: AssistEvent–build_o

AssistEvent​

AssistEvent(player_code: 'str', count: 'ShotClockStats' = <factory>) -> None

One assist relationship's counts (LineupEventStats.AssistEvent).

Parameters

ParameterTypeDefaultDescription
player_codestrThe other player in the assist event (by code).
countShotClockStats<factory>The assist counts, by shot-clock segment.

AssistInfo​

AssistInfo(counts: 'ShotClockStats' = <factory>, target: 'Optional[list[AssistEvent]]' = None, source: 'Optional[list[AssistEvent]]' = None) -> None

Detailed assist info, split into given/received

(LineupEventStats.AssistInfo).

Parameters

ParameterTypeDefaultDescription
countsShotClockStats<factory>Raw assist statistics.
targetOptional[list[AssistEvent]]NonePlayers "I" assisted, if tracked.
sourceOptional[list[AssistEvent]]NonePlayers who assisted "me", if tracked.

ConferenceId​

ConferenceId(name: 'str') -> None

CBB conference identifier (ConferenceId, ``models/ConferenceId

.scala, AnyVal). **Scope addition** -- the first model consumed by mbb_ncaa_team_parsers.py (TeamIdParser.get_team_triples/build_lineup_cli_array/build_available_team_list``). Appended here (not inserted among the 5a-reviewed classes above) to keep this an additive-only change, matching RosterEntry's precedent.

ConferenceId.is_high_major (the companion object's other member) is NOT ported. It has no call site anywhere in TeamIdParser/TeamScheduleParser (verified: the only other ConferenceId construction sites in the upstream tree are kenpom/TeamParser.scala and BuildIngestPipeline.scala, neither of which is in this port's scope, and neither calls is_high_major either) -- nothing in the ported parsers would exercise it. Noted here rather than silently dropped, matching this module's precedent for other unreferenced companion-object members (see the module docstring's Year.until / Game.Score.by_winner notes).

Parameters

ParameterTypeDefaultDescription
namestrThe unique name of the conference.

CutdownShotEvent​

CutdownShotEvent(loc: 'Optional[ShotLocation]', geo: 'Optional[ShotGeo]', dist: 'Optional[float]', pts: 'int', value: 'int', is_ast: 'Optional[bool]', is_trans: 'Optional[bool]', is_orb: 'Optional[bool]') -> None

A narrowed ShotEvent, keeping only the fields needed once a

shot has been matched to a player/lineup event (CutdownShotEvent). Scope addition -- ported for shape fidelity even though it is dead code in the ENTIRE upstream tree: grepping shows it appears only in its own definition (ShotEvent.scala) and as the never-populated shot_info: Option[CutdownShotEvent] field on PlayerEvent.scala -- it is never constructed anywhere. (PlayByPlayUtils.shot_value is an UNRELATED event_str -> int point-value classifier that merely shares a similar name -- the enrichment pass does NOT produce this type either.) Appended here (not inserted among the 5a-reviewed classes above) to keep this an additive-only change, matching RosterEntry/ConferenceId's precedent.

Parameters

ParameterTypeDefaultDescription
locOptional[ShotLocation]The shot's court location, in feet, if known.
geoOptional[ShotGeo]The shot's synthetic lat/lon, if known.
distOptional[float]The shot's distance from the basket, in feet, if known.
ptsintThe point value if made (2/3), else 0.
valueintThe shot's attempt value (2/3), regardless of make/miss.
is_astOptional[bool]Whether the shot was assisted, if known.
is_transOptional[bool]Whether the shot was in transition, if known.
is_orbOptional[bool]Whether the shot followed an offensive rebound, if known.

Direction​

Direction(*values)

Which team is in possession (RawGameEvent.Direction).

FieldGoalStats​

FieldGoalStats(attempts: 'ShotClockStats' = <factory>, made: 'ShotClockStats' = <factory>, ast: 'Optional[ShotClockStats]' = None) -> None

Field-goal counting stats (LineupEventStats.FieldGoalStats).

Parameters

ParameterTypeDefaultDescription
attemptsShotClockStats<factory>Shot attempts, successful or not.
madeShotClockStats<factory>Successful shot attempts.
astOptional[ShotClockStats]NoneSuccessful shot attempts that were assisted, if tracked.

LeagueConstants​

LeagueConstants(hfa: 'float', margin_sd: 'float', em_scale: 'float', avg_tempo: 'float', avg_efficiency: 'float', quad_thresholds: 'dict[str, dict[str, int]]', bubble_adj_em: 'float', in_game_wp_artifact: 'str') -> None

Per-league fitted constants for the prediction & tournament stack.

Algorithms in the stack are league-agnostic; every men's/women's-specific number lives here so a WBB caller is a by-reference shim plus this table (the same pattern wbb_rapm / wbb_ratings already use).

Parameters

ParameterTypeDefaultDescription
hfafloatHome-court advantage in points (fitted on the 2024 backtest).
margin_sdfloatStd. dev. of the game-margin residual (fitted on the 2024 backtest; the Brier-minimizing sigma agrees to within 0.04).
em_scalefloatSlope applied to the AdjEM difference when predicting a game margin. AdjEM is per-100-possessions, so a game margin scales by ~tempo/100 (~0.67); the fitted value is lower still because the as-of AdjEM estimate is noisy and the optimal predictive slope is attenuated (regression dilution). Fitted jointly with hfa.
avg_tempofloatLeague baseline possessions per game (adjusted-tempo anchor).
avg_efficiencyfloatLeague baseline points per 100 possessions.
quad_thresholdsdict[str, dict[str, int]]NET-style quadrant opponent-rank upper bounds, keyed by venue (home / neutral / away) then q1 / q2 / q3 (Quad 4 is any opponent ranked worse than q3).
bubble_adj_emfloatAdjEM of a bubble-quality team on THIS engine's scale (mean of engine ranks 40-50 on the fit season) -- the WAB baseline.
in_game_wp_artifactstrFilename of the bundled in-game-WP coefficients under sportsdataverse/mbb/models (fitted + committed in Phase 3).

LineupEvent​

LineupEvent(date: 'datetime', location_type: 'LocationType', start_min: 'float', end_min: 'float', duration_mins: 'float', score_info: 'ScoreInfo', team: 'TeamSeasonId', opponent: 'TeamSeasonId', lineup_id: 'LineupId', players: 'list[PlayerCodeId]', players_in: 'list[PlayerCodeId]', players_out: 'list[PlayerCodeId]', raw_game_events: 'list[RawGameEvent]', team_stats: 'LineupEventStats', opponent_stats: 'LineupEventStats', player_count_error: 'Optional[int]' = None) -> None

A portion of a game during which a given lineup was on the floor

(LineupEvent).

Parameters

ParameterTypeDefaultDescription
datedatetimeThe date of the game.
location_typeLocationTypeHome/away/neutral (etc.) for this game.
start_minfloatThe point in the game at which the lineup entered.
end_minfloatThe point in the game at which the lineup changed.
duration_minsfloatThe duration of the lineup.
score_infoScoreInfoThe score differential context for this event.
teamTeamSeasonIdThe team under analysis.
opponentTeamSeasonIdThe opposing team.
lineup_idLineupIdA string that defines the set of players on the floor.
playerslist[PlayerCodeId]Mapping from player code to full identity, for this lineup.
players_inlist[PlayerCodeId]Players who subbed in for this event.
players_outlist[PlayerCodeId]Players who subbed out for this event.
raw_game_eventslist[RawGameEvent]The raw NCAA event strings for both teams.
team_statsLineupEventStatsNumerical stats extracted for the lineup (team side).
opponent_statsLineupEventStatsNumerical stats extracted for the lineup (opponent side).
player_count_errorOptional[int]NoneIf the lineup is "impossible", the number of players actually seen (for analysis purposes).

LineupEventStats​

LineupEventStats(num_events: 'int' = 0, num_possessions: 'int' = 0, fg: 'FieldGoalStats' = <factory>, fg_rim: 'FieldGoalStats' = <factory>, fg_mid: 'FieldGoalStats' = <factory>, fg_2p: 'FieldGoalStats' = <factory>, fg_3p: 'FieldGoalStats' = <factory>, ft: 'FieldGoalStats' = <factory>, orb: 'Optional[ShotClockStats]' = None, drb: 'Optional[ShotClockStats]' = None, to: 'ShotClockStats' = <factory>, stl: 'Optional[ShotClockStats]' = None, blk: 'Optional[ShotClockStats]' = None, assist: 'Optional[ShotClockStats]' = None, ast_rim: 'Optional[AssistInfo]' = None, ast_mid: 'Optional[AssistInfo]' = None, ast_3p: 'Optional[AssistInfo]' = None, foul: 'Optional[ShotClockStats]' = None, player_shot_info: 'Optional[PlayerShotInfo]' = None, pts: 'int' = 0, plus_minus: 'int' = 0) -> None

A lineup event's full counting-stat tree (LineupEventStats).

Only num_events/num_possessions/pts/plus_minus are exercised by the possession builder -- see the module docstring's scope note.

Parameters

ParameterTypeDefaultDescription
num_eventsint0Number of raw events folded into this lineup event.
num_possessionsint0Number of possessions attributed to this lineup event.
fgFieldGoalStats<factory>Overall field-goal stats.
fg_rimFieldGoalStats<factory>Rim field-goal stats.
fg_midFieldGoalStats<factory>Mid-range field-goal stats.
fg_2pFieldGoalStats<factory>2pt field-goal stats.
fg_3pFieldGoalStats<factory>3pt field-goal stats.
ftFieldGoalStats<factory>Free-throw stats.
orbOptional[ShotClockStats]NoneOffensive-rebound stats, if tracked.
drbOptional[ShotClockStats]NoneDefensive-rebound stats, if tracked.
toShotClockStats<factory>Turnover stats.
stlOptional[ShotClockStats]NoneSteal stats, if tracked.
blkOptional[ShotClockStats]NoneBlock stats, if tracked.
assistOptional[ShotClockStats]NoneAssist stats, if tracked.
ast_rimOptional[AssistInfo]NoneRim-shot assist info, if tracked.
ast_midOptional[AssistInfo]NoneMid-range-shot assist info, if tracked.
ast_3pOptional[AssistInfo]None3pt-shot assist info, if tracked.
foulOptional[ShotClockStats]NoneFoul stats, if tracked.
player_shot_infoOptional[PlayerShotInfo]NonePer-player shot-quality info, if tracked.
ptsint0Points scored.
plus_minusint0Point differential while this lineup was on the floor.

Methods

LineupEventStats.empty​

LineupEventStats.empty() -> "'LineupEventStats'"

A fresh all-defaults LineupEventStats.

LineupId​

LineupId(value: 'str') -> None

The set of players on the floor, as an opaque id string

(LineupEvent.LineupId, AnyVal).

Parameters

ParameterTypeDefaultDescription
valuestrThe opaque lineup identifier.

LocationType​

LocationType(*values)

Game location (Game.LocationType).

PlayerCodeId​

PlayerCodeId(code: 'str', id: 'PlayerId', ncaa_id: 'Optional[str]' = None) -> None

A player's within-team-season code paired with their full identity

(LineupEvent.PlayerCodeId).

Parameters

ParameterTypeDefaultDescription
codestrThe player code, unique within the team/season only.
idPlayerIdThe player's globally-unique identity.
ncaa_idOptional[str]NoneThe player's NCAA-issued id, if known.

PlayerEvent​

PlayerEvent(player: 'PlayerCodeId', player_stats: 'LineupEventStats', date: 'datetime', location_type: 'LocationType', start_min: 'float', end_min: 'float', duration_mins: 'float', score_info: 'ScoreInfo', team: 'TeamSeasonId', opponent: 'TeamSeasonId', lineup_id: 'LineupId', players: 'list[PlayerCodeId]', players_in: 'list[PlayerCodeId]', players_out: 'list[PlayerCodeId]', raw_game_events: 'list[RawGameEvent]', team_stats: 'LineupEventStats', opponent_stats: 'LineupEventStats', player_count_error: 'Optional[int]' = None) -> None

A lineup event's stats, narrowed to one player (PlayerEvent). Scope addition

-- deferred by 5a since only ~sportsdataverse.mbb .mbb_ncaa_lineup_enrich.create_player_events (5c.4) returns it. Appended here (not inserted among the 5a-reviewed classes above) to keep this an additive-only change.

Same field shape as LineupEvent with two fields prepended (player, player_stats) -- the Scala builds this via a shapeless.LabelledGeneric HList splice of PlayerEvent's own player/player_stats onto every field of a LineupEvent instance; this port has no generic-programming machinery, so ~sportsdataverse.mbb.mbb_ncaa_lineup_enrich.create_player_events constructs the dataclass directly instead.

SingleEventMeta / event_meta / game_id are NOT ported. PlayerEvent.scala's companion object nests a SingleEventMeta case class, but the two fields that would carry it (event_meta, game_id) are commented out in the Scala source itself -- never part of the live case class, and create_player_events never constructs a SingleEventMeta. Nothing to defer; there is no live field to port.

Parameters

ParameterTypeDefaultDescription
playerPlayerCodeIdThe player this narrowed event describes.
player_statsLineupEventStatsThe player's own numerical stats for this lineup event.
datedatetimeThe date of the game.
location_typeLocationTypeHome/away/neutral (etc.) for this game.
start_minfloatThe point in the game at which the lineup entered.
end_minfloatThe point in the game at which the lineup changed.
duration_minsfloatThe duration of the lineup.
score_infoScoreInfoThe score differential context for this event.
teamTeamSeasonIdThe team under analysis.
opponentTeamSeasonIdThe opposing team.
lineup_idLineupIdA string that defines the set of players on the floor.
playerslist[PlayerCodeId]Mapping from player code to full identity, for this lineup.
players_inlist[PlayerCodeId]Players who subbed in for this event.
players_outlist[PlayerCodeId]Players who subbed out for this event.
raw_game_eventslist[RawGameEvent]The raw NCAA event strings for both teams.
team_statsLineupEventStatsNumerical stats extracted for the lineup (team side).
opponent_statsLineupEventStatsNumerical stats extracted for the lineup (opponent side).
player_count_errorOptional[int]NoneIf the lineup is "impossible", the number of players actually seen (for analysis purposes).

PlayerShotInfo​

PlayerShotInfo(unknown_3pm: 'Optional[tuple[int, int, int, int, int]]' = None, early_3pa: 'Optional[tuple[int, int, int, int, int]]' = None, unast_3pm: 'Optional[tuple[int, int, int, int, int]]' = None, ast_3pm: 'Optional[tuple[int, int, int, int, int]]' = None) -> None

Per-player shot-quality info, keyed by lineup slot

(LineupEventStats.PlayerShotInfo). Each tuple is a fixed-arity 5-slot (one per lineup spot), mirroring the Scala PlayerTuple[Int] = Tuple5[Int, Int, Int, Int, Int] alias.

Parameters

ParameterTypeDefaultDescription
unknown_3pmOptional[tuple[int, int, int, int, int]]None3pt makes of unknown assist status, per slot.
early_3paOptional[tuple[int, int, int, int, int]]NoneEarly-shot-clock 3pt attempts, per slot.
unast_3pmOptional[tuple[int, int, int, int, int]]NoneUnassisted 3pt makes, per slot.
ast_3pmOptional[tuple[int, int, int, int, int]]NoneAssisted 3pt makes, per slot.

PlayerValueConstants​

PlayerValueConstants(pace_baseline: 'float', bubble_recruit_rank: 'int', bundle_prefix: 'str') -> None

Per-league constants for the player-value spine.

Parameters

ParameterTypeDefaultDescription
pace_baselinefloatLeague baseline possessions per game (per-100 scaling).
bubble_recruit_rankintNational recruit rank of a "bubble" high-major rotation player (recruiting-model reference point).
bundle_prefixstrArtifact filename prefix under mbb/models ("mbb" / "wbb").

PossCalcFragment​

PossCalcFragment(shots_made_or_missed: 'int' = 0, liveball_orbs: 'int' = 0, actual_deadball_orbs: 'int' = 0, ft_events: 'int' = 0, ignored_and_ones: 'int' = 0, bad_fouls: 'int' = 0, offsetting_bad_fouls: 'int' = 0, turnovers: 'int' = 0) -> None

Running stats needed to calculate possessions for one lineup event,

one direction at a time (PossessionUtils.PossCalcFragment).

Parameters

ParameterTypeDefaultDescription
shots_made_or_missedint0Count of shot attempts (made or missed).
liveball_orbsint0Count of live-ball offensive rebounds.
actual_deadball_orbsint0Count of dead-ball offensive rebounds.
ft_eventsint0Count of free-throw sets (capped-at-1 flag per set).
ignored_and_onesint0Count of and-one free throws ignored for possession purposes (capped-at-1 flag).
bad_foulsint0Count of technical/flagrant fouls counted against the defending side (capped-at-1 flag).
offsetting_bad_foulsint0Count of technical/flagrant fouls that offset (net zero) rather than counting against either side (capped-at-1 flag).
turnoversint0Count of turnovers.

PossessionEvent​

PossessionEvent(dir: 'Direction') -> None

Decomposes RawGameEvent\ s into attacking/defending sides

(RawGameEvent.PossessionEvent).

Parameters

ParameterTypeDefaultDescription
dirDirectionWhich team (Direction.TEAM / Direction.OPPONENT) is currently in possession.

Methods

PossessionEvent.attacking_team​

PossessionEvent.attacking_team(ev: 'RawGameEvent') -> 'Optional[str]'

The event string for the team in possession, or None.

Parameters

ParameterTypeDefaultDescription
evRawGameEventThe raw game event to inspect.

Returns

ev.team if dir is Direction.TEAM, ev.opponent if Direction.OPPONENT, else None.

PossessionEvent.defending_team​

PossessionEvent.defending_team(ev: 'RawGameEvent') -> 'Optional[str]'

The event string for the team NOT in possession, or None.

Parameters

ParameterTypeDefaultDescription
evRawGameEventThe raw game event to inspect.

Returns

ev.team if dir is Direction.OPPONENT, ev.opponent if Direction.TEAM, else None.

PreseasonPrior​

PreseasonPrior(regression: ForwardRef('float'), new_team_quantile: ForwardRef('float'), weight: ForwardRef('float'), rating_sd: ForwardRef('float'))

The college preseason prior and the season sim's rating noise, per league.

Parameters

ParameterTypeDefaultDescription
regressionForwardRef('float')Multiplies a team's prior-season final AdjO / AdjD deviation from the league average (1 carries it over in full, 0 starts everyone average).
new_team_quantileForwardRef('float')A program new to Division I starts at this quantile of last season's Division I AdjEM.
weightForwardRef('float')The prior's weight in pseudo-games: a team with g games so far is rated g / (g + weight) on this season and the rest on the prior.
rating_sdForwardRef('float')The season sim draws one AdjEM shift per team per simulated season, N(0, rating_sd ** 2 / (g + weight)).

RapmConfig​

RapmConfig(...)

Port of RapmConfig (RapmUtils.ts:175-179).

RapmPlayerContext​

RapmPlayerContext(...)

Port of RapmPlayerContext (RapmUtils.ts:147-173).

See the module docstring for why filtered_lineups is a Python callable rather than a materialized dict.

RapmPreProcDiagnostics​

RapmPreProcDiagnostics(...)

Port of RapmPreProcDiagnostics (RapmUtils.ts:187-194) -- the

multi-collinearity diagnostic calc_collinearity_diag returns.

RapmPriorInfo​

RapmPriorInfo(...)

Port of RapmPriorInfo (RapmUtils.ts:124-133).

RapmProcessingInputs​

RapmProcessingInputs(...)

Port of RapmProcessingInputs (RapmUtils.ts:196-203).

See the module docstring for why soln_matrix and sd_rapm are plain nested lists rather than NDArrays, and why sd_rapm exists at all (a Python-only addition beyond upstream's own return shape).

RawGameEvent​

RawGameEvent(min: 'float', team: 'Optional[str]' = None, opponent: 'Optional[str]' = None) -> None

A single NCAA play-by-play event line (LineupEvent.RawGameEvent).

Exactly one of team / opponent is populated per event -- the raw string is the literal "date,time,event" line from the NCAA website.

Parameters

ParameterTypeDefaultDescription
minfloatThe game-clock minute (fractional) this event occurred at.
teamOptional[str]NoneThe raw event string, if this event belongs to the team under analysis.
opponentOptional[str]NoneThe raw event string, if this event belongs to the opponent.

Methods

RawGameEvent.for_opponent​

RawGameEvent.for_opponent(s: 'str', min: 'float') -> "'RawGameEvent'"

Build an opponent-side event (Scala ``RawGameEvent.opponent(s,

min)-- renamed per the "Scala idiom decisions" module note to avoid colliding with theopponent`` field).

Parameters

ParameterTypeDefaultDescription
sstr
minfloat

RawGameEvent.for_team​

RawGameEvent.for_team(s: 'str', min: 'float') -> "'RawGameEvent'"

Build a team-side event (Scala RawGameEvent.team(s, min) -- renamed per the "Scala idiom

decisions" module note to avoid colliding with the team field).

Parameters

ParameterTypeDefaultDescription
sstr
minfloat

RosterEntry​

RosterEntry(player_code_id: 'PlayerCodeId', number: 'str', pos: 'str', height: 'str', height_in: 'Optional[int]', year_class: 'str', gp: 'int', origin: 'Optional[str]', role: 'Optional[str]') -> None

An entry in an NCAA team roster (RosterEntry, ``models/ncaa

/RosterEntry.scala). **Scope addition** -- the first model consumed by the HTML-parser layer (mbb_ncaa_roster_parser.py``). Appended here (not inserted among the 5a-reviewed classes above) to keep this an additive-only change, matching PlayerEvent's precedent.

The trailing role field (present in the Scala case class shape but never populated by RosterParser.parse_roster -- every construction site there, both the real-player and __coach__ branches, passes the literal None for it) is presumably set by a later phase's box-score parser (BoxscoreParser, out of this task's scope); it is carried here for shape fidelity even though the only producer never populates it.

Parameters

ParameterTypeDefaultDescription
player_code_idPlayerCodeIdThe player's code + full identity (the roster-row equivalent of a box-score/PbP player reference).
numberstrThe jersey number, as printed (may be non-numeric text).
posstrThe listed position.
heightstrThe listed height, in "FT-IN" text form (e.g. "6-3").
height_inOptional[int]height parsed to total inches, if it matched height_regex.
year_classstrThe listed academic year ("Fr"/"So"/"Jr"/ "Sr"/etc.).
gpintGames played.
originOptional[str]The player's hometown/prior-school text, if the source table has that column (v1 rosters only).
roleOptional[str]Reserved for a later phase; always None from parse_roster (see above).

Score​

Score(scored: 'int', allowed: 'int') -> None

Points scored / allowed (Game.Score).

Parameters

ParameterTypeDefaultDescription
scoredintPoints scored by the team under analysis.
allowedintPoints scored by the opponent.

ScoreInfo​

ScoreInfo(start: 'Score', end: 'Score', start_diff: 'int', end_diff: 'int') -> None

Score context at the start/end of a lineup event

(LineupEvent.ScoreInfo).

Parameters

ParameterTypeDefaultDescription
startScoreScore at the start of the event.
endScoreScore at the end of the event.
start_diffintScore differential (team - opponent) at the start.
end_diffintScore differential (team - opponent) at the end.

Methods

ScoreInfo.empty​

ScoreInfo.empty() -> "'ScoreInfo'"

A fresh zeroed ScoreInfo (ScoreInfo.empty).

ShotClockStats​

ShotClockStats(total: 'int' = 0, early: 'Optional[int]' = None, mid: 'Optional[int]' = None, late: 'Optional[int]' = None, orb: 'Optional[int]' = None) -> None

Counting stats broken down by shot-clock segment

(LineupEventStats.ShotClockStats).

Parameters

ParameterTypeDefaultDescription
totalint0Count across the entire shot clock.
earlyOptional[int]NoneCount in the first 10s, if tracked.
midOptional[int]NoneCount in the middle 10s, if tracked.
lateOptional[int]NoneCount in the last 10s, if tracked.
orbOptional[int]NoneCount in the first 10s following an offensive rebound, if tracked (else folded into mid/late as normal).

ShotEvent​

ShotEvent(player: 'Optional[PlayerCodeId]', date: 'datetime', location_type: 'LocationType', team: 'TeamSeasonId', opponent: 'TeamSeasonId', is_off: 'bool', lineup_id: 'Optional[LineupId]', players: 'list[PlayerCodeId]', score: 'Score', min: 'float', loc: 'ShotLocation', geo: 'ShotGeo', dist: 'float', pts: 'int', value: 'int', ast_by: 'Optional[PlayerCodeId]', is_ast: 'Optional[bool]', is_trans: 'Optional[bool]', raw_event: 'Optional[str]') -> None

Info about one shot taken during a game, all distances in feet

(ShotEvent). Scope addition -- the model produced by ~sportsdataverse.mbb.mbb_ncaa_shot_parser.create_shot_event_data.

Fields mbb_ncaa_shot_parser.create_shot_event_data (this task) actually populates: player (best-effort -- tidy-resolved + coded for the team under analysis, name-coded only for the opponent), date/location_type/team/opponent (copied from the box-score lineup), is_off, score (re-oriented for home/away/ neutral perspective), min (ascending game-clock time, after phase1_shot_event_enrichment), loc/dist (transformed court coordinates + Euclidean distance from the basket, after the self-correcting flip pass), geo (synthetic lat/lon), raw_event (the SVG <title> text, for debugging).

Fields left as placeholders for the later enrichment pass (PlayByPlayUtils/ShotEnrichmentUtils): lineup_id (always None here -- "discard if bad lineup" per the Scala comment, filled in once the shot is matched against an actual on-floor lineup), players (always [] here -- filled in from the matched lineup), pts (not the real point value -- this task only sets it to 1/0 for made/missed, matching the Scala's own // (enrich in final phase) comment; the real 2pt/3pt value comes from PlayByPlayUtils.shot_value), value (always 0 here, same "final phase" note), ast_by/is_ast/is_trans (always None here -- assist/ transition attribution needs the play-by-play cross-reference that the enrichment pass builds).

Parameters

ParameterTypeDefaultDescription
playerOptional[PlayerCodeId]The shooting player's code + identity, if resolved (None is never actually produced by this task's parser, but the type allows for it per the Scala Option).
datedatetimeThe date of the game.
location_typeLocationTypeHome/away/neutral (etc.) for this game.
teamTeamSeasonIdThe team under analysis.
opponentTeamSeasonIdThe opposing team.
is_offboolWhether the team under analysis is the one shooting.
lineup_idOptional[LineupId]The on-floor lineup id, if/when matched (see above).
playerslist[PlayerCodeId]The on-floor lineup's players, if/when matched (see above).
scoreScoreThe score at the time of the shot, team-oriented.
minfloatThe ascending game-clock time (minutes) of the shot.
locShotLocationThe shot's transformed court location, in feet.
geoShotGeoThe shot's synthetic lat/lon.
distfloatThe shot's distance from the basket, in feet.
ptsintMade(1)/missed(0) flag from this task -- NOT the real point value (see above).
valueintAlways 0 from this task (see above).
ast_byOptional[PlayerCodeId]The assisting player, if/when matched (see above).
is_astOptional[bool]Whether the shot was assisted, if/when matched (see above).
is_transOptional[bool]Whether the shot was in transition, if/when matched (see above).
raw_eventOptional[str]The raw SVG <title> text this shot was parsed from, for debugging (discarded before writing to disk upstream).

ShotGeo​

ShotGeo(lat: 'float', lon: 'float') -> None

A shot's synthetic lat/lon, for geo-aware visualization tooling

(ShotEvent.ShotGeo). Scope addition -- flattened per ShotLocation's note.

Parameters

ParameterTypeDefaultDescription
latfloatSynthetic latitude (feet-to-meters converted, offset from an arbitrary base point -- not a real-world location).
lonfloatSynthetic longitude, same convention as lat.

ShotLocation​

ShotLocation(x: 'float', y: 'float') -> None

A shot's court-relative coordinates, in feet (ShotEvent.ShotLocation). Scope addition --

flattened out of the Scala ShotEvent companion object per this module's established nested-object-flattening precedent (see the module docstring's "Scala idiom decisions": ScoreInfo/PlayerCodeId were already flattened out of LineupEvent's companion the same way).

Parameters

ParameterTypeDefaultDescription
xfloatFeet from the basket; positive is to the right of the basket (facing the goal), negative is to the left.
yfloatFeet from the basket along the baseline-perpendicular axis.

TeamId​

TeamId(name: 'str') -> None

CBB team identifier (TeamId, TeamId.scala, AnyVal).

Parameters

ParameterTypeDefaultDescription
namestrThe unique team name.

TeamSeasonId​

TeamSeasonId(team: 'TeamId', year: 'Year') -> None

A team's season identifier (TeamSeasonId, TeamSeasonId.scala).

Parameters

ParameterTypeDefaultDescription
teamTeamIdThe team playing the season.
yearYearThe year the season ends.

Year​

Year(value: 'int') -> None

CBB season, named by the year it ends (Year, Year.scala).

Parameters

ParameterTypeDefaultDescription
valueintThe ending year of the season.

adjust_efficiency​

adjust_efficiency(game_eff: 'pl.DataFrame', *, league: 'str' = 'mens', max_iter: 'int' = 100, tol: 'float' = 0.0001, prior: 'pl.DataFrame | None' = None, prior_weight: 'float' = 0.0) -> 'pl.DataFrame'

Iterative opponent-adjusted efficiency -> AdjO / AdjD / AdjEM per team-season.

KenPom-style fixed point: initialise adj_o = raw_o / adj_d = raw_d, then repeatedly recompute each team's rating from its games with the opponent's current adjusted rating and a home-court adjustment removed, until the largest change is below tol. Ratings are computed independently per season (a team's opponent pool is within-season).

The per-game offensive update is off_eff - (adj_d_opp - avg) - loc_o where loc_o is +hfa/2 at home, -hfa/2 away, 0 neutral (defense is symmetric with the opposite sign); avg is the league mean efficiency and hfa comes from ~sportsdataverse.mbb.mbb_prediction_constants.get_constants.

Parameters

ParameterTypeDefaultDescription
game_effDataFrameOutput of raw_game_efficiency.
leaguestr'mens'"mens" / "womens" -- selects the HFA constant.
max_iterint100Maximum fixed-point iterations.
tolfloat0.0001Convergence tolerance on the largest rating change.
priorDataFrame | NoneNoneOptional preseason prior in PRIOR_SCHEMA (preseason_prior): each listed team is shrunk toward its prior as if it had played prior_weight extra games at that rating. A listed team with no game yet comes back at its prior (games 0, raw rates null), and a season in prior with no game at all is rated from the prior alone.
prior_weightfloat0.0Pseudo-games of prior per team (0 turns the prior off).

Returns

One row per (season, team_id): season, team_id, adj_o, adj_d, adj_em, raw_o, raw_d, games. Empty input (and no prior) returns that schema with zero rows.

col_nametypedescription
seasonInt64Season year.
team_idStringUnique team identifier.
adj_oFloat64Adj o.
adj_dFloat64Adj d.
adj_emFloat64Adj em.
raw_oFloat64Raw o.
raw_dFloat64Raw d.
gamesInt64Games played.

Example

from sportsdataverse.mbb.mbb_team_ratings import adjust_efficiency, raw_game_efficiency
ratings = adjust_efficiency(raw_game_efficiency(sched, box))

adjust_off_rating_stats​

adjust_off_rating_stats(pts_correction_factor: 'float', poss_correction_factor: 'float', mutable_o_rtg: 'ORtgDiagnostics', maybe_raw_o_rtg: 'float | None') -> 'tuple[float, float] | None'

Apply a missing-possession correction factor to an ORtgDiagnostics dict in place.

Faithful port of RatingUtils.adjustOffRatingStats (RatingUtils.ts:993-1033). Genuinely public upstream (called from LineupTableUtils.ts after a lineup-level pts/poss reconciliation), so this port is public too. Recomputes the productivity fields via build_productivity (reused, not re-derived).

Landmine 4 (see module docstring): the o_adj = avgEff / defSos or 1 recomputation here is unguarded against defSos == 0 -- same reachability analysis as landmine 3 (only reachable if the diagnostics dict's original build_o_rtg call used avg_efficiency == 0).

Parameters

ParameterTypeDefaultDescription
pts_correction_factorfloatPoints correction factor (e.g. team pts / sum of player pts, capped to [0.95, 1.05] by callers).
poss_correction_factorfloatPossession correction factor, same shape.
mutable_o_rtgORtgDiagnosticsThe ORtgDiagnostics dict to mutate in place (oRtg, Usage, adjORtg, adjORtgPlus, Usage_Bonus, SoS_Bonus, adjPtsFactor, adjPossFactor, and (conditionally) Raw_Usage are all updated).
maybe_raw_o_rtgfloat | NoneThe un-overridden raw oRtg value (rawORtg's .value, or None when no override was in play), used to compute the raw-side return.

Returns

(new_raw_o_rtg, raw_adj_o_rtg_plus) when both mutable_o_rtg["Raw_Usage"] and maybe_raw_o_rtg are not None; otherwise None (.isNilsemantics -- an explicit0` does NOT count as nil).

Example

from sportsdataverse.mbb.mbb_ratings import build_o_rtg, adjust_off_rating_stats

_, _, raw_o_rtg, _, o_diags = build_o_rtg(player, {}, {}, 100.0, True, False)
maybe_raw = raw_o_rtg["value"] if raw_o_rtg else None
adjust_off_rating_stats(1.1, 0.9, o_diags, maybe_raw)
print(o_diags["oRtg"], o_diags["adjORtgPlus"])

adjust_tempo​

adjust_tempo(game_eff: 'pl.DataFrame', *, league: 'str' = 'mens', max_iter: 'int' = 100, tol: 'float' = 0.0001) -> 'pl.DataFrame'

Opponent-adjusted tempo (possessions/40) per team-season.

Same fixed point as adjust_efficiency, applied to game possessions under the additive model poss = tempo_i + tempo_j - avg: a team's tempo is recovered by removing its opponents' current adjusted tempo. avg is the league baseline tempo from ~sportsdataverse.mbb.mbb_prediction_constants.get_constants.

Parameters

ParameterTypeDefaultDescription
game_effDataFrameOutput of raw_game_efficiency.
leaguestr'mens'"mens" / "womens" -- selects the tempo baseline.
max_iterint100Maximum fixed-point iterations.
tolfloat0.0001Convergence tolerance on the largest tempo change.

Returns

One row per (season, team_id): season, team_id, adj_tempo. Empty input returns that schema with zero rows.

col_nametypedescription
seasonInt64Season year.
team_idStringUnique team identifier.
adj_tempoFloat64

Example

from sportsdataverse.mbb.mbb_team_ratings import adjust_tempo, raw_game_efficiency
tempo = adjust_tempo(raw_game_efficiency(sched, box))

aggregate_player_seasons​

aggregate_player_seasons(seasons: "'list[int]'", *, league: 'str' = 'mens') -> 'pl.DataFrame'

Canonical per-player-season counting frame from the boxscore release.

Sums the per-game player boxscores into one row per (player_id, season, team_id) with the counting columns player_per100_features expects. Only rows with minutes are counted, and a row with minutes but no athlete (one per league in 2014) is dropped rather than kept as a null player_id. Shot-location splits come from the shots release (2025+): free throws (MadeFreeThrow) are excluded, layup/dunk/tip = rim, and jump shots split three vs mid by score_value (the release's type_text carries no three-point marker; score_value is populated on misses too). For seasons without shots data, three-point attempts come from the box and all remaining attempts fold into fga_mid.

Parameters

ParameterTypeDefaultDescription
seasonslist[int]Seasons to aggregate.
leaguestr'mens'"mens" or "womens".

Returns

One row per (player_id, season, team_id): player_id:Utf8, season, team_id:Utf8, player, position, minutes, games, starter_share (the share of his box rows marked starter) + the counting columns + fga_rim, fga_mid, fga_three. Empty input returns zero rows.

col_nametypedescription
seasonInt64Season year.
team_idStringUnique team identifier.
playerStringPlayer name.
positionStringListed roster position (G, F, C, etc.).
minutesFloat64Minutes played, formatted MM:SS (V3 PT-duration parsed) or decimal minutes (V2).
field_goals_madeFloat64Field goals made (2-pt + 3-pt).
field_goals_attemptedFloat64Field goal attempts (2-pt + 3-pt).
three_point_field_goals_madeFloat64Three-point field goals made.
three_point_field_goals_attemptedFloat64Three-point field goal attempts.
free_throws_madeFloat64Free throws made.
free_throws_attemptedFloat64Free throw attempts.
offensive_reboundsFloat64Offensive rebounds.
defensive_reboundsFloat64Defensive rebounds.
assistsFloat64Total assists.
stealsFloat64Total steals.
blocksFloat64Total blocks.
turnoversFloat64Total turnovers.
pointsFloat64Points scored.
player_idStringUnique player identifier.
fga_rimFloat64Rim field-goal attempts (layups, dunks, tips), the player's whole-season count from the shots release, so a player with rows for two teams carries the same count on each; 0 in seasons without shots data.
fga_midFloat64Mid-range field-goal attempts (non-rim twos), the player's whole-season count from the shots release, so a player with rows for two teams carries the same count on each; in seasons without shots data, the row's box two-point attempts.
fga_threeFloat64Three-point field-goal attempts, the player's whole-season count from the shots release, so a player with rows for two teams carries the same count on each; in seasons without shots data, the row's box three-point attempts.
gamesInt64Games played.
starter_shareFloat64Share of the player's positive-minute box-score rows for the team-season, among those with a known starter flag, that mark them a starter (0-1); null when the box release has no starter column.

Example

from sportsdataverse.mbb.mbb_player_value_constants import (
aggregate_player_seasons, player_per100_features,
)
feats = player_per100_features(aggregate_player_seasons([2025]))

apply_weak_priors​

apply_weak_priors(field: 'str', player_poss_pcts: 'list[float]', prior_info: 'RapmPriorInfo', debug_mode: 'bool' = False) -> 'Callable[[float, list[float]], list[float]]'

Build a closure that nudges ridge-regressed RAPM back towards its weak prior.

Faithful port of RapmUtils.applyWeakPriors (RapmUtils.ts:921-995). Ridge regression depresses estimates towards 0; this "fills" the team-total error (see pick_ridge_regression's [IMPORTANT-EQUATION-01] team-total reconciliation) back in using each player's weak (KenPom-derived) prior as the fallback signal, capped so no more than half the team-total error gets attributed via this path (max_multiplier = -0.5) -- an alternate flat-translation path (use_alt_rating) kicks in for off_adj_ppp/def_adj_ppp fields when the capped path can't fully explain the error.

Parameters

ParameterTypeDefaultDescription
fieldstrThe prior key to read off each prior_info["players_weak"] entry, e.g. "off_adj_ppp".
player_poss_pctslist[float]Per-player possession-share weights (index-aligned with prior_info["players_weak"]), e.g. pick_ridge_regression's own pct_by_player[off_or_def].
prior_infoRapmPriorInfoA RapmPriorInfo (only ["players_weak"] is read).
debug_modeboolFalseKept for TS signature parity -- upstream gates a console.log behind this flag (RapmUtils.ts:979-984), which this port deliberately does not reproduce: every production call site pins it False (offDefDebugMode.off/.def are hardcoded False constants inside pickRidgeRegression), so it is dead in every current caller and would only ever emit console noise, not test-observable behavior.

Returns

A closure (error, base_results) -> adjusted_results -- call it with the team-total efficiency error and the pre-adjustment RAPM vector to get the weak-prior-nudged result.

Example

from sportsdataverse.mbb.mbb_rapm import apply_weak_priors

nudge = apply_weak_priors("off_adj_ppp", pct_by_player, ctx["prior_info"])
adjusted = nudge(adj_eff_err_pre_prior, results_pre_prior)

as_of_ratings_split​

as_of_ratings_split(results: 'pl.DataFrame', cutoff_date: 'datetime.date') -> 'pl.DataFrame'

Filter a results frame to games strictly before a cutoff date (leakage boundary).

Parameters

ParameterTypeDefaultDescription
resultsDataFrameA polars.DataFrame with a date column.
cutoff_datedateGames on or after this date are excluded.

Returns

A polars.DataFrame containing only rows with date < cutoff_date.

col_nametypedescription
idInt64Id.
uidStringESPN UID string.
attendanceFloat64Reported attendance.
time_validBooleanTime valid.
neutral_siteBooleanNeutral site.
conference_competitionBooleanConference competition.
play_by_play_availableBoolean
recentBooleanRecent.
start_dateStringStart date (YYYY-MM-DD).
notes_typeStringNotes type.
notes_headlineStringNotes headline.
broadcast_marketStringBroadcast market label (e.g. 'national', 'home').
broadcast_nameStringBroadcast name.
type_idInt64Type identifier (numeric).
type_abbreviationStringType abbreviation.
venue_idInt64Unique venue identifier.
venue_full_nameStringVenue full name.
venue_address_cityStringVenue address city.
venue_address_stateStringVenue address state / region.
venue_indoorBooleanTRUE if the venue is indoors.
status_clockFloat64Status clock.
status_display_clockStringStatus display clock.
status_periodFloat64Status period.
status_type_idInt64Unique identifier for status type.
status_type_nameStringStatus type name.
status_type_stateStringStatus type state.
status_type_completedBooleanStatus type completed.
status_type_descriptionStringStatus type description.
status_type_detailStringStatus type detail.
status_type_short_detailStringStatus type short detail.
format_regulation_periodsFloat64Format regulation periods.
home_team_idInt64Unique identifier for the home team.
home_uidStringHome team's uid.
home_locationStringHome team's location.
home_nameStringHome name.
home_abbreviationStringHome team's abbreviation.
home_display_nameStringHome display name.
home_short_display_nameStringHome short display name.
home_colorStringColor code (hex) for home.
home_alternate_colorStringColor code (hex) for home alternate.
home_is_activeBooleanHome team's is active.
home_venue_idInt64Unique identifier for home venue.
home_logoStringHome team logo URL.
home_conference_idInt64Unique identifier for home conference.
home_scoreInt64Home team score at the time of the play.
home_winnerBooleanHome team's winner.
home_current_rankFloat64
home_linescoresString
home_recordsString
away_team_idInt64Unique identifier for the away team.
away_uidStringAway team's uid.
away_locationStringAway team's location.
away_nameStringAway name.
away_abbreviationStringAway team's abbreviation.
away_display_nameStringAway display name.
away_short_display_nameStringAway short display name.
away_colorStringColor code (hex) for away.
away_alternate_colorStringColor code (hex) for away alternate.
away_is_activeBooleanAway team's is active.
away_venue_idInt64Unique identifier for away venue.
away_logoStringAway team logo URL.
away_conference_idInt64Unique identifier for away conference.
away_scoreInt64Away team score at the time of the play.
away_winnerBooleanAway team's winner.
away_current_rankFloat64
away_linescoresString
away_recordsString
game_idInt64Unique game identifier.
seasonInt64Season year.
season_typeInt64Season type (1=pre-season, 2=regular season, 3=postseason, 4=off-season for ESPN; or string label for WNBA Stats).
status_type_alt_detailStringStatus type alt detail.
tournament_idInt64ESPN tournament identifier.
groups_idInt64Unique identifier for groups.
groups_nameStringGroups name.
groups_short_nameStringGroups short name.
groups_is_conferenceBooleanGroups is conference.
game_jsonBoolean
game_json_urlString
game_date_timeStringGame start date/time (ISO 8601).
dateStringDate in YYYY-MM-DD format.
PBPBoolean
team_boxBooleanTeam box.
player_boxBooleanPlayer box.

Example

import datetime as dt
from sportsdataverse._common.metrics import as_of_ratings_split
as_of_ratings_split(results, dt.date(2023, 9, 8))

as_of_season_split​

as_of_season_split(df: 'pl.DataFrame', target_season: 'int') -> 'pl.DataFrame'

Rows strictly before target_season -- the leakage boundary.

Parameters

ParameterTypeDefaultDescription
dfDataFrameFrame with an integer season column.
target_seasonintThe season being predicted; its rows (and later) drop.

Returns

The subset with season < target_season.

col_nametypedescription
seasonInt64Season year.
team_idStringUnique team identifier.
playerStringPlayer name.
positionStringListed roster position (G, F, C, etc.).
minutesFloat64Minutes played, formatted MM:SS (V3 PT-duration parsed) or decimal minutes (V2).
field_goals_madeFloat64Field goals made (2-pt + 3-pt).
field_goals_attemptedFloat64Field goal attempts (2-pt + 3-pt).
three_point_field_goals_madeFloat64Three-point field goals made.
three_point_field_goals_attemptedFloat64Three-point field goal attempts.
free_throws_madeFloat64Free throws made.
free_throws_attemptedFloat64Free throw attempts.
offensive_reboundsFloat64Offensive rebounds.
defensive_reboundsFloat64Defensive rebounds.
assistsFloat64Total assists.
stealsFloat64Total steals.
blocksFloat64Total blocks.
turnoversFloat64Total turnovers.
pointsFloat64Points scored.
player_idStringUnique player identifier.
fga_rimFloat64
fga_midFloat64
fga_threeFloat64

Example

from sportsdataverse.mbb.mbb_player_value_constants import as_of_season_split
prior = as_of_season_split(df, 2026)

bootstrap_ari​

bootstrap_ari(fit_fn: "'Callable[[np.ndarray], tuple[np.ndarray, np.ndarray]]'", X: 'np.ndarray', n_boot: 'int' = 20, seed: 'int' = 0) -> 'float'

Cluster stability: mean ARI between the full fit and bootstrap refits.

Parameters

ParameterTypeDefaultDescription
fit_fnCallable[[ndarray], tuple[ndarray, ndarray]]X -> (centers, labels) (e.g. a seeded kmeans_fit partial).
XndarrayFeature matrix.
n_bootint20Bootstrap resamples.
seedint0RNG seed.

Returns

Mean adjusted Rand index of the resample fits' assignments (of the FULL sample, via nearest refit center) vs the full-fit labels.

Example

from functools import partial
score = bootstrap_ari(lambda Z: kmeans_fit(Z, 8, seed=0), Z, n_boot=20, seed=0)

brier_score​

brier_score(y_true: 'np.ndarray', p_pred: 'np.ndarray') -> 'float'

Mean squared error between predicted probabilities and binary outcomes.

Parameters

ParameterTypeDefaultDescription
y_truendarrayArray of binary outcomes (0/1).
p_predndarrayArray of predicted probabilities in [0, 1].

Returns

The Brier score (0.0 is a perfect forecast).

Example

import numpy as np
from sportsdataverse._common.metrics import brier_score
brier_score(np.array([1, 0]), np.array([0.9, 0.1]))

build_d_rtg​

build_d_rtg(stat_set: 'LineupStatSet | None', avg_efficiency: 'float', calc_diags: 'bool', override_adjusted: 'bool') -> 'tuple[dict[str, float] | None, dict[str, float] | None, dict[str, float] | None, dict[str, float] | None, DRtgDiagnostics | None]'

Individual defensive rating (Dean-Oliver DRtg) + diagnostics.

Faithful port of RatingUtils.buildDRtg (RatingUtils.ts:1252-1485). Mirrors build_o_rtg's structure (stat_get closure, calc_diags/override_adjusted flag pair, recursive un-overridden raw-value pass) over the simpler (stat_set, avg_efficiency, calc_diags, override_adjusted) 4-arg signature (no roster/extra-team-stat args, confirmed against the TS).

Parameters

ParameterTypeDefaultDescription
stat_setLineupStatSet | NoneThe player's stat dict. None returns an all-None 5-tuple (RatingUtils.ts:1264-1265's if (!statSet) -- null/undefined only). Unlike build_o_rtg, an empty dict computes cleanly -- every division in buildDRtg is guard-ternary'd (see the module docstring's "Contrast" note), so {} does not raise ZeroDivisionError.
avg_efficiencyfloatLeague/context average efficiency (100 in every vendored jest call).
calc_diagsboolWhen True, populate the 5th tuple slot (DRtgDiagnostics); otherwise it is None.
override_adjustedboolWhen True, apply _build_def_overrides to the raw opponent-FGM/points fields before computing, and additionally recurse once (with calc_diags=False, override_adjusted=False) to compute the un-overridden "raw" values for the 3rd/4th tuple slots.

Returns

A 5-tuple (d_rtg, adj_d_rtg, raw_d_rtg, raw_adj_d_rtg, d_rtg_diags): - d_rtg: {"value": DRtg} when Opponent_Possessions_Box > 0, else None. - adj_d_rtg: {"value": Adj_DRtgPlus} under the same guard. - raw_d_rtg / raw_adj_d_rtg: the un-overridden values from the recursive call when override_adjusted=True; None otherwise (unlike build_o_rtg, there is no internal-usage special case here -- the TS destructures only the first 2 slots of the recursive 5-tuple). - d_rtg_diags: the full DRtgDiagnostics dict (None unless calc_diags=True).

Example

from sportsdataverse.mbb.mbb_ratings import build_d_rtg

d_rtg, adj_d_rtg, _, _, diags = build_d_rtg(player, 100.0, True, False)
print(d_rtg["value"], diags["dRtg"])

# Override-adjusted (manual 3P-defense-% override applied)

d_rtg2, adj_d_rtg2, raw_d_rtg2, raw_adj_d_rtg2, _ = build_d_rtg(
player, 100.0, False, True,
)

build_mbb_season_wp​

build_mbb_season_wp(season: 'int', *, league: 'str' = 'mens', return_as_pandas: 'bool' = False) -> "Union[pl.DataFrame, 'pd.DataFrame']"

A season's play-by-play with win-probability columns joined in.

Loads the season's play-by-play, schedule, and team boxscores, builds a leakage-free weekly as-of pregame anchor per game, scores every play through the bundled in-game win-probability artifact, and returns the full load_mbb_pbp frame with pregame_home_prob + home_win_prob appended -- the enrich-in-place shape that overwrites the season's play_by_play_<season>.parquet release asset.

Parameters

ParameterTypeDefaultDescription
seasonintSeason year (e.g. 2024); bounded by load_mbb_pbp release availability (>= 2002).
leaguestr'mens'"mens" or "womens" (selects the loaders + constants).
return_as_pandasboolFalseReturn a pandas DataFrame instead of polars.

Returns

The season's load_mbb_pbp frame (every column preserved) with the two _WP_COLS appended (both Float64), sorted by game_id then game_play_number.

col_nametypedescription
game_play_numberInt64Sequential play number within the game.
idInt64Id.
sequence_numberInt64Sequence number representing a shot-possession (V3 PBP).
type_idInt64Type identifier (numeric).
type_textStringDisplay text for the type field.
textStringText description of the play / record.
away_scoreInt64Away team score at the time of the play.
home_scoreInt64Home team score at the time of the play.
period_numberInt64Numeric period (1-4 for quarters; 5+ for OT).
period_display_valueStringPeriod display label (e.g. '1st Quarter', 'OT').
clock_display_valueStringGame clock display string (e.g. '8:32').
scoring_playBooleanTRUE if the play resulted in points scored.
score_valueInt64Point value of the play (2 / 3 / 1).
team_idInt64Unique team identifier.
athlete_id_1Int64Primary athlete identifier (e.g. shooter).
wallclockStringWallclock.
shooting_playBooleanTRUE if the play was a shooting attempt.
athlete_id_2Int64Secondary athlete identifier (e.g. assister / fouler).
game_idInt64Unique game identifier.
seasonInt64Season year.
season_typeInt64Season type (1=pre-season, 2=regular season, 3=postseason, 4=off-season for ESPN; or string label for WNBA Stats).
home_team_idInt64Unique identifier for the home team.
home_team_nameStringHome team name.
home_team_mascotStringHome team mascot.
home_team_abbrevStringHome team three-letter abbreviation.
home_team_name_altStringAlternate home team name.
away_team_idInt64Unique identifier for the away team.
away_team_nameStringAway team name.
away_team_mascotStringAway team mascot.
away_team_abbrevStringAway team three-letter abbreviation.
away_team_name_altStringAlternate away team name.
game_spreadFloat64Game spread (signed; positive = home favored).
home_favoriteBooleanTRUE if the home team is the betting favorite.
game_spread_availableBooleanTRUE if a point spread was available.
home_team_spreadFloat64Home team's point spread.
halfInt64Half of the game (1 or 2).
timeStringTime / clock value.
clock_minutesInt64Clock minutes split out for convenience.
clock_secondsInt64Clock seconds split out for convenience.
home_timeout_calledBoolean
away_timeout_calledBoolean
lag_periodInt64
lead_periodInt64
lag_halfInt64A lag column on the half
lead_halfInt64A lead column on the half
start_period_seconds_remainingInt64
start_game_seconds_remainingInt64Seconds remaining in the game at the start of the play.
end_period_seconds_remainingInt64
end_game_seconds_remainingInt64Seconds remaining in the game at the end of the play.
game_dateStringGame date (YYYY-MM-DD).
game_date_timeStringGame start date/time (ISO 8601).
coordinate_xFloat64X coordinate on the court (half-court layout).
coordinate_yFloat64Y coordinate on the court (half-court layout).
coordinate_x_rawFloat64X coordinate as returned by the API before any adjustment.
coordinate_y_rawFloat64Y coordinate as returned by the API before any adjustment.
athlete_name_1String
athlete_name_2String
athlete_name_3String
media_idStringMedia identifier (video / image).
pregame_home_probFloat64
home_win_probFloat64

Example

from sportsdataverse.mbb import build_mbb_season_wp
wp = build_mbb_season_wp(2024)
wp.select("game_id", "game_play_number", "home_win_prob").head()

build_net_points​

build_net_points(player_rapm_and_poss_pct: 'LineupStatSet', ortg: 'ORtgDiagnostics', drtg: 'DRtgDiagnostics', avg_eff: 'float', scale_type: "Literal['T%', 'P%', '/G']", num_games: 'float' = 1, missing_game_adjustment: 'float' = 1) -> 'NetPoints'

Decompose ORtg/DRtg + RAPM into a Net-Points-like breakdown.

Faithful port of RatingUtils.buildNetPoints (RatingUtils.ts:1036-1234). Genuinely public upstream (called from buildLeaderboards.ts, PlayerImpactBreakdownTable.tsx, and ImpactBreakdownUtils.ts), so this port is public too.

Parameters

ParameterTypeDefaultDescription
player_rapm_and_poss_pctLineupStatSetThe player's stat dict -- reads off_team_poss_pct/def_team_poss_pct (nullish-coalesced to 0.0, see _nullish) and, when present, off_adj_rapm/def_adj_rapm (each a {"value": float} "Statistic"-shaped field) for the RAPM "with-or-without-you" (WOWY) deltas.
ortgORtgDiagnosticsAn ORtgDiagnostics dict from build_o_rtg (calc_diags=True), typically with adjPtsFactor/ adjPossFactor overridden from their 1 default by a missing-possession correction.
drtgDRtgDiagnosticsA DRtgDiagnostics dict from build_d_rtg (calc_diags=True). If it carries an onBallDiags key (this port's build_d_rtg never sets one -- see the module docstring's deferred-work note), the on-ball-adjusted branch is used instead of the base dRtg/adjDRtgPlus.
avg_efffloatLeague/context average efficiency.
scale_typeLiteral['T%', 'P%', '/G']"T%" (scale by on-floor team-possession share, avgEff-adjusted possession count), "P%" (scale to 100 possessions), or "/G" (scale to per-game).
num_gamesfloat1Divisor for the "/G" scale type. Default 1.
missing_game_adjustmentfloat1Multiplier folded into the "T%" scale factor for imputed-missing-games correction. Default 1.

Returns

A NetPoints dict -- 20 keys, plus an optional defNetPtsIndiv 21st key present only when drtg["onBallDiags"] is set (TS-verbatim key names throughout).

Example

from sportsdataverse.mbb.mbb_ratings import build_o_rtg, build_d_rtg, build_net_points

_, _, _, _, o_diags = build_o_rtg(player, {}, {}, 100.0, True, False)
_, _, _, _, d_diags = build_d_rtg(player, 100.0, True, False)
net_pts = build_net_points(player, o_diags, d_diags, 100.0, "T%")
print(net_pts["offNetPts"], net_pts["defNetPts"])

build_o_rtg​

build_o_rtg(stat_set: 'LineupStatSet | None', roster_stats_by_code: 'dict[str, LineupStatSet] | None', extra_team_stat_info: 'LineupStatSet', avg_efficiency: 'float', calc_diags: 'bool', override_adjusted: 'bool') -> 'tuple[dict[str, float] | None, dict[str, float] | None, dict[str, float] | None, dict[str, float] | None, ORtgDiagnostics | None]'

Individual offensive rating (Dean-Oliver ORtg) + diagnostics.

Faithful port of RatingUtils.buildORtg (RatingUtils.ts:398-960). See the module docstring for the signature-vs-brief note (this mirrors the TS 6-positional-arg / 5-tuple contract verbatim, snake_cased) and the diagnostics-dict key-naming convention (TS-verbatim, not snake_cased).

Parameters

ParameterTypeDefaultDescription
stat_setLineupStatSet | NoneThe player's LineupStatSet (ES-aggregation-shaped per-player doc, "IndivStatSet" upstream). None returns an all-None 5-tuple (RatingUtils.ts:412-413's if (!statSet) -- null/undefined only). An empty dict does NOT short-circuit ({} is truthy in JS and falls through to compute upstream); in this port it falls into unguarded-division landmine 1 and raises ZeroDivisionError where the TS degrades to a NaN-laced degenerate result -- see the module docstring's landmine list.
roster_stats_by_codedict[str, LineupStatSet] | None{player_code: LineupStatSet} for every player on the roster -- used for the approximate team-ORB apportionment and the per-shot-location assisted-eFG fallback. None is treated as {} (every vendored jest call passes a literal {}).
extra_team_stat_infoLineupStatSet{"total_off_to": {...}, "sum_total_off_to": {...}} -- team-level TOV bookkeeping used to compute "unblamed" team turnovers apportioned by off_team_poss_pct.
avg_efficiencyfloatLeague/context average efficiency (100 in every vendored jest call).
calc_diagsboolWhen True, populate the 5th tuple slot (ORtgDiagnostics); otherwise it is None.
override_adjustedboolWhen True, apply _build_off_overrides to the raw made/attempt/turnover fields before computing, and additionally recurse once (with calc_diags=False, override_adjusted=False) to compute the un-overridden "raw" values for the 3rd/4th tuple slots.

Returns

A 5-tuple (o_rtg, adj_o_rtg, raw_o_rtg, raw_adj_o_rtg, o_rtg_diags): - o_rtg: {"value": ORtg} when TotPoss > 0, else None. - adj_o_rtg: {"value": Adj_ORtgPlus} when TotPoss > 0, else None. - raw_o_rtg: when calc_diags or override_adjusted, the un-overridden ORtg (None if override_adjusted=False, since no un-overridden pass was computed); otherwise a special internal-recursion value {"value": usage} (RatingUtils.ts:835's "if called internally return usage here" case). - raw_adj_o_rtg: the un-overridden adj_o_rtg (None when override_adjusted=False). - o_rtg_diags: the full ORtgDiagnostics dict (None unless calc_diags=True).

Example

from sportsdataverse.mbb.mbb_ratings import build_o_rtg

o_rtg, adj_o_rtg, _, _, diags = build_o_rtg(
player, {}, {"total_off_to": {"value": 0}, "sum_total_off_to": {}},
100.0, True, False,
)
print(o_rtg["value"], diags["oRtg"])

# Override-adjusted (manual shooting-% overrides applied)

o_rtg2, adj_o_rtg2, raw_o_rtg2, raw_adj_o_rtg2, _ = build_o_rtg(
player, {}, {"total_off_to": {"value": 0}, "sum_total_off_to": {}},
100.0, False, True,
)