Skip to content

Commit

Permalink
Add percentages to stats page
Browse files Browse the repository at this point in the history
  • Loading branch information
AdmiralGT committed Aug 30, 2024
1 parent 8854bd0 commit 799f65b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
37 changes: 25 additions & 12 deletions scripts/templates/statistics.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% extends 'base.html' %}

{% load bootstrap4 %}
{% load botc_script_tags %}

{% block content %}

Expand Down Expand Up @@ -73,8 +74,9 @@ <h4 class="mt-2">Most popular Townsfolk</h4>
<tbody>
{% for character, count in Townsfolk %}
<tr class='row{{forloop.counter|stringformat:"02d"}}' background-color="#">
<td class="w-75"><a href="/statistics/{{ character.character_id }}" class="text-dark">{{ character.character_name }}</a></td>
<td class="w-50"><a href="/statistics/{{ character.character_id }}" class="text-dark">{{ character.character_name }}</a></td>
<td class="w-25 text-center">{{ count }}</td>
<td class="w-25 text-center">{% get_character_percentage count total %}</td>
</tr>
{% endfor %}
</tbody>
Expand All @@ -86,8 +88,9 @@ <h4 class="mt-2">Least popular Townsfolk</h4>
<tbody>
{% for character, count in Townsfolkleast %}
<tr class='row{{forloop.counter|stringformat:"02d"}}' background-color="#">
<td class="w-75"><a href="/statistics/{{ character.character_id }}" class="text-dark">{{ character.character_name }}</a></td>
<td class="w-50"><a href="/statistics/{{ character.character_id }}" class="text-dark">{{ character.character_name }}</a></td>
<td class="w-25 text-center">{{ count }}</td>
<td class="w-25 text-center">{% get_character_percentage count total %}</td>
</tr>
{% endfor %}
</tbody>
Expand All @@ -102,8 +105,9 @@ <h4 class="mt-2">Most popular Outsider</h4>
<tbody>
{% for character, count in Outsider %}
<tr class='row{{forloop.counter|stringformat:"02d"}}' background-color="#">
<td class="w-75"><a href="/statistics/{{ character.character_id }}" class="text-dark">{{ character.character_name }}</a></td>
<td class="w-50"><a href="/statistics/{{ character.character_id }}" class="text-dark">{{ character.character_name }}</a></td>
<td class="w-25 text-center">{{ count }}</td>
<td class="w-25 text-center">{% get_character_percentage count total %}</td>
</tr>
{% endfor %}
</tbody>
Expand All @@ -115,8 +119,9 @@ <h4 class="mt-2">Least popular Outsider</h4>
<tbody>
{% for character, count in Outsiderleast %}
<tr class='row{{forloop.counter|stringformat:"02d"}}' background-color="#">
<td class="w-75"><a href="/statistics/{{ character.character_id }}" class="text-dark">{{ character.character_name }}</a></td>
<td class="w-50"><a href="/statistics/{{ character.character_id }}" class="text-dark">{{ character.character_name }}</a></td>
<td class="w-25 text-center">{{ count }}</td>
<td class="w-25 text-center">{% get_character_percentage count total %}</td>
</tr>
{% endfor %}
</tbody>
Expand All @@ -131,8 +136,9 @@ <h4 class="mt-2">Most popular Minions</h4>
<tbody>
{% for character, count in Minion %}
<tr class='row{{forloop.counter|stringformat:"02d"}}' background-color="#">
<td class="w-75"><a href="/statistics/{{ character.character_id }}" class="text-dark">{{ character.character_name }}</a></td>
<td class="w-50"><a href="/statistics/{{ character.character_id }}" class="text-dark">{{ character.character_name }}</a></td>
<td class="w-25 text-center">{{ count }}</td>
<td class="w-25 text-center">{% get_character_percentage count total %}</td>
</tr>
{% endfor %}
</tbody>
Expand All @@ -144,8 +150,9 @@ <h4 class="mt-2">Least popular Minions</h4>
<tbody>
{% for character, count in Minionleast %}
<tr class='row{{forloop.counter|stringformat:"02d"}}' background-color="#">
<td class="w-75"><a href="/statistics/{{ character.character_id }}" class="text-dark">{{ character.character_name }}</a></td>
<td class="w-50"><a href="/statistics/{{ character.character_id }}" class="text-dark">{{ character.character_name }}</a></td>
<td class="w-25 text-center">{{ count }}</td>
<td class="w-25 text-center">{% get_character_percentage count total %}</td>
</tr>
{% endfor %}
</tbody>
Expand All @@ -160,8 +167,9 @@ <h4 class="mt-2">Most popular Demons</h4>
<tbody>
{% for character, count in Demon %}
<tr class='row{{forloop.counter|stringformat:"02d"}}' background-color="#">
<td class="w-75"><a href="/statistics/{{ character.character_id }}" class="text-dark">{{ character.character_name }}</a></td>
<td class="w-50"><a href="/statistics/{{ character.character_id }}" class="text-dark">{{ character.character_name }}</a></td>
<td class="w-25 text-center">{{ count }}</td>
<td class="w-25 text-center">{% get_character_percentage count total %}</td>
</tr>
{% endfor %}
</tbody>
Expand All @@ -173,8 +181,9 @@ <h4 class="mt-2">Least popular Demons</h4>
<tbody>
{% for character, count in Demonleast %}
<tr class='row{{forloop.counter|stringformat:"02d"}}' background-color="#">
<td class="w-75"><a href="/statistics/{{ character.character_id }}" class="text-dark">{{ character.character_name }}</a></td>
<td class="w-50"><a href="/statistics/{{ character.character_id }}" class="text-dark">{{ character.character_name }}</a></td>
<td class="w-25 text-center">{{ count }}</td>
<td class="w-25 text-center">{% get_character_percentage count total %}</td>
</tr>
{% endfor %}
</tbody>
Expand All @@ -189,8 +198,9 @@ <h4 class="mt-2">Most popular Travellers</h4>
<tbody>
{% for character, count in Traveller %}
<tr class='row{{forloop.counter|stringformat:"02d"}}' background-color="#">
<td class="w-75"><a href="/statistics/{{ character.character_id }}" class="text-dark">{{ character.character_name }}</a></td>
<td class="w-50"><a href="/statistics/{{ character.character_id }}" class="text-dark">{{ character.character_name }}</a></td>
<td class="w-25 text-center">{{ count }}</td>
<td class="w-25 text-center">{% get_character_percentage count total %}</td>
</tr>
{% endfor %}
</tbody>
Expand All @@ -202,8 +212,9 @@ <h4 class="mt-2">Least popular Travellers</h4>
<tbody>
{% for character, count in Travellerleast %}
<tr class='row{{forloop.counter|stringformat:"02d"}}' background-color="#">
<td class="w-75"><a href="/statistics/{{ character.character_id }}" class="text-dark">{{ character.character_name }}</a></td>
<td class="w-50"><a href="/statistics/{{ character.character_id }}" class="text-dark">{{ character.character_name }}</a></td>
<td class="w-25 text-center">{{ count }}</td>
<td class="w-25 text-center">{% get_character_percentage count total %}</td>
</tr>
{% endfor %}
</tbody>
Expand All @@ -218,8 +229,9 @@ <h4 class="mt-2">Most popular Fabled</h4>
<tbody>
{% for character, count in Fabled %}
<tr class='row{{forloop.counter|stringformat:"02d"}}' background-color="#">
<td class="w-75"><a href="/statistics/{{ character.character_id }}" class="text-dark">{{ character.character_name }}</a></td>
<td class="w-50"><a href="/statistics/{{ character.character_id }}" class="text-dark">{{ character.character_name }}</a></td>
<td class="w-25 text-center">{{ count }}</td>
<td class="w-25 text-center">{% get_character_percentage count total %}</td>
</tr>
{% endfor %}
</tbody>
Expand All @@ -231,8 +243,9 @@ <h4 class="mt-2">Least popular Fabled</h4>
<tbody>
{% for character, count in Fabledleast %}
<tr class='row{{forloop.counter|stringformat:"02d"}}' background-color="#">
<td class="w-75"><a href="/statistics/{{ character.character_id }}" class="text-dark">{{ character.character_name }}</a></td>
<td class="w-50"><a href="/statistics/{{ character.character_id }}" class="text-dark">{{ character.character_name }}</a></td>
<td class="w-25 text-center">{{ count }}</td>
<td class="w-25 text-center">{% get_character_percentage count total %}</td>
</tr>
{% endfor %}
</tbody>
Expand Down
5 changes: 5 additions & 0 deletions scripts/templatetags/botc_script_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,8 @@ def get_language_name(locale: str):
return get_language_name("ar_KW")

return locale

@register.simple_tag()
def get_character_percentage(count: int, total: int):
percentage = count * 100 / total
return f"{percentage:.2f}%"

0 comments on commit 799f65b

Please sign in to comment.