Esempio n. 1
0
def player_page(year, player_id):
    player = Player.query.get(player_id)
    name = player.name
    years = []
    for team in player.teams:
        years.append((team.year, team.id))
    stats = []
    for entry in years:
        player = {}
        summary = player_summary(year=entry[0],
                                 team_id=entry[1],
                                 player_id=player_id)
        if name in summary:
            player = summary[name]
        player['team'] = str(Team.query.get(entry[1]))
        player['team_id'] = entry[1]
        player['year'] = entry[0]
        stats.append(player)
    return render_template("website/player.html",
                           route=Routes,
                           base=base_data(year),
                           stats=stats,
                           title="Player Stats",
                           name=name,
                           year=year)
Esempio n. 2
0
def player_page(year, player_id):
    player = Player.query.get(player_id)
    name = player.name
    years = []
    for team in player.teams:
        years.append((team.year, team.id))
    stats = []
    for entry in years:
        player = {}
        summary = player_summary(year=entry[0], team_id=entry[1], player_id=player_id)
        if name in summary:
            player = summary[name]
        player["team"] = str(Team.query.get(entry[1]))
        player["team_id"] = entry[1]
        player["year"] = entry[0]
        stats.append(player)
    return render_template(
        "website/player.html",
        route=Routes,
        base=base_data(year),
        stats=stats,
        title="Player Stats",
        name=name,
        year=year,
    )
Esempio n. 3
0
def stats_page(year):
    players = player_summary(year)
    return render_template("website/stats.html",
                           route=Routes,
                           base=base_data(year),
                           title="Players Stats",
                           year=year,
                           players=players)
def player_page(year, player_id):
    player = Player.query.get(player_id)
    if player is None:
        return render_template("website/notFound.html",
                               route=Routes,
                               base=base_data(year),
                               title="Player not found",
                               year=year,
                               user_info=get_user_information())
    name = player.name
    years = []
    for team in player.teams:
        years.append((team.year, team.id))
    stats = []
    for entry in years:
        player = {}
        summary = player_summary(year=entry[0],
                                 team_id=entry[1],
                                 player_id=player_id)
        if name in summary:
            player = summary[name]
        else:
            player = {
                's': 0,
                'd': 0,
                'hr': 0,
                'ss': 0,
                'k': 0,
                'fo': 0,
                'fc': 0,
                'e': 0,
                'go': 0,
                'id': player_id,
                'rbi': 0,
                'avg': 0.000,
                'bats': 0
            }
        player['team'] = str(Team.query.get(entry[1]))
        player['team_id'] = entry[1]
        player['year'] = entry[0]
        stats.append(player)
    return render_template("website/player.html",
                           route=Routes,
                           base=base_data(year),
                           stats=stats,
                           title="Player Stats",
                           name=name,
                           year=year,
                           user_info=get_user_information())
def get_team(year, tid: int) -> dict:
    result = Team.query.get(tid)
    team = None
    if result is not None:
        captain = "TBD"
        players = []
        for player in result.players:
            if player.name not in players:
                players.append(player.json())
        if result.player_id is not None:
            captain = str(Player.query.get(result.player_id))
        p_ = player_summary(team_id=tid)
        stats = []
        for name in p_:
            sp = (
                (
                    p_[name]["s"] +
                    p_[name]["ss"] +
                    p_[name]["d"] * 2 +
                    p_[name]["hr"] * 4
                ) / p_[name]['bats']
            )
            stats.append({
                'id': p_[name]['id'],
                'name': name,
                'ss': p_[name]['ss'],
                's': p_[name]['s'],
                'd': p_[name]['d'],
                'hr': p_[name]['hr'],
                'bats': p_[name]['bats'],
                'ba': "{0:.3f}".format(p_[name]['avg']),
                'sp': "{0:.3f}".format(sp)})
        record = single_team(tid)
        team = {'name': str(result),
                'league': str(League.query.get(result.league_id)),
                'captain': str(captain),
                'captain_id': result.player_id,
                'players': players,
                'record': record,
                'wins': record[tid]['wins'],
                'losses': record[tid]['losses'],
                'ties': record[tid]['ties'],
                'stats': stats}
    return team
Esempio n. 6
0
def get_team(year, tid):
    result = Team.query.get(tid)
    team = None
    if result is not None:
        captain = "TBD"
        players = []
        for player in result.players:
            if player.name not in players:
                players.append(player.name)
        if result.player_id is not None:
            captain = str(Player.query.get(result.player_id))
        p_ = player_summary(team_id=tid)
        stats = []
        for name in p_:
            sp = (p_[name]["s"] + p_[name]["ss"] + p_[name]["d"] * 2 + p_[name]["hr"] * 4) / p_[name]["bats"]
            stats.append(
                {
                    "id": p_[name]["id"],
                    "name": name,
                    "ss": p_[name]["ss"],
                    "s": p_[name]["s"],
                    "d": p_[name]["d"],
                    "hr": p_[name]["hr"],
                    "bats": p_[name]["bats"],
                    "ba": "{0:.3f}".format(p_[name]["avg"]),
                    "sp": "{0:.3f}".format(sp),
                }
            )
        #            players.append(name)
        record = single_team(tid)
        team = {
            "name": str(result),
            "league": str(League.query.get(result.league_id)),
            "captain": str(captain),
            "players": players,
            "record": record,
            "wins": record[tid]["wins"],
            "losses": record[tid]["losses"],
            "ties": record[tid]["ties"],
            "stats": stats,
        }
    return team
Esempio n. 7
0
def stats_page(year):
    players = player_summary(year)
    return render_template(
        "website/stats.html", route=Routes, base=base_data(year), title="Players Stats", year=year, players=players
    )