Enhanced PBP¶
Ejection¶
End of Period¶
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-
data
¶ returns list of pbp event dicts
-
rebounds
¶ returns list of
Rebound
events
-
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
-
base_stats
¶ returns list of dicts with all seconds played and possession count stats for event
-
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
-
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
-
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
-
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
-
lineup_ids
¶ returns dict with lineup ids for each team for current event. Lineup ids are hyphen separated sorted player id strings.
-
score_margin
¶ returns the score margin from perspective of offense team before the event took place
-
seconds_remaining
¶ returns seconds remaining in period as a
float
-
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
-
distance
¶ returns shot distance in feet
-
event_stats
¶ returns list of dicts with all stats for event
-
is_and1
¶ returns True if shot was an and 1, False otherwise
-
is_assisted
¶ returns True if shot was assisted, False otherwise
-
is_blocked
¶ returns True if shot was blocked, False otherwise
-
is_corner_3
¶ returns True if shot was a corner 3, False otherwise
-
is_heave
¶ returns True if shot was a last second heave, False otherwise
-
is_made
¶ returns True if shot was made, False otherwise
-
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
-
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
-
shot_data
¶ returns a dict with detailed shot data
-
shot_type
¶ returns shot type string (‘AtRim’, ‘ShortMidRange’, ‘LongMidRange’, ‘Arc3’ or ‘Corner3’)
-
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
-
counts_as_personal_foul
¶ returns True if fouls is a foul type that counts as a personal foul, False otherwise
-
counts_towards_penalty
¶ returns True if foul is a foul type that counts towards the penalty, False otherwise
-
event_stats
¶ returns list of dicts with all stats for event
-
foul_type_string
¶ returns string description of foul type
-
is_away_from_play_foul
¶
-
is_charge
¶
-
is_clear_path_foul
¶
-
is_defensive_3_seconds
¶
-
is_delay_of_game
¶
-
is_double_foul
¶
-
is_double_technical
¶
-
is_flagrant
¶
-
is_flagrant1
¶
-
is_flagrant2
¶
-
is_inbound_foul
¶
-
is_loose_ball_foul
¶
-
is_offensive_foul
¶
-
is_personal_block_foul
¶
-
is_personal_foul
¶
-
is_personal_take_foul
¶
-
is_shooting_block_foul
¶
-
is_shooting_foul
¶
-
is_technical
¶
-
is_transition_take_foul
¶
-
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
-
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.
-
event_stats
¶ returns list of dicts with all stats for event
-
free_throw_type
¶ returns string description of free throw type
-
is_away_from_play_ft
¶ returns True if free throw is from an away from the play foul, False otherwise.
-
is_end_ft
¶ returns True if free throw is last of trip to the free throw line, False otherwise
-
is_first_ft
¶ returns True if free throw is first of trip to the free throw line, False otherwise
-
is_ft_1_of_1
¶
-
is_ft_1_of_2
¶
-
is_ft_1_of_3
¶
-
is_ft_1pt
¶
-
is_ft_2_of_2
¶
-
is_ft_2_of_3
¶
-
is_ft_2pt
¶
-
is_ft_3_of_3
¶
-
is_ft_3pt
¶
-
is_inbound_foul_ft
¶ returns True if free throw is from an inbound foul, False otherwise.
-
is_made
¶ returns True if shot was made, False otherwise
-
is_technical_ft
¶
-
is_transition_take_foul_ft
¶ returns True if free throw is from an transition take foul, False otherwise.
-
num_ft_for_trip
¶ returns number of shots for the trip to the free throw line
-
shot_type
= 'FT'¶
-
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¶
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
-
event_stats
¶ returns list of dicts with all stats for event
-
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
-
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
-
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
-
is_placeholder
¶ returns True if rebound is a placeholder event, False otherwise.
These are team rebounds on for example missed FT 1 of 2
-
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.
-
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
-
missed_shot
¶
-
oreb
¶
-
self_reb
¶ returns True if rebound was gotten by player who missed the shot, False otherwise
-
Replay¶
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
-
current_players
¶ returns period starters
-
event_stats
¶ returns list of dicts with all stats for event
-
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.
-
league
¶ Returns League for game id.
First 2 in game id represent league - 00 for nba, 10 for wnba, 20 for g-league
-
league_url_part
¶
-
Substitution¶
-
class
pbpstats.resources.enhanced_pbp.substitution.
Substitution
[source]¶ Bases:
object
Class for Substitution events
-
current_players
¶ returns dict with list of player ids for each team with players on the floor following the sub
-
event_stats
¶ returns list of dicts with all stats for event
-
incoming_player_id
¶
-
outgoing_player_id
¶
-