Пример #1
0
def all_coaches_by_year(data,
                        start=2007,
                        end=datetime.datetime.now().year + 1):
    import stats.collate
    #data = stats.collate.collate()
    for year in range(2007, end):
        coaches = coach_list.list_all_coaches2(data=data, year=year)
        #print( "{} coaches {} ".format(year, len(coaches)))
        coaches = [
            c for c in coaches if c["games"]["total"]["gamesplayed"] > 0
        ]
        coaches = sorted(coaches, key=lambda x: x["nick"])
        coaches = sorted(coaches,
                         key=lambda x: x["games"]["total"]["cas"],
                         reverse=True)
        coaches = sorted(coaches,
                         key=lambda x: x["games"]["total"]["td"],
                         reverse=True)
        coaches = sorted(coaches,
                         key=lambda x: x["games"]["total"]["gamesplayed"],
                         reverse=True)
        coaches = sorted(coaches,
                         key=lambda x: x["games"]["total"]["performance"],
                         reverse=True)
        coaches = sorted(coaches,
                         key=lambda x: x["games"]["total"]["points"],
                         reverse=True)
        #print( "{} coaches {} ".format(year, len(coaches)))
        with open("output/coaches-{}.html".format(year), "w") as fp:
            fp.write(
                export.get_template("coach/all_coaches2.html").render(
                    coaches=coaches, title="All coaches in {}".format(year)))
Пример #2
0
def all_teams_by_year(data, year):
    teams = team_list.list_all_teams_by_year(year)
    return export.get_template("team/all_team.html").render(
        teams_average=team_list.format_for_average(teams),
        teams_total=team_list.format_for_total(teams),
        teams=teams,
        title="All teams in {}".format(year),
        subtitle="sorted by points")
Пример #3
0
def all_teams(data):
    teams = team_list.list_all_teams_by_points(data=data)

    return export.get_template("team/all_team.html").render(
        teams_average=team_list.format_for_average(teams),
        teams_total=team_list.format_for_total(teams),
        teams=team_list.list_all_teams_by_points(),
        title="All teams",
        subtitle="sorted by points")
Пример #4
0
def team_stats(data, teams, games, the_team):
    #team_data = coach_list.coach_data(the_team, data)

    games_for_team = match_list.we_are_team(list(data["game"].values()),
                                            the_team)

    games_for_team = sorted(games_for_team,
                            key=lambda g: int(g["matchid"]),
                            reverse=True)
    games_for_team = sorted(games_for_team,
                            key=lambda g: g["date"],
                            reverse=True)

    game_total = match_list.sum_game(games_for_team)
    streaks = match_list.game_streaks(games_for_team)

    games_by_race = match_list.sum_game_by_group(
        games_for_team, match_list.group_games_by_race)

    games_by_our_coach = match_list.sum_game_by_group(
        games_for_team, match_list.group_games_by_our_coach)

    #FIXME, improve nick lookup
    for c in games_by_our_coach:
        if c["title"] in data["_coachid"]:
            c["title"] = data["_coachid"][c["title"]]["nick"]
            c["link"] = "/coach/{}.html".format(c["title"].replace(" ", "-"))
        else:
            c["title"] = "Unknown {}".format(c["title"])
            c["link"] = "/coaches.html"

    export.write_html(
        export.get_template("team/team.html").render(
            team_data=team_list.team_data(the_team, games_for_team),
            stats_average=game_total["average"],
            stats_total=game_total["total"],
            matches=games_for_team,
            games_by_race=games_by_race,
            games_by_our_coach=games_by_our_coach,
            show_coaches=len(games_by_our_coach) > 1,
            coaches=data["coach"],
            streaks=streaks,
            teamname=the_team["name"],
            teamid=the_team["id"],
            title="{}".format(the_team["name"], subtitle="sorted by date")),
        "team/{}".format(the_team["id"]))
