nba_api icon indicating copy to clipboard operation
nba_api copied to clipboard

CumeStatsPlayer does not work.

Open YKhanTU opened this issue 2 years ago • 4 comments

CumeStatsPlayer doesn't seem to be working properly.

It requires a list of GameIDs, which are provided when I fetch all game IDs for a certain player's season (in this case, Jason Tatum 2021-22). Despite giving a ton of GameIDs, I only get the totals for 1 game? I am confused. It even says GP/GS are both values of 1 in the response.

Below is what I am executing:

from nba_api.stats.endpoints import commonplayerinfo, cumestatsplayer, cumestatsplayergames
from nba_api.stats.static import players;

# nba_players = players.get_players()
nba_players = players.find_players_by_full_name('Jayson Tatum')

for nba_player in nba_players:
    player_id = nba_player['id']

    player_info = commonplayerinfo.CommonPlayerInfo(player_id).common_player_info.get_dict()

    p_columns = player_info['headers']
    p_rows = player_info['data'][0]

    p_data = dict(zip(p_columns, p_rows))

    print(p_data)

    p_games = cumestatsplayergames.CumeStatsPlayerGames(player_id, league_id='00', season='2021-22', season_type_all_star='Regular Season').cume_stats_player_games.get_dict()['data']

    game_ids = []

    for game in p_games:
        game_ids.append(game[1])
    
    print(game_ids)

    p_stats = cumestatsplayer.CumeStatsPlayer(player_id, game_ids, league_id='00', season='2021-22').total_player_stats.get_dict()

    pstats_columns = p_stats['headers']
    pstats_rows = p_stats['data'][0]

    pstats_data = dict(zip(pstats_columns, pstats_rows))

    print('\n\n')
    print('player stats: ')
    print(pstats_data)

Even putting hand-picked game IDs into the game_ids parameter gives me the same result, cumulative stats for only 1 game despite giving a bunch of game IDs that are valid.

YKhanTU avatar Nov 13 '22 01:11 YKhanTU

@YKhanTU: The game_ids should be formatted as 0022200186|0022200176|0022200163|0022200152

Here's a valid URL:

https://stats.nba.com/stats/cumestatsplayer?LeagueID=00&Season=2022-23&SeasonType=Regular Season&PlayerID=1628369&gameIDs=0022200186|0022200176|0022200163|0022200152

Actual Site: https://www.nba.com/stats/cumestats?ReportType=Player&PlayerID=1628369

You can use the browsers Dev Tools to view the call.

All that being said, I think we could certainly make this more clear, or put in an option that simply takes a dictionary in; that would have been my first thought.

Hope that helps.

rsforbes avatar Nov 14 '22 01:11 rsforbes

@YKhanTU: The game_ids should be formatted as 0022200186|0022200176|0022200163|0022200152

Here's a valid URL:

https://stats.nba.com/stats/cumestatsplayer?LeagueID=00&Season=2022-23&SeasonType=Regular Season&PlayerID=1628369&gameIDs=0022200186|0022200176|0022200163|0022200152

Actual Site: https://www.nba.com/stats/cumestats?ReportType=Player&PlayerID=1628369

You can use the browsers Dev Tools to view the call.

All that being said, I think we could certainly make this more clear, or put in an option that simply takes a dictionary in; that would have been my first thought.

Hope that helps.

Awesome. I didn't realize it needed to be formatted in that way. That would be nice if we could pass in an array or dictionary in as well.

Thanks for the help.

YKhanTU avatar Nov 16 '22 06:11 YKhanTU

I am having trouble even using one game id. I tried multiple ones with the format you suggested and it also does not work. This line returns an error. from nba_api.stats.endpoints import cumestatsplayer cumestatsplayer.CumeStatsPlayer(game_ids='22001069', player_id=1630173, season='2020-21', season_type_all_star='Regular Season')

I tried just using the game_ids as a single value thats not a string. I tried using your format hoping multiple games would return something like so : game_ids='22001069|22001062'.

I have had no other trouble with your other endpoints I have used so far.

Here is the error that comes up.

Traceback (most recent call last): File "", line 1, in File "/Users/jamesordaya/.local/lib/python3.9/site-packages/nba_api/stats/endpoints/cumestatsplayer.py", line 38, in init self.get_request() File "/Users/jamesordaya/.local/lib/python3.9/site-packages/nba_api/stats/endpoints/cumestatsplayer.py", line 48, in get_request self.load_response() File "/Users/jamesordaya/.local/lib/python3.9/site-packages/nba_api/stats/endpoints/cumestatsplayer.py", line 51, in load_response data_sets = self.nba_response.get_data_sets() File "/Users/jamesordaya/.local/lib/python3.9/site-packages/nba_api/stats/library/http.py", line 83, in get_data_sets raw_dict = self.get_dict() File "/Users/jamesordaya/.local/lib/python3.9/site-packages/nba_api/library/http.py", line 41, in get_dict return json.loads(self._response) File "/Users/jamesordaya/.conda/envs/pythonProject1/lib/python3.9/json/init.py", line 346, in loads return _default_decoder.decode(s) File "/Users/jamesordaya/.conda/envs/pythonProject1/lib/python3.9/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/Users/jamesordaya/.conda/envs/pythonProject1/lib/python3.9/json/decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Jimmay13 avatar Dec 03 '22 20:12 Jimmay13

At least of now, it's probably best to update the documentation for this endpoint. It's unclear that the required input format is 1. a string and 2. the string needs to follow the format 'game_id_0|game_id_1|game_id2'.

Secondly, this is probably an implementation detail that can be handled by the CumeStatsPlayer endpoint and just expect a list or a set as input to the game_ids parameter.

kterusaki avatar Nov 01 '23 16:11 kterusaki