Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 56 additions & 56 deletions src/nba_api/stats/endpoints/_expected_data/dunkscoreleaders.py
Original file line number Diff line number Diff line change
@@ -1,61 +1,61 @@
"""Expected data structure for DunkScoreLeaders endpoint."""

_EXPECTED_DATA = {
"Dunks": [
"GAME_ID",
"GAME_DATE",
"MATCHUP",
"PERIOD",
"GAME_CLOCK_TIME",
"EVENT_NUM",
"PLAYER_ID",
"PLAYER_NAME",
"FIRST_NAME",
"LAST_NAME",
"TEAM_ID",
"TEAM_NAME",
"TEAM_CITY",
"TEAM_ABBREVIATION",
"DUNK_SCORE",
"JUMP_SUBSCORE",
"POWER_SUBSCORE",
"STYLE_SUBSCORE",
"DEFENSIVE_CONTEST_SUBSCORE",
"MAX_BALL_HEIGHT",
"BALL_SPEED_THROUGH_RIM",
"PLAYER_VERTICAL",
"HANG_TIME",
"TAKEOFF_DISTANCE",
"REVERSE_DUNK",
"DUNK_360",
"THROUGH_THE_LEGS",
"ALLEY_OOP",
"TIP_IN",
"SELF_OOP",
"PLAYER_ROTATION",
"PLAYER_LATERAL_SPEED",
"BALL_DISTANCE_TRAVELED",
"BALL_REACH_BACK",
"TOTAL_BALL_ACCELERATION",
"DUNKING_HAND",
"JUMPING_FOOT",
"PASS_LENGTH",
"CATCHING_HAND",
"CATCH_DISTANCE",
"LATERAL_CATCH_DISTANCE",
"PASSER_ID",
"PASSER_NAME",
"PASSER_FIRST_NAME",
"PASSER_LAST_NAME",
"PASS_RELEASE_POINT",
"SHOOTER_ID",
"SHOOTER_NAME",
"SHOOTER_FIRST_NAME",
"SHOOTER_LAST_NAME",
"SHOT_RELEASE_POINT",
"SHOT_LENGTH",
"DEFENSIVE_CONTEST_LEVEL",
"POSSIBLE_ATTEMPTED_CHARGE",
"VIDEO_AVAILABLE",
"dunks": [
"gameId",
"gameDate",
"matchup",
"period",
"gameClockTime",
"eventNum",
"playerId",
"playerName",
"firstName",
"lastName",
"teamId",
"teamName",
"teamCity",
"teamAbbreviation",
"dunkScore",
"jumpSubscore",
"powerSubscore",
"styleSubscore",
"defensiveContestSubscore",
"maxBallHeight",
"ballSpeedThroughRim",
"playerVertical",
"hangTime",
"takeoffDistance",
"reverseDunk",
"dunk360",
"throughTheLegs",
"alleyOop",
"tipIn",
"selfOop",
"playerRotation",
"playerLateralSpeed",
"ballDistanceTraveled",
"ballReachBack",
"totalBallAcceleration",
"dunkingHand",
"jumpingFoot",
"passLength",
"catchingHand",
"catchDistance",
"lateralCatchDistance",
"passerId",
"passerName",
"passerFirstName",
"passerLastName",
"passReleasePoint",
"shooterId",
"shooterName",
"shooterFirstName",
"shooterLastName",
"shotReleasePoint",
"shotLength",
"defensiveContestLevel",
"possibleAttemptedCharge",
"videoAvailable",
]
}
3 changes: 3 additions & 0 deletions src/nba_api/stats/endpoints/_parsers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from .boxscoresummaryv3 import NBAStatsBoxscoreSummaryParserV3
from .boxscoretraditionalv3 import NBAStatsBoxscoreTraditionalParserV3
from .boxscoreusagev3 import NBAStatsBoxscoreUsageV3Parser
from .dunkscoreleaders import NBAStatsDunkScoreLeadersParser
from .gravityleaders import NBAStatsGravityLeadersParser
from .iststandings import NBAStatsISTStandingsParser
from .playbyplayv3 import NBAStatsPlayByPlayParserV3
Expand Down Expand Up @@ -48,6 +49,7 @@
"NBAStatsScheduleLeagueV2Parser",
"NBAStatsScheduleLeagueV2IntParser",
"NBAStatsScoreboardV3Parser",
"NBAStatsDunkScoreLeadersParser",
"get_parser_for_endpoint",
]

