get_tracking_shot_stats_for_date_range.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:nba_db 作者: dblackrun 项目源码 文件源码
def main():
    logging.basicConfig(filename='logs/tracking_shot_stats.log',level=logging.ERROR, format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')
    config=json.loads(open('config.json').read())

    command_line_args = sys.argv

    dates = utils.validate_dates(command_line_args)
    start_date = dates[0]
    end_date = dates[1]

    username = config['username']
    password = config['password']
    host = config['host']
    database = config['database']

    engine = create_engine('mysql://'+username+':'+password+'@'+host+'/'+database)

    DBSession = scoped_session(sessionmaker(autoflush=True,autocommit=False,bind=engine))

    # get data
    for dt in rrule(DAILY, dtstart=start_date, until=end_date):
        date = dt.strftime("%m/%d/%Y")

        game_team_map, player_team_game_map, daily_game_ids = sportvu.get_player_game_team_maps_and_daily_game_ids(date)

        if len(daily_game_ids) > 0:
            team_queue = Queue()
            player_queue = Queue()
            # Create worker threads
            for x in range(5):
                team_worker = sportvu.TeamShotWorker(team_queue, DBSession)
                player_worker = sportvu.PlayerShotWorker(player_queue, DBSession)
                # Setting daemon to True will let the main thread exit even though the workers are blocking
                team_worker.daemon = True
                player_worker.daemon = True
                team_worker.start()
                player_worker.start()
            # Put the tasks into the queue as a tuple
            for close_def_dist_range in constants.CLOSE_DEF_DIST_RANGES:
                for shot_clock_range in constants.SHOT_CLOCK_RANGES:
                    for shot_dist_range in constants.SHOT_DIST_RANGES:
                        for touch_time_range in constants.TOUCH_TIME_RANGES:
                            for dribble_range in constants.DRIBBLE_RANGES:
                                for general_range in constants.GENERAL_RANGES:
                                    team_queue.put((date, daily_game_ids, game_team_map, close_def_dist_range, shot_clock_range, shot_dist_range, touch_time_range, dribble_range, general_range))
                                    player_queue.put((date, daily_game_ids, player_team_game_map, close_def_dist_range, shot_clock_range, shot_dist_range, touch_time_range, dribble_range, general_range))
            # Causes the main thread to wait for the queue to finish processing all the tasks
            team_queue.join()
            player_queue.join()

    DBSession.remove()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号