NBAComAgent: Documentation


In [2]:
import datetime
import os
import logging
import pprint
logger = logging.getLogger()
logger.setLevel(logging.ERROR)

In [3]:
from nba.agents.nbacom import NBAComAgent
from nba.db.nbapg import NBAPostgres

If make changes to code, can reload


In [10]:
import nba.agents.nbacom
reload(nba.agents.nbacom)
from nba.agents.nbacom import NBAComAgent
import nba.db.nbacom
reload(nba.db.nbacom)
from nba.db.nbapg import NBAPostgres

Initialization


In [4]:
agent = NBAComAgent(cache_name='nbacom-cache', cookies=None, db=None, safe=False)
for k, v in vars(agent).iteritems():
    print k, pprint.pformat(v, indent=2)


nbadb None
safe False
parser <nba.parsers.nbacom.NBAComParser object at 0x7f46e0aef950>
scraper <nba.scrapers.nbacom.NBAComScraper object at 0x7f46e0beafd0>

In [6]:
os.getenv('NBA_PG_USER')

In [6]:
db = NBAPostgres(username=os.getenv('NBA_PG_USER'), password=os.getenv('NBA_PG_PASSWORD'), database=os.getenv('NBA_PG_DB'))
agent = NBAComAgent(cache_name='nbacom-cache', cookies=None, db=db, safe=False)
for k, v in vars(agent).iteritems():
    print k, pprint.pformat(v, indent=2)


nbadb <nba.db.nbacom.NBAPostgres object at 0x7f46e0aefd50>
safe False
parser <nba.parsers.nbacom.NBAComParser object at 0x7f46e0aef790>
scraper <nba.scrapers.nbacom.NBAComScraper object at 0x7f46e0aef510>

cs_player_gamelogs

    Fetches player_gamelogs and updates cs_player_gamelogs table

    Arguments:
         season (str): in YYYY-YY format (2015-16)

    Returns:
         players (list): player dictionary of stats + dfs points

In [39]:
agent = NBAComAgent(safe=False, db=False)

In [44]:
season = agent.nbas.in_what_season(datetime.datetime.today())
gl = agent.cs_player_gamelogs(season=season)
print gl[0].get('player_name'), gl[0].get('matchup'), gl[0].get('game_date')


Stephen Curry GSW @ WAS 2016-02-03

cs_playerstats


In [56]:
agent = NBAComAgent(safe=False, db=False)

In [57]:
season = agent.nbas.in_what_season(datetime.datetime.today())
b, adv = agent.cs_playerstats(season=season)

In [58]:
print b[0]
print adv[0]


{'MIN_PLAYED': 626.0, u'BLK': 8, u'MIN': 626.4183333333333, u'AGE': 31.0, u'TOV': 38, u'REB': 68, u'TEAM_ID': 1610612741, u'PLAYER_ID': 201166, u'FG3A': 113, u'PLAYER_NAME': u'Aaron Brooks', u'AST': 94, u'DD2': 0, u'TEAM_ABBREVIATION': u'CHI', u'FG3M': 41, u'OREB': 15, u'FGM': 107, u'PF': 80, u'PTS': 285, u'FGA': 266, u'GP': 39, u'STL': 13, u'CFPARAMS': u'201166,1610612741', u'L': 17, u'FTA': 36, u'PLUS_MINUS': 52, u'W': 22, u'W_PCT': 0.564, u'DREB': 53, u'FTM': 30, u'FT_PCT': 0.833, u'PFD': 44, u'FG_PCT': 0.402, u'CFID': 5, 'SEC_PLAYED': 0.4183333333332939, u'FG3_PCT': 0.363, u'BLKA': 18, u'TD3': 0}
{'MIN_PLAYED': 16.0, u'MIN': 16.1, u'AGE': 31.0, u'TEAM_ID': 1610612741, u'PLAYER_ID': 201166, u'AST_PCT': 0.238, u'CFPARAMS': u'201166,1610612741', u'EFG_PCT': 0.479, u'PLAYER_NAME': u'Aaron Brooks', u'DEF_RATING': 100.9, 'SEC_PLAYED': 0.10000000000000142, u'NET_RATING': 3.3, u'TEAM_ABBREVIATION': u'CHI', u'PIE': 0.08, u'AST_TO': 2.47, u'FGM': 107, u'FGA_PG': 6.8, u'FGA': 266, u'TS_PCT': 0.506, u'GP': 39, u'USG_PCT': 0.223, u'L': 17, u'OREB_PCT': 0.026, u'REB_PCT': 0.057, u'W': 22, u'W_PCT': 0.564, u'DREB_PCT': 0.087, u'FGM_PG': 2.7, u'FG_PCT': 0.402, u'CFID': 5, u'PACE': 97.49, u'TM_TOV_PCT': 9.2, u'AST_RATIO': 22.7, u'OFF_RATING': 104.2}

