Пример #1
0
def show_season_table(db, player, stype, week_range=None, pos=None):
    if pos is None:
        pos = player.position
    _, cur_year, _ = nfldb.current(db)

    pstats = []
    for year in range(2009, cur_year+1):
        qgames = nflcmd.query_games(db, player, year, stype, week_range)
        games = qgames.as_games()
        if len(games) == 0:
            continue

        game_stats = map(partial(nflcmd.Game.make, db, player), games)
        agg = qgames.sort([]).as_aggregate()
        pstats.append(nflcmd.Games(db, year, game_stats, agg[0]))

    spec = prefix_season + nflcmd.columns['season'][nflcmd.pcolumns[pos]]
    rows = [nflcmd.header_row(spec)]
    rows += map(partial(nflcmd.pstat_to_row, spec), pstats)
    if len(pstats) > 1:
        summary = nfldb.aggregate(pstat._pstat for pstat in pstats)[0]
        allrows = nflcmd.Games(db, '-', [], summary)
        allrows._fgs = []
        for pstat in pstats:
            allrows._fgs += pstat.fgs
            allrows.games += pstat.games
        rows.append(nflcmd.pstat_to_row(spec, allrows))
    print(nflcmd.table(rows))
Пример #2
0
def show_game_table(db, player, year, stype, week_range=None, pos=None):
    if pos is None:
        pos = player.position

    games = nflcmd.query_games(db, player, year, stype, week_range).as_games()
    pstats = map(partial(nflcmd.Game.make, db, player), games)

    spec = prefix_game + nflcmd.columns['game'][nflcmd.pcolumns[pos]]
    rows = [nflcmd.header_row(spec)]
    rows += map(partial(nflcmd.pstat_to_row, spec), pstats)
    if len(pstats) > 1:
        summary = nfldb.aggregate(pstat._pstat for pstat in pstats)[0]
        allrows = nflcmd.Game(db, None, '-', summary)
        allrows._fgs = []
        for pstat in pstats:
            allrows._fgs += pstat.fgs
        rows.append(nflcmd.pstat_to_row(spec, allrows))
    print(nflcmd.table(rows))
Пример #3
0
 def to_games(agg):
     syrs = years[0] if len(years) == 1 else '%d-%d' % (years[0], years[-1])
     qgames = nflcmd.query_games(db, agg.player, years, stype, weeks)
     return nflcmd.Games(db, syrs, qgames.as_games(), agg)