Expand All @@ -71,6 +73,7 @@
"scheduleleaguev2": NBAStatsScheduleLeagueV2Parser,
"scheduleleaguev2int": NBAStatsScheduleLeagueV2IntParser,
"scoreboardv3": NBAStatsScoreboardV3Parser,
"dunkscoreleaders": NBAStatsDunkScoreLeadersParser,
}


Expand Down
109 changes: 109 additions & 0 deletions src/nba_api/stats/endpoints/_parsers/dunkscoreleaders.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
"""Parser for dunkscoreleaders endpoint."""


class NBAStatsDunkScoreLeadersParser:
"""Parser for dunkscoreleaders endpoint data.

Parses the nested JSON response from the dunkscoreleaders endpoint into
tabular datasets for use with Pandas DataFrames.
"""

def __init__(self, nba_dict):
"""Initialize parser with NBA stats dictionary.

Args:
nba_dict: Dictionary containing 'dunks' key with nested data
"""
self.nba_dict = nba_dict
self.dunks = nba_dict.get("dunks", [])

def get_dunkscoreleaders_headers(self):
"""Get headers for dunk score leaders data.

Returns:
List of header names for the DunkScoreLeaders dataset

"""
return [
"gameId",
"gameDate",
"matchup",
"period",
"gameClockTime",
"eventNum",
"playerId",
"playerName",
"firstName",
"lastName",
"teamId",
"teamName",
"teamCity",
"teamAbbreviation",
"dunkScore",
"jumpSubscore",
"powerSubscore",
"styleSubscore",
"defensiveContestSubscore",
"maxBallHeight",
"ballSpeedThroughRim",
"playerVertical",
"hangTime",
"takeoffDistance",
"reverseDunk",
"dunk360",
"throughTheLegs",
"alleyOop",
"tipIn",
"selfOop",
"playerRotation",
"playerLateralSpeed",
"ballDistanceTraveled",
"ballReachBack",
"totalBallAcceleration",
"dunkingHand",
"jumpingFoot",
"passLength",
"catchingHand",
"catchDistance",
"lateralCatchDistance",
"passerId",
"passerName",
"passerFirstName",
"passerLastName",
"passReleasePoint",
"shooterId",
"shooterName",
"shooterFirstName",
"shooterLastName",
"shotReleasePoint",
"shotLength",
"defensiveContestLevel",
"possibleAttemptedCharge",
"videoAvailable",
]

def get_dunkscoreleaders_data(self):
"""Extract dunkscoreleaders data

Returns:
list: A list of rows, where each row represents a dunk event.
"""
rows = []
headers = self.get_dunkscoreleaders_headers()
for dunk in self.dunks:
row = [dunk.get(header) for header in headers]
rows.append(row)
return rows

def get_data_sets(self):
"""Return all datasets for this endpoint.

Returns:
Dictionary mapping dataset name to its headers and data.
"""
return {
"DunkScoreLeaders": {
"headers": self.get_dunkscoreleaders_headers(),
"data": self.get_dunkscoreleaders_data(),
},
}
8 changes: 4 additions & 4 deletions src/nba_api/stats/endpoints/dunkscoreleaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
>>> from nba_api.stats.endpoints import DunkScoreLeaders
>>> dunks = DunkScoreLeaders(season='2024-25')
>>> df = dunks.dunks.get_data_frame()
>>> print(df[['PLAYER_NAME', 'DUNK_SCORE', 'PLAYER_VERTICAL']].head())
>>> print(df[['playerName', 'dunkScore', 'playerVertical']].head())
"""

from nba_api.stats.endpoints._base import Endpoint
Expand Down Expand Up @@ -57,7 +57,7 @@ class DunkScoreLeaders(Endpoint):
... player_id_nullable='1630168'
... )
>>> df = player_dunks.dunks.get_data_frame()
>>> print(df[['PLAYER_NAME', 'DUNK_SCORE', 'PLAYER_VERTICAL', 'HANG_TIME']])
>>> print(df[['playerName', 'dunkScore', 'playerVertical', 'hangTime']].head())
"""

endpoint = "dunkscoreleaders"
Expand Down Expand Up @@ -140,9 +140,9 @@ def load_response(self):
accessible DataSet object containing all dunk records with detailed
biomechanics and scoring information.
"""
data_sets = self.nba_response.get_data_sets()
data_sets = self.nba_response.get_data_sets(self.endpoint)
self.data_sets = [
Endpoint.DataSet(data=data_set)
for data_set_name, data_set in data_sets.items()
]
self.dunks = Endpoint.DataSet(data=data_sets["Dunks"])
self.dunks = Endpoint.DataSet(data=data_sets["DunkScoreLeaders"])
Loading