Skip to content

Commit

Permalink
Stats became elo and rankings is a new page. issue #18
Browse files Browse the repository at this point in the history
  • Loading branch information
pizzato committed Dec 17, 2015
1 parent 96380b7 commit 9e4944b
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 4 deletions.
21 changes: 18 additions & 3 deletions foosball.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ def player_name_edit(name):
@app.route('/teams')
def teams_get():
all_teams = db.get_all_teams()
return render_template('teams.html', teams=all_teams)
sorted_teams = sorted(all_teams, key=lambda team: -team.team_stats.elo_rating)
return render_template('teams.html', teams=sorted_teams)


@app.route('/teams/<team_id>', methods=['GET'])
Expand Down Expand Up @@ -188,8 +189,8 @@ def is_game_on():
else:
return "No"

@app.route('/stats', methods=['GET'])
def stats_get():
@app.route('/rankings', methods=['GET'])
def rankings_get():
all_players = db.get_all_players()

players_ranking = list(enumerate(sorted(all_players, key=lambda p: p.player_stats.elo_rating, reverse=True)))
Expand All @@ -201,6 +202,20 @@ def stats_get():
team_ranking = list(enumerate(sorted(all_teams, key=lambda t: t.team_stats.elo_rating, reverse=True)))
return render_template('stats_page.html', players_ranking=players_ranking, attack_ranking=attack_ranking, defense_ranking=defense_ranking, team_ranking=team_ranking, win_perc_ranking=win_perc_ranking)

@app.route('/elo', methods=['GET'])
def elo_get():
all_players = db.get_all_players()

players_ranking = list(enumerate(sorted(all_players, key=lambda p: p.player_stats.elo_rating, reverse=True)))
attack_ranking = list(enumerate(sorted(all_players, key=lambda p: p.attack_stats.elo_rating, reverse=True)))
defense_ranking = list(enumerate(sorted(all_players, key=lambda p: p.defense_stats.elo_rating, reverse=True)))
win_perc_ranking = list(enumerate(sorted(all_players, key=lambda p: p.player_stats.perc_win(), reverse=True)))

all_teams = db.get_all_teams()
team_ranking = list(enumerate(sorted(all_teams, key=lambda t: t.team_stats.elo_rating, reverse=True)))
return render_template('elo_page.html', players_ranking=players_ranking, attack_ranking=attack_ranking, defense_ranking=defense_ranking, team_ranking=team_ranking, win_perc_ranking=win_perc_ranking)




@app.route('/redo_stats', methods=['GET'])
Expand Down
3 changes: 2 additions & 1 deletion templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
<p class="navbar-text"><a href="{{ url_for('games_get_post') }}">Games</a></p>
<p class="navbar-text"><a href="{{ url_for('players_get_post') }}">Players</a></p>
<p class="navbar-text"><a href="{{ url_for('teams_get') }}">Teams</a></p>
<p class="navbar-text"><a href="{{ url_for('stats_get') }}">Stats</a></p>
<p class="navbar-text"><a href="{{ url_for('elo_get') }}">Elo</a></p>
<p class="navbar-text"><a href="{{ url_for('rankings_get') }}">Rankings</a></p>

</div>
</nav>
Expand Down
111 changes: 111 additions & 0 deletions templates/elo_page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
{% extends "base.html" %}
{% import "bootstrap/utils.html" as utils %}


{% block head %}
{{super()}}
{%- endblock %}

{% block content %}


<div class="container">

<div class="col-xs-2">
<div class="h3">Player</div>
<div class="row">
{% for pos, player in players_ranking %}
<div class="caption text-center">{{ pos+1 }}: {{ player.player_stats.elo_rating_str() }}</div>
<div class="thumbnail col-md-12 col-xs-12">
<a href="{{ url_for('players_name_get', name=player.name) }}">
<img src="{{ player.photo }}" class="player" alt="{{ player.name|safe }}" />
<div class="caption post-content h3 text-center">
{{ player.name }}
</div>
</a>
</div>
{% else %}
<em>Unbelievable. No players, please add</em>
{% endfor %}

</div>
</div>

<div class="col-xs-offset-1 col-xs-2">
<div class="h3">Attack</div>
<div class="row">
{% for pos, player in attack_ranking %}
<div class="caption text-center">{{ pos+1 }}: {{ player.attack_stats.elo_rating_str() }}</div>
<div class="thumbnail col-md-12 col-xs-12">
<a href="{{ url_for('players_name_get', name=player.name) }}">
<img src="{{ player.photo }}" class="player" alt="{{ player.name|safe }}" />
<div class="caption post-content h3 text-center">
{{ player.name }}
</div>
</a>
</div>
{% else %}
<em>Unbelievable. No players, please add</em>
{% endfor %}

</div>
</div>


<div class="col-xs-offset-1 col-xs-2">
<div class="h3">Defense</div>
<div class="row">
{% for pos, player in defense_ranking %}
<div class="caption text-center">{{ pos+1 }}: {{ player.defense_stats.elo_rating_str() }}</div>
<div class="thumbnail col-md-12 col-xs-12">
<a href="{{ url_for('players_name_get', name=player.name) }}">
<img src="{{ player.photo }}" class="player" alt="{{ player.name|safe }}" />
<div class="caption post-content h3 text-center">
{{ player.name }}
</div>
</a>
</div>
{% else %}
<em>Unbelievable. No players, please add</em>
{% endfor %}

</div>
</div>


<div class="col-xs-offset-1 col-xs-2">
<div class="h3">Team</div>
<div class="row">
{% for pos, team in team_ranking %}
<div class="caption text-center">{{ pos+1 }}: {{ team.team_stats.elo_rating_str() }}</div>
<div class="thumbnail col-md-6 col-xs-6">
<a href="{{ url_for('players_name_get', name=team.defense_player.name) }}">
<img src="{{ team.defense_player.photo }}" class="player" alt="{{ team.defense_player.name|safe }}" />
<div class="caption post-content h4 text-center">
{{ team.defense_player.name }}
</div>
</a>
</div>
<div class="thumbnail col-md-6 col-xs-6">
<a href="{{ url_for('players_name_get', name=team.attack_player.name) }}">
<img src="{{ team.attack_player.photo }}" class="player" alt="{{ team.attack_player.name|safe }}" />
<div class="caption post-content h4 text-center">
{{ team.attack_player.name }}
</div>
</a>
</div>

{% else %}
<em>Unbelievable. No teams, please add</em>
{% endfor %}

</div>
</div>

</div>





{% endblock %}

0 comments on commit 9e4944b

Please sign in to comment.