Пример #5
0
def teams_by_coach(data):
    coaches = coach.list_coaches()
    teams = sorted(team_list.list_all_teams_by_points(data),
                   key=lambda x: x["gamesplayed"],
                   reverse=True)

    add_elo(data)
    #games = list_all_games_by_coach()

    for c in coaches:
        name = c["nick"]

        if name in data["coach"] and "elo" in data["coach"][name]:
            c["elo"] = data["coach"][name]["elo"]

        cgames = list(
            sorted(coach_list.list_all_games_by_coach2(data, name),
                   key=lambda x: int(x["matchid"]),
                   reverse=True))
        cgames = list(sorted(cgames, key=lambda x: x["date"], reverse=True))
        cgames = deepcopy(match_list.we_are_coach(cgames, c))

        team_coach = list(
            sorted(match_list.games_for_teams(data, cgames).values(),
                   key=lambda x: x["name"]))
        team_coach = sorted(team_coach,
                            key=lambda x: x["total"]["performance"],
                            reverse=True)
        team_coach = sorted(team_coach,
                            key=lambda x: x["total"]["gamesplayed"],
                            reverse=True)

        with open("output/coach/{}.html".format(name.replace(" ", "-")),
                  "w") as fp:
            fp.write(all_teams_for_coach(data, c, team_coach, cgames))

        with open("output/coach/{}-games.html".format(name.replace(" ", "-")),
                  "w") as fp:
            fp.write(
                export.get_template("coach/coach-games.html").render(
                    coach=c,
                    games=cgames,
                    title="All games by {}".format(name)))
Пример #6
0
def all_coaches(data):
    coaches = coach_list.list_all_coaches2(data)
    add_elo(data)
    coaches = [c for c in coaches if c["games"]["total"]["gamesplayed"] > 0]
    coaches = sorted(coaches,
                     key=lambda x: x["games"]["total"]["td"],
                     reverse=True)
    coaches = sorted(coaches,
                     key=lambda x: x["games"]["total"]["performance"],
                     reverse=True)
    coaches = sorted(coaches,
                     key=lambda x: x["games"]["total"]["points"],
                     reverse=True)
    #coaches = sorted(coaches, key=lambda x: x["elo"]["rating"], reverse=True)

    with open("output/coaches.html", "w") as fp:
        fp.write(
            export.get_template("coach/all_coaches2.html").render(
                display_rating=True,
                coaches=coaches,
                title="All coaches through all time"))
Пример #7
0
def all_teams_for_coach(data, coach, coach_teams, coach_games):
    game_total = match_list.sum_game(coach_games)
    streaks = match_list.game_streaks(coach_games)
    streaks.update(coach_list.coach_streaks(coach_games))

    games_with_race = match_list.sum_game_by_group(
        coach_games, match_list.group_games_with_race)
    games_by_race = match_list.sum_game_by_group(
        coach_games, match_list.group_games_by_race)
    games_by_weekday = match_list.games_by_weekday(coach_games)
    games_by_coach = match_list.sum_game_by_group(
        coach_games, match_list.group_games_by_coach)

    #FIXME. group_games_by_coach should return proper coach
    for c in games_by_coach:
        if c["title"] in data["_coachid"]:
            c["title"] = data["_coachid"][c["title"]]["nick"]
            c["link"] = "/coach/{}.html".format(c["title"].replace(" ", "-"))
        else:
            c["title"] = "Unknown {}".format(c["title"])
            c["link"] = "/coaches.html"

    return export.get_template("coach/coach.html").render(
        coach_name=coach["nick"],
        coach=coach_list.coach_data(coach, coach_games),
        streaks=streaks,
        games_with_race=games_with_race,
        games_by_race=games_by_race,
        games_by_coach=games_by_coach,
        games_by_weekday=games_by_weekday,
        more_games=len(coach_games) - 10,
        teams=coach_teams,
        stats_average=game_total["average"],
        stats_total=game_total["total"],
        games=coach_games[:10],
        title="{}".format(coach["nick"]))
Пример #8
0
def all_games(data):
    games = list_all_matches(data)
    return export.get_template("game/all_games.html").render(
        matches = games, 
        title="All games",
        subtitle="sorted by date")
Пример #9
0
def all_games_by_year(data, year):
    return export.get_template("game/all_games.html").render(
        matches = list_all_games_by_year(data, year), 
        title="All games in {}".format(year),
        subtitle="sorted by date")