Enhanced PBP

Ejection

class pbpstats.resources.enhanced_pbp.ejection.Ejection[source]

Bases: object

Class for Ejection events

property event_stats

returns list of dicts with all stats for event

End of Period

class pbpstats.resources.enhanced_pbp.end_of_period.EndOfPeriod[source]

Bases: object

Class for end of period events

property event_stats

returns list of dicts with all stats for event

Enhanced PBP

The EnhancedPbp class has some basic properties for handling enhanced pbp data

class pbpstats.resources.enhanced_pbp.enhanced_pbp.EnhancedPbp(items)[source]

Bases: pbpstats.resources.base.Base

Class for enhanced play-by-play events

Parameters

events (list) – list of EnhancedPbpItem items, typically from a enhanced pbp data loader

property data

returns list of pbp event dicts

property fgas

returns list of FieldGoal events

property fgms

returns list of FieldGoal events with all made FGs

property ftas

returns list of FreeThrow events

property rebounds

returns list of Rebound events

property turnovers

returns list of Turnover events

Enhanced PBP Item

EnhancedPbpItem is an abstract base class for all enhanced pbp event types

class pbpstats.resources.enhanced_pbp.enhanced_pbp_item.EnhancedPbpItem[source]

Bases: object

property base_stats

returns list of dicts with all seconds played and possession count stats for event

property count_as_possession

returns True if event is possession changing event that should count as a real possession, False otherwise.

In order to not include possessions which a very low probability of scoring in possession counts, possession won’t be counted as a possession if it starts with <= 2 seconds left and no points are scored before period ends

property current_players

returns dict with list of player ids for each team with players on the floor for current event

For all non subsitution events current players are just the same as previous event

This gets overwritten in Substitution since those are the only event types where players are not the same as the previous event

abstract property event_stats

returns list of dicts with all stats for event

get_all_events_at_current_time()[source]

returns list of all events that take place as the same time as the current event

abstract get_offense_team_id()[source]

returns team id for team on offense for event

is_penalty_event()[source]

returns True if the team on offense is in the penalty, False otherwise

abstract property is_possession_ending_event

returns True if event ends a possession, False otherwise

is_second_chance_event()[source]

returns True if the event takes place after an offensive rebound on the current possession, False otherwise

property lineup_ids

returns dict with lineup ids for each team for current event. Lineup ids are hyphen separated sorted player id strings.

property score_margin

returns the score margin from perspective of offense team before the event took place

abstract property seconds_remaining

returns seconds remaining in period as a float

property seconds_since_previous_event

returns the number of seconds that have elapsed since the previous event

Field Goal

class pbpstats.resources.enhanced_pbp.field_goal.FieldGoal[source]

Bases: object

Class for field goal events

property distance

returns shot distance in feet

property event_stats

returns list of dicts with all stats for event

property is_and1

returns True if shot was an and 1, False otherwise

property is_assisted

returns True if shot was assisted, False otherwise

property is_blocked

returns True if shot was blocked, False otherwise

property is_corner_3

returns True if shot was a corner 3, False otherwise

property is_heave

returns True if shot was a last second heave, False otherwise

abstract property is_made

returns True if shot was made, False otherwise

property is_make_that_does_not_end_possession

returns True if shot is a made shot that does not end the possession due to a foul, False otherwise

property is_putback

returns True if shot is a 2pt attempt within 2 seconds of an offensive rebound attempted by the same player who got the rebound

property rebound

returns Rebound item for the rebound of the shot, if it was missed, None otherwise

property shot_data

returns a dict with detailed shot data

property shot_type

returns shot type string (‘AtRim’, ‘ShortMidRange’, ‘LongMidRange’, ‘Arc3’ or ‘Corner3’)

abstract property shot_value

returns 3 if shot is a 3 point attempt, 2 otherwise

Foul

class pbpstats.resources.enhanced_pbp.foul.Foul[source]

Bases: object

Class for foul events

property counts_as_personal_foul

returns True if fouls is a foul type that counts as a personal foul, False otherwise

property counts_towards_penalty

returns True if foul is a foul type that counts towards the penalty, False otherwise

property event_stats

returns list of dicts with all stats for event

property foul_type_string

returns string description of foul type

abstract property is_away_from_play_foul
abstract property is_charge
abstract property is_clear_path_foul
abstract property is_defensive_3_seconds
abstract property is_delay_of_game
abstract property is_double_foul
abstract property is_double_technical
property is_flagrant
abstract property is_flagrant1
abstract property is_flagrant2
abstract property is_inbound_foul
abstract property is_loose_ball_foul
abstract property is_offensive_foul
abstract property is_personal_block_foul
abstract property is_personal_foul
abstract property is_personal_take_foul
abstract property is_shooting_block_foul
abstract property is_shooting_foul
abstract property is_technical
abstract property number_of_fta_for_foul

returns the number of free throws resulting from the foul

Free Throw

class pbpstats.resources.enhanced_pbp.free_throw.FreeThrow[source]

Bases: object

Class for free throw events

property event_for_efficiency_stats

returns Foul object for the foul that resulted in the free throw. Plus/minus points should go to the players on the floor at the time of the foul, not the free throw.

property event_stats

returns list of dicts with all stats for event

property foul_that_led_to_ft

returns Foul object for the foul that resulted in the free throw

property free_throw_type

returns string description of free throw type

property is_away_from_play_ft

returns True if free throw is from an away from the play foul, False otherwise.

property is_end_ft

returns True if free throw is last of trip to the free throw line, False otherwise

property is_first_ft

returns True if free throw is first of trip to the free throw line, False otherwise

abstract property is_ft_1_of_1
abstract property is_ft_1_of_2
abstract property is_ft_1_of_3
abstract property is_ft_1pt
abstract property is_ft_2_of_2
abstract property is_ft_2_of_3
abstract property is_ft_2pt
abstract property is_ft_3_of_3
abstract property is_ft_3pt
property is_inbound_foul_ft

returns True if free throw is from an inbound foul, False otherwise.

abstract property is_made

returns True if shot was made, False otherwise

abstract property is_technical_ft
property num_ft_for_trip

returns number of shots for the trip to the free throw line

shot_type = 'FT'
property shot_value

returns shot value of a free throw Starting in 2019-20 season, the G-League added 2 and 3 point FTs

Jump Ball

class pbpstats.resources.enhanced_pbp.jump_ball.JumpBall[source]

Bases: object

Class for jump ball events

property event_stats

returns list of dicts with all stats for event

property winning_team

returns team id that won the jump ball

Rebound

exception pbpstats.resources.enhanced_pbp.rebound.EventOrderError[source]

Bases: Exception

Class for exception raised when rebound event is not immediately following a missed shot event.

You can manually edit the event order in the pbp file stored on disk to fix this.

class pbpstats.resources.enhanced_pbp.rebound.Rebound[source]

Bases: object

Class for rebound events

property event_stats

returns list of dicts with all stats for event

property is_buzzer_beater_placeholder

returns True if rebound is a placeholder event after a missed buzzer beater, False otherwise.

Rebounds occur after time has expired but are still logged in play-by-play, but should not be counted in rebound totals

property is_buzzer_beater_rebound_at_shot_time

returns True if rebound is a placeholder event after a missed buzzer beater, False otherwise.

Sometimes rebound on buzzer beater is given the same time as shot - don’t count these. Only don’t count if rebound is last event before end of period event, ignoring replay events

property is_non_live_ft_placeholder

returns True if rebound is a placeholder event after a missed free throw that is not a live ball, False otherwise.

Example: rebound after missed flagrant FT 2 of 2

abstract property is_placeholder

returns True if rebound is a placeholder event, False otherwise.

These are team rebounds on for example missed FT 1 of 2

property is_real_rebound

Returns True if rebound should be counted as a rebound, False otherwise.

All missed shots have a rebound in the play-by-play but not all of these rebounds should be counted as actual rebounds. Some are just placeholder events.

property is_turnover_placeholder

returns True if rebound is a placeholder event when a turnover occurs, False otherwise.

Example shot clock violation or kicked ball turnover at time of team rebound

abstract property missed_shot
abstract property oreb
property self_reb

returns True if rebound was gotten by player who missed the shot, False otherwise

Replay

class pbpstats.resources.enhanced_pbp.replay.Replay[source]

Bases: object

Class for replay events

property event_stats

returns list of dicts with all stats for event

abstract property overturn_ruling
abstract property ruling_stands
abstract property support_ruling

Start of Period

exception pbpstats.resources.enhanced_pbp.start_of_period.InvalidNumberOfStartersException[source]

Bases: Exception

Class for exception when a team’s 5 period starters can’t be determined.

You can add the correct period starters to overrides/missing_period_starters.json in your data directory to fix this.

class pbpstats.resources.enhanced_pbp.start_of_period.StartOfPeriod[source]

Bases: object

Class for start of period events

property current_players

returns period starters

property event_stats

returns list of dicts with all stats for event

get_offense_team_id()[source]

returns team id for team on starting period on offense

abstract classmethod get_period_starters(file_directory)[source]

Gets player ids of players who started the period for each team

Parameters

file_directory (str) – directory in which overrides subdirectory exists containing period starter overrides when period starters can’t be determined from parsing pbp events

Returns

dict with list of player ids for each team with players on the floor at start of period

Raises

InvalidNumberOfStartersException: If all 5 players that start the period for a team can’t be determined.

get_team_starting_with_ball()[source]

returns team id for team on starting period with the ball

property league

Returns League for game id.

First 2 in game id represent league - 00 for nba, 10 for wnba, 20 for g-league

Substitution

class pbpstats.resources.enhanced_pbp.substitution.Substitution[source]

Bases: object

Class for Substitution events

property current_players

returns dict with list of player ids for each team with players on the floor following the sub

property event_stats

returns list of dicts with all stats for event

abstract property incoming_player_id
abstract property outgoing_player_id

Timeout

class pbpstats.resources.enhanced_pbp.timeout.Timeout[source]

Bases: object

Class for timeout events

property event_stats

returns list of dicts with all stats for event

Turnover

class pbpstats.resources.enhanced_pbp.turnover.Turnover[source]

Bases: object

Class for Turnover events

property event_stats

returns list of dicts with all stats for event

abstract classmethod is_3_second_violation()[source]
abstract classmethod is_bad_pass()[source]
abstract classmethod is_bad_pass_out_of_bounds()[source]
abstract classmethod is_kicked_ball()[source]
abstract classmethod is_lane_violation()[source]
abstract classmethod is_lost_ball()[source]
abstract classmethod is_lost_ball_out_of_bounds()[source]
abstract classmethod is_no_turnover()[source]
abstract classmethod is_offensive_goaltending()[source]
abstract classmethod is_shot_clock_violation()[source]
property is_steal
abstract classmethod is_step_out_of_bounds()[source]
abstract classmethod is_travel()[source]

Violation

class pbpstats.resources.enhanced_pbp.violation.Violation[source]

Bases: object

Class for violation events

property event_stats

returns list of dicts with all stats for event

abstract classmethod is_delay_of_game()[source]
abstract classmethod is_double_lane_violation()[source]
abstract classmethod is_goaltend_violation()[source]
abstract classmethod is_jumpball_violation()[source]
abstract classmethod is_kicked_ball_violation()[source]
abstract classmethod is_lane_violation()[source]