Skip to content

Commit

Permalink
Put unranked players at bottom of leaderboard
Browse files Browse the repository at this point in the history
  • Loading branch information
syargeau committed Jun 15, 2018
1 parent 8b7bc53 commit c55de5b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
35 changes: 26 additions & 9 deletions leaderboard/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,38 @@ <h1>PongBoard</h1>
<th>PPG</th>
<th>AvgDiff</th>
</tr>
{% for ranking in leaderboard %}
{% for ranked_player in ranked_players %}
<tr id='player-ranking'>
<td>{{ forloop.counter }}</td>
<td>{{ ranking.player.full_name }}</td>
<td>{{ ranking.rating }}</td>
<td>{{ ranking.games_played }}</td>
<td>{{ ranking.wins }}</td>
<td>{{ ranking.losses }}</td>
<td>{{ ranking.win_percent|percentage:1 }}</td>
<td>{{ ranking.points_per_game|floatformat }}</td>
<td>{{ ranking.avg_point_differential|stringformat:"+.1f" }}</td>
<td>{{ ranked_player.player.full_name }}</td>
<td>{{ ranked_player.rating }}</td>
<td>{{ ranked_player.games_played }}</td>
<td>{{ ranked_player.wins }}</td>
<td>{{ ranked_player.losses }}</td>
<td>{{ ranked_player.win_percent|percentage:1 }}</td>
<td>{{ ranked_player.points_per_game|floatformat }}</td>
<td>{{ ranked_player.avg_point_differential|stringformat:"+.1f" }}</td>
</tr>
{% endfor %}
{% for unranked_player in unranked_players %}
<tr id='player-ranking'>
<td>N/A</td>
<td>{{ unranked_player.player.full_name }}</td>
<td>{{ unranked_player.rating }}</td>
<td>{{ unranked_player.games_played }}</td>
<td>{{ unranked_player.wins }}</td>
<td>{{ unranked_player.losses }}</td>
<td>{{ unranked_player.win_percent|percentage:1 }}</td>
<td>{{ unranked_player.points_per_game|floatformat }}</td>
<td>{{ unranked_player.avg_point_differential|stringformat:"+.1f" }}</td>
</tr>
{% endfor %}
</table>

{% if unranked_players %}
<p id='unranked-warning'>Note: you must play a minimum of 5 games before being ranked.</p>
{% endif %}

<ul id="recent-matches" list-style-type="none">
{% for match in recent_matches %}
<li>{{ match.description }}</li>
Expand Down
7 changes: 5 additions & 2 deletions leaderboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
def home_page(request):
"""Render view for home page."""
recent_matches = Match.get_recent_matches(num_matches=20)
leaderboard = PlayerRating.objects.all().order_by('-rating')
rated_players = PlayerRating.objects.all().order_by('-rating')
ranked_players = [player for player in rated_players if player.games_played >= 5]
unranked_players = [player for player in rated_players if player.games_played < 5]
match_form = MatchForm()
player_form = PlayerForm()
if request.method == 'POST':
Expand All @@ -28,6 +30,7 @@ def home_page(request):
'recent_matches': recent_matches,
'match_form': match_form,
'player_form': player_form,
'leaderboard': leaderboard
'ranked_players': ranked_players,
'unranked_players': unranked_players
}
)

0 comments on commit c55de5b

Please sign in to comment.