From 5eeab018792aed2431361b7e7f0ab814f0636634 Mon Sep 17 00:00:00 2001 From: Brennan Bibic Date: Wed, 14 Aug 2024 15:47:51 -0400 Subject: [PATCH] Fix email spam, maybe do color formatting --- ranked/templates/ranked/leaderboard.html | 61 +++++++++++++----------- ranked/templates/ranked/player_info.html | 14 +++--- ranked/templatetags/rank_filter.py | 22 ++++----- 3 files changed, 52 insertions(+), 45 deletions(-) diff --git a/ranked/templates/ranked/leaderboard.html b/ranked/templates/ranked/leaderboard.html index d4abb82..4967900 100644 --- a/ranked/templates/ranked/leaderboard.html +++ b/ranked/templates/ranked/leaderboard.html @@ -15,35 +15,40 @@

style="text-align: center" > - # - Player - ELO - MMR - Rank - # Played - Win % - Wins - Losses - Ties + + # + Player + ELO + MMR + Rank + # Played + Win % + Wins + Losses + Ties + - {% for player in players %} - - {{forloop.counter}} - - {{player.player}} - - {{ player.elo|floatformat:1 }} - {{ player.mmr|floatformat:1 }} - {% mmr_to_rank player.mmr highest_mmr lowest_mmr %} - {{player.matches_played}} - {{ player.win_rate|floatformat:2 }}% - {{player.matches_won}} - {{player.matches_lost}} - {{player.matches_drawn}} - - {% endfor %} + + {% for player in players %} + + {{forloop.counter}} + + {{player.player}} + + {{ player.elo|floatformat:1 }} + {{ player.mmr|floatformat:1 }} + {% mmr_to_rank player.mmr highest_mmr lowest_mmr as rank color %} + {{ rank }} + {{player.matches_played}} + {{ player.win_rate|floatformat:2 }}% + {{player.matches_won}} + {{player.matches_lost}} + {{player.matches_drawn}} + + {% endfor %} + {% endblock %} diff --git a/ranked/templates/ranked/player_info.html b/ranked/templates/ranked/player_info.html index 268daa8..95a0e90 100644 --- a/ranked/templates/ranked/player_info.html +++ b/ranked/templates/ranked/player_info.html @@ -1,4 +1,6 @@ -{% extends 'home/base.html' %} {% block content %} {% load rank_filter %} +{% extends 'home/base.html' %} +{% block content %} +{% load rank_filter %}
@@ -35,10 +37,10 @@

-

{{ mmr|get_rank }}

+ {% mmr_to_rank player.mmr highest_mmr lowest_mmr as rank color %} +

{{ rank }}

- {{ player.elo|floatformat:1 }} ELO
{{ mmr|floatformat:1 }} - MMR + {{ player.elo|floatformat:1 }} ELO
{{ player.mmr|floatformat:1 }} MMR

@@ -102,10 +104,10 @@

const eloHistoryChart = new Chart(document.getElementById('chart-elo-history').getContext('2d'), { type: 'line', data: { - labels: JSON.parse("{{match_labels}}"), + labels: JSON.parse("{{ match_labels }}"), datasets: [{ label: 'ELO', - data: JSON.parse("{{elo_history}}"), + data: JSON.parse("{{ elo_history }}"), backgroundColor: '#ffc107', borderColor: '#ffc107', }] diff --git a/ranked/templatetags/rank_filter.py b/ranked/templatetags/rank_filter.py index 770f42e..b2f3e68 100644 --- a/ranked/templatetags/rank_filter.py +++ b/ranked/templatetags/rank_filter.py @@ -5,29 +5,29 @@ @register.simple_tag def mmr_to_rank(mmr, highest_mmr, lowest_mmr): if highest_mmr == lowest_mmr: - return 'Stone' # All players have the same MMR, edge case + return 'Stone', '#ffffff' # All players have the same MMR, edge case # Calculate the percentile percentile = (highest_mmr - mmr) / (highest_mmr - lowest_mmr) # Determine rank based on percentile if percentile <= 0.1: - return 'Challenger' + return 'Challenger', '#ffffff' elif percentile <= 0.2: - return 'Grandmaster' + return 'Grandmaster', '#ffffff' elif percentile <= 0.3: - return 'Master' + return 'Master', '#ffffff' elif percentile <= 0.4: - return 'Diamond' + return 'Diamond', '#ffffff' elif percentile <= 0.5: - return 'Platinum' + return 'Platinum', '#ffffff' elif percentile <= 0.6: - return 'Gold' + return 'Gold', '#ebce75' elif percentile <= 0.7: - return 'Silver' + return 'Silver', '#ffffff' elif percentile <= 0.8: - return 'Bronze' + return 'Bronze', '#ffffff' elif percentile <= 0.9: - return 'Iron' + return 'Iron', '#ffffff' else: - return 'Stone' + return 'Stone', '#ffffff'