Beispiel #1
0
# iterate over games and parse play-by-play
print('parsing play-by-play data...')
for game in gamedict.keys():
    print('on game', game)
    # get teams
    home, away = game[-3:], game[-6:-3]
    teams = [home, away]
    # get players on those teams
    active = [p for p in pstats.keys() if pstats[p].team() in teams]
    # initialize new game for those players
    for p in active:
        pstats[p]._newgame(game)
    # parse game
    data = pbp[gamedict[game][0]:gamedict[game][1]]
    pstats, score = PPBP.processgame(data, pstats, teams, active)

    # get players from game that actually played
    played_game = [p for p in active if pstats[p].playedgame()]
                   
    # get total game stats from players involved
    gstats[game] = NBAP.game(game, pstats, score, players)
    update(game, pstats, active, score)
                       
    # flush game stats for players involved
    for p in active:
        pstats[p]._flushgame()
        

# write out data parsed from pbp
print("writing out game stats...")
import NBA_playerclass as NBAP

'''
Assume that each play-by-play file has an associated "players" file that
provides the list of active players and their ESPN IDs, and an associated
player-stats file with data for each game that allows starters to be
assessed;
'''
datadirectory   = os.path.join(chdir,'DataFiles')
playbyplayfile  = os.path.join(datadirectory, playbyplayname)
playerstotfile  = os.path.join(datadirectory, playerstotname)
playesstatfile  = os.path.join(datadirectory, playesstatname)

gstats          = list()
pstats          = LAS.createplayers(playerstotfile)
gamedict, pbp   = LAS.getpbp(playbyplayfile, ['times', 'actions'])

print('parsing play-by-play data...')
for game in gamedict.keys():
    print('on game', game)
    teams       = [game[-3:], game[-6:-3]]      # [home, away]
    curplayers  = [p for p in pstats.keys() if pstats[p].team() in teams]
    curgame     = pbp[gamedict[game][0]:gamedict[game][1]]
    for p in curplayers: pstats[p]._newgame(game)
    pstats, score   = PPBP.processgame(curgame, pstats, teams, curplayers)
    played_game     = [p for p in curplayers if pstats[p].playedgame()]
    for p in active: pstats[p]._flushgame()

return gstats, pstats
print('Done with current file')
Beispiel #3
0
'''
Assume that each play-by-play file has an associated "players" file that
provides the list of active players and their ESPN IDs, and an associated
player-stats file with data for each game that allows starters to be
assessed;
'''
datadirectory = os.path.join(chdir, 'DataFiles')
playbyplayfile = os.path.join(datadirectory, playbyplayname)
playerstotfile = os.path.join(datadirectory, playerstotname)
playesstatfile = os.path.join(datadirectory, playesstatname)

gstats = list()
pstats = LAS.createplayers(playerstotfile)
gamedict, pbp = LAS.getpbp(playbyplayfile, ['times', 'actions'])

print('parsing play-by-play data...')
for game in gamedict.keys():
    print('on game', game)
    teams = [game[-3:], game[-6:-3]]  # [home, away]
    curplayers = [p for p in pstats.keys() if pstats[p].team() in teams]
    curgame = pbp[gamedict[game][0]:gamedict[game][1]]
    for p in curplayers:
        pstats[p]._newgame(game)
    pstats, score = PPBP.processgame(curgame, pstats, teams, curplayers)
    played_game = [p for p in curplayers if pstats[p].playedgame()]
    for p in active:
        pstats[p]._flushgame()

return gstats, pstats
print('Done with current file')
Beispiel #4
0
# load play-by-play and find game indicies; pbp is times and actions
gamedict, pbp = LAS.getpbp(fhandlepbp, ['times', 'actions'])
# iterate over games and parse play-by-play
print('parsing play-by-play data...')
for game in gamedict.keys():
    # get teams
    home, away = game[-3:], game[-6:-3]
    teams = [home, away]
    # get players on those teams
    active = [p for p in pstats.keys() if pstats[p].team() in teams]
    # initialize new game for those players
    for p in active:
        pstats[p]._newgame(game)
    # parse game
    data = pbp[gamedict[game][0]:gamedict[game][1]]
    pstats, score = NBA1.processgame(data, pstats, teams, active)
    # get total game stats from players involved
    gstats.update(game, pstats, active, score)
    # flush game stats for player involved
    for p in active:
        pstats[p]._flushgame()
        
# write out data parsed from pbp
print("writing out game stats...")
gamestats = gstats.getgames()

with open(os.path.join(chdir ,'DataFiles', gstats._pbpfile + \
                       "GameStats.txt"), 'w') as f1:
    for game in gamestats.keys():
        if game != 'statlist':
            home, away = gamestats[game]['home'], gamestats[game]['away']