cs_team_gamelogs


In [75]:
agent = NBAComAgent(safe=False, db=False)

In [76]:
season = agent.nbas.in_what_season(datetime.datetime.today())
gl = agent.cs_team_gamelogs(season=season)
print gl[0]


{u'fg_pct': 0.527, u'season_id': u'22015', u'team_id': 1610612744, u'team_name': u'Golden State Warriors', u'pts': 134, 'team_code': u'GSW', u'tov': 18, u'fta': 29, u'pf': 24, 'opponent_pts': 121, u'blk': 5, u'reb': 49, u'ftm': 16, u'ft_pct': 0.552, u'fg3a': 41, u'ast': 35, u'wl': u'W', u'fg3m': 20, u'fgm': 49, u'fg3_pct': 0.488, u'game_id': u'0021500739', u'dreb': 38, u'fga': 93, u'plus_minus': 13, u'stl': 10, u'video_available': 1, u'oreb': 11, u'game_date': u'2016-02-03', u'matchup': u'GSW @ WAS', 'minutes': 240}

cs_teamstats()


In [77]:
# can run script without database update
agent = NBAComAgent(safe=False, db=False)

In [78]:
b, adv = agent.cs_team_stats(season='2015-16', date_from=None, date_to=None)
print b[0]
print adv[0]


{u'BLK': 5.5, u'MIN': 48.1, u'TOV': 15.1, u'TEAM_ID': 1610612737, u'REB': 40.8, u'TEAM_NAME': u'Atlanta Hawks', u'FG3A': 26.8, u'AST': 25.3, u'PLUS_MINUS': 2.6, u'FG3M': 9.2, u'OREB': 8.3, u'FGM': 38.4, u'PF': 19.0, u'PTS': 102.2, u'FGA': 83.4, u'GP': 52, u'STL': 9.4, u'CFPARAMS': u'Atlanta Hawks', u'L': 22, u'FTA': 20.5, u'W': 30, u'W_PCT': 0.577, u'DREB': 32.5, u'FTM': 16.2, u'FT_PCT': 0.789, u'PFD': 18.4, u'FG_PCT': 0.461, u'CFID': 10, u'FG3_PCT': 0.344, u'BLKA': 5.2}
{u'MIN': 2501.0, u'TEAM_ID': 1610612737, u'TEAM_NAME': u'Atlanta Hawks', u'AST_PCT': 0.659, u'CFPARAMS': u'Atlanta Hawks', u'EFG_PCT': 0.516, u'DEF_RATING': 99.9, u'NET_RATING': 3.1, u'PIE': 0.523, u'AST_TO': 1.68, u'TS_PCT': 0.553, u'GP': 52, u'L': 22, u'OREB_PCT': 0.195, u'REB_PCT': 0.472, u'W': 30, u'W_PCT': 0.577, u'DREB_PCT': 0.739, u'CFID': 10, u'PACE': 99.25, u'TM_TOV_PCT': 0.152, u'AST_RATIO': 19.1, u'OFF_RATING': 103.0}

In [ ]: