def nbacom_xref(db=None, with_pos=False): ''' Adds nbacom_player_id to list of player dict Args: db (NBAPostgres): instance with_pos (bool): default false, set True to get key with position + name Returns: dict: key is str, val is list ''' if not db: db = getdb() q = """SELECT * FROM player""" nbacom_players = defaultdict(list) if with_pos: for p in db.select_dict(q): key = '{}_{}'.format(p['display_first_last'], p['nbacom_position']).lower() nbacom_players[key].append(p) else: for p in db.select_dict(q): key = p['display_first_last'].lower() nbacom_players[key].append(p) return nbacom_players
import json import logging import sys from nba.agents.bbref import BBRefAgent from nba.agents.nbacom import NBAComAgent from nba.dates import datetostr, today from nba.pipelines.bbref import * from nba.pipelines.nbacom import players_v2015_table from nba.season import season_start from nba.utility import getdb logging.basicConfig(stream=sys.stdout, level=logging.INFO) season_code = '2017-18' a = NBAComAgent(db=getdb(), cache_name='nbacom-agent') bbrefa = BBRefAgent(db=getdb(), cache_name='bbref-agent') def add_gamelog_player(gamelog_player): ''' Adds player to player table Args: gamelog_player (dict): Returns: None ''' bbref_player = bbrefa.match_gamelog_player(gamelog_player)
def run(): ''' Updates nba.com statistics Args: None Returns: None ''' logging.basicConfig(stream=sys.stdout, level=logging.INFO) db = getdb() cn = 'nba-agent-{}'.format(today()) a = NBAComAgent(cache_name=cn, db=db) a.scraper.delay = 1 season_year = 2018 season_code = '2017-18' # ensures players table is up-to-date before inserting gamelogs, etc. # players uses 2017 as season_year if season_code is 2017-18 # whereas nbadb calls that season_year 2018 logging.info('starting update nba.com players') nbadb_player_update.run() logging.info('finished update nba.com players') # player_gamelogs logging.info('starting nba.com player gamelogs') a.player_gamelogs(season_code, date_from=datetostr( season_start(season_code=season_code), fmt='nba'), date_to=yesterday(fmt='nba')) logging.info('finished nba.com player gamelogs') # playerstats_daily logging.info('starting playerstats daily') a.playerstats(season_code, all_missing=True, per_mode='Totals') a.playerstats(season_code, all_missing=True, per_mode='PerGame') logging.info('finished playerstats daily') # player and team boxscores combined logging.info('starting player_boxscores_combined') pbs, tbs = a.combined_boxscores() logging.info('finished player_boxscores_combined') # update team_gamelogs logging.info('starting team gamelogs') a.team_gamelogs(season_code) logging.info('finished team gamelogs') # teamstats_daily logging.info('starting teamstats daily') a.teamstats(season_code, all_missing=True, per_mode='Totals') a.teamstats(season_code, all_missing=True, per_mode='PerGame') logging.info('finished teamstats daily') # team_opponent_dashboards logging.info('start team_opponent_dashboards') a.team_opponent_dashboards(season_code, all_missing=True, per_mode='Totals') a.team_opponent_dashboards(season_code, all_missing=True, per_mode='PerGame') logging.info('finished team_opponent_dashboards') # game boxscores - linescores, refs, etc. logging.info('start game_boxscores') a.game_boxscores() logging.info('finished game_boxscores') # refresh all materialized views logging.info('start refresh materialized views') a.refresh_materialized() logging.info('refreshed materialized views')
def setUp(self): self.db = getdb()
def run(): ''' Updates nba.com statistics Args: None Returns: None ''' logging.basicConfig(stream=sys.stdout, level=logging.INFO) db = getdb() cn = 'nba-agent-{}'.format(today()) a = NBAComAgent(cache_name=cn, db=db) a.scraper.delay = 1 season_year = 2018 season_code = '2017-18' # gets all missing (days) salaries from current seasons #logging.info('starting dfs salaries') #fla.salaries(all_missing=True) #rgurua.salaries(all_missing=True) #logging.info('finished dfs salaries') # ensures that player_xref table includes all players from salaries #logging.info('starting update player_xref') #fla.update_player_xref() #logging.info('finished update player_xref') # gets model from fantasylabs #td = today('fl') #mn = 'phan' #flpg.insert_models([{ # 'game_date': today('fl'), # 'data': fla.scraper.model(model_day=td, model_name=mn), # 'model_name': mn}]) # gets ownership data from fantasylabs #logging.info('starting dfs ownership') #fla.ownership(all_missing=True) #logging.info('finished dfs ownership') # gets data from rotogrinders #logging.info('starting rotogrinders') #rs = RotoGrindersNBAScraper() #rp = RotoGrindersNBAParser() #rdb = RotoGrindersNBAPg(username=config['nbadb']['username'], # password=config['nbadb']['password'], # database=config['nbadb']['database']) #jsonstr = rp.odds(rs.odds()) #rdb.insert_odds(today(), json.loads(jsonstr)) #logging.info('finished rotogrinders') # refresh all materialized views logging.info('start refresh materialized queries') a.refresh_materialized() logging.info('refreshed materialized queries') # odds and lines logging.info('start odds and lines') dba = DonBestNBAAgent(db=db) dba.odds(all_missing=True) logging.info('finished odds and lines')