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

event_type = 11

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

event_type = 13

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

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

event_type = [1, 2]
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

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’)

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

event_type = 6
property foul_type_string

returns string description of foul type

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

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

event_type = 3
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

property is_ft_1_of_1
property is_ft_1_of_2
property is_ft_1_of_3
property is_ft_1pt

returns True if free throw is a 1 point free throw, False otherwise Only used in g-league, starting in 2019-20 season

property is_ft_2_of_2
property is_ft_2_of_3
property is_ft_2pt

returns True if free throw is a 2 point free throw, False otherwise Only used in g-league, starting in 2019-20 season

property is_ft_3_of_3
property is_ft_3pt

returns True if free throw is a 3 point free throw, False otherwise Only used in g-league, starting in 2019-20 season

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

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

event_type = 10
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

event_type = 4
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

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

property missed_shot

returns FieldGoal or FreeThrow object for shot that was missed

Raises

EventOrderError: If rebound event is not immediately following a missed shot event.

property oreb

returns True if rebound is an offensive rebound, False otherwise

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

event_type = 18
property overturn_ruling
property ruling_stands
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

event_type = 12
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

event_type = 8
property incoming_player_id

returns player id of player coming in to the game

property outgoing_player_id

returns player id of player going out of the game

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

event_type = 9

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

event_type = 5
property is_3_second_violation
property is_bad_pass
property is_bad_pass_out_of_bounds
property is_kicked_ball
property is_lane_violation
property is_lost_ball
property is_lost_ball_out_of_bounds
property is_no_turnover
property is_offensive_goaltending
property is_shot_clock_violation
property is_steal
property is_step_out_of_bounds
property is_travel

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

event_type = 7
property is_delay_of_game
property is_double_lane_violation
property is_goaltend_violation
property is_jumpball_violation
property is_kicked_ball_violation
property is_lane_violation