コード例 #1
0
ファイル: web.py プロジェクト: BurntSushi/fanfoot
def league(labels, week=None):
    db = fanfoot.conn()
    if week is None:
        week = db.get_week()

    leagues = []
    for label in labels.split(','):
        leagues.append(find_league(label))

    def week_url(week):
        return url_query('league_week', {}, labels=labels, week=week)

    return dict(
        db=db,
        leagues=leagues,
        week=week,
        week_url=week_url,
    )
コード例 #2
0
ファイル: web.py プロジェクト: BurntSushi/fanfoot
def plays(league_teams, week=None):
    db = fanfoot.conn()
    bench = bottle.request.query.bench == '1'
    live = bottle.request.query.live == '1'
    short = bottle.request.query.short == '1'
    only = bottle.request.query.only == '1'
    if week is None:
        week = db.get_week()

    teams = find_teams_players(db, week, league_teams, bench=bench)
    games = db.games(week)
    plays = db.plays(week)

    def play_sort_notime(p):
        ginfo = nflgame.schedule.games_byid[p.game_id]
        return (nflgame.live._game_datetime(ginfo), p.play_id)
    def play_sort_live(p):
        return (p.timeline, p.play_id)
    plays = sorted(plays, reverse=True,
                   key=play_sort_live if live else play_sort_notime)

    all_players = set()
    for _, players in teams:
        for group in players:
            for player in group:
                if player.stats is None:
                    continue
                all_players.add(player.stats.player_name)

    def highlight_play(play):
        for player_name in all_players:
            if player_name in play.desc:
                return True
        return False

    def week_url(week):
        query_pairs = {
            'bench': int(bench),
            'live': int(live),
            'short': int(short),
            'only': int(only),
        }
        return url_query('plays_week', query_pairs,
                         league_teams=league_teams, week=week)

    return dict(
        nflgame_schedule=nflgame.schedule,
        db=db,
        week=week,
        games=games,
        plays=plays,
        teams=teams,
        highlight_play=highlight_play,
        bench=bench,
        live=live,
        short=short,
        only=only,
        week_url=week_url,
        bench_url=url_query('plays_week',
                            {'bench': 0 if bench else 1,
                             'live': int(live),
                             'short': int(short),
                             'only': int(only),},
                            league_teams=league_teams, week=week),
        live_url=url_query('plays_week',
                           {'bench': int(bench),
                            'live': 0 if live else 1,
                            'short': int(short),
                             'only': int(only),},
                            league_teams=league_teams, week=week),
        short_url=url_query('plays_week',
                            {'bench': int(bench),
                             'live': int(live),
                             'short': 0 if short else 1,
                             'only': int(only),},
                            league_teams=league_teams, week=week),
        only_url=url_query('plays_week',
                           {'bench': int(bench),
                            'live': int(live),
                            'short': int(short),
                            'only': 0 if only else 1},
                           league_teams=league_teams, week=week),
    )
コード例 #3
0
ファイル: web.py プロジェクト: BurntSushi/fanfoot
def team(league_teams, week=None):
    db = fanfoot.conn()
    bench = bottle.request.query.bench == '1'
    detailed = bottle.request.query.detailed == '1'
    headers = fanfoot.player.highlight_headers()
    if week is None:
        week = db.get_week()

    teams = find_teams_players(db, week, league_teams, bench=bench)
    tables = []
    for team, players in teams:
        total = 0.0
        table = []
        for i, (group, header) in enumerate(zip(players, headers)):
            if detailed:
                table.append(header + ['Score'])
            else:
                table.append(header[0:3] + ['Score'])

            for player in group:
                row = player.highlights(get_stats=True)
                score = None

                s = player.computed_score
                if s is not None:
                    score = '%0.2f' % s
                    if player.pos != 'BN':
                        total += s
                else:
                    score = '-'
                if detailed:
                    row += [score]
                else:
                    row = row[0:3] + [score]

                if player.playing():
                    row = ['*'] + row

                table.append(row)
            table.append('')


        max_row = max([len(row) for row in table
                                if len(row) > 0 and row[0] != '*'])
        total_row = [''] * max_row
        total_row[-2] = 'TOTAL:'
        if total == 0.0:
            total_row[-1] = '-'
        else:
            total_row[-1] = '%0.2f' % total
        table.append(total_row)

        tables.append((team, max_row, table))

    def week_url(week):
        query_pairs = {'bench': int(bench), 'detailed': int(detailed)}
        return url_query('team_week', query_pairs,
                         league_teams=league_teams, week=week)

    return dict(
        db=db,
        teams=teams,
        week=week,
        week_url=week_url,
        tables=tables,
        bench=bench,
        detailed=detailed,
        bench_url=url_query('team_week',
                            {'bench': 0 if bench else 1,
                             'detailed': int(detailed)},
                            league_teams=league_teams, week=week),
        detailed_url=url_query('team_week',
                               {'bench': int(bench),
                                'detailed': 0 if detailed else 1},
                               league_teams=league_teams, week=week),
    )