Ejemplo n.º 1
0
import NBA_loadandsplit as LAS
import NBA_parseplaybyplay as PPBP
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()
Ejemplo n.º 2
0
    '''
    out = dict()
    for game in games.keys():
        out[game] = game.getgame()
    out['statlist'] = NPAP.getstatlist()
    return out

print('checking files and loading game files...')
chdir = os.getcwd()
pbpfname    = "playbyplay20072008reg20081211"
plafname    = "players20072008reg20081211"
fhandlepbp  = os.path.join(chdir,'DataFiles', pbpfname+'.txt')
fhandlenam  = os.path.join(chdir,'DataFiles', plafname+'.txt')

# initialize players dictionary, game dictionary
pstats = LAS.createplayers(fhandlenam)
gstats = []
# 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():
    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:
Ejemplo n.º 3
0
import NBA_parseplaybyplay as PPBP
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')