Skip to content

Commit

Permalink
Add hall of fame
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenswat committed Feb 7, 2024
1 parent 6ed4372 commit e7e4777
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{% extends 'content_page.html' %}
{% load humanize %}
{% load cache %}
{% load static %}
{% load module_stats %}

{% block title %}{{ module_type.name }}{% endblock %}

{% block header %}
<div class="container-fluid d-flex flex-column ng-scope">
<div class="row align-items-center bg-primary check-contrast py-5">
<div class="col-xl-9 container-alt text-light toggles-ignore mx-auto">
<h1 class="display-3 mb-0">
<span data-ng-bind="selected.palette.name" class="ng-binding">{{ module_type.name }}</span>
</h1>
</div>
</div>
</div>
{% endblock %}

{% block content_tabs %}
<div class="container">
{% include "abyssal_modules/module_tabs.html" with active_page="hall_of_fame" %}
</div>
{% endblock %}

{% block content %}
<div class="container my-5">
{% for k, v in hof.items %}
<h2>{{ v.0.name }}</h2>

<div class="row">
<div class="col-6">
<h4>Best Modules</h4>

<table class="table stats-table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Module</th>
<th scope="col"><img src="{% static v.0.icon_path %}" title="{{ v.0.name }}"> {{ v.0.name }}</th>
</tr>
</thead>
<tbody>
{% for c in v.1 %}
<tr>
<th scope="row">{{ forloop.counter }}</th>
<td><img src="https://image.eveonline.com/Type/{{ module_type.id }}_32.png" class="module-icon"><a href="{% url 'abyssal_modules:module_view' pk=c.module_id %}">Module {{ c.module_id }}</a></td>
<td>{{ c.value|format_attribute_simple:k }} {{ v.0.unit_str }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<div class="col-6">
<h4>Worst Modules</h4>

<table class="table stats-table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Module</th>
<th scope="col"><img src="{% static v.0.icon_path %}" title="{{ v.0.name }}"> {{ v.0.name }}</th>
</tr>
</thead>
<tbody>
{% for c in v.2 %}
<tr>
<th scope="row">{{ forloop.counter }}</th>
<td><img src="https://image.eveonline.com/Type/{{ module_type.id }}_32.png" class="module-icon"><a href="{% url 'abyssal_modules:module_view' pk=c.module_id %}">Module {{ c.module_id }}</a></td>
<td>{{ c.value|format_attribute_simple:k }} {{ v.0.unit_str }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endfor %}
</div>
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@
<li class="nav-item">
<a class="nav-tab nav-link {% if active_page == 'roll_calculator' %}active{% endif %}" href="{% url 'abyssal_modules:roll_calculator' type_id=module_type.id %}">Roll Calculator</a>
</li>
<li class="nav-item">
<a class="nav-tab nav-link {% if active_page == 'hall_of_fame' %}active{% endif %}" href="{% url 'abyssal_modules:type_hall_of_fame' type_id=module_type.id %}">Hall of Fame</a>
</li>
</ul>
9 changes: 8 additions & 1 deletion backend/abyssal_modules/templatetags/module_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from abyssal_modules.utils import (
format_attribute_basic as fb,
render_attribute_value as rv,
correct_high_is_good as hg
correct_high_is_good as hg,
)


Expand All @@ -17,14 +17,21 @@ def format_attribute(mod, attr):
return fb(rv(val, attr), attr)


@register.filter
def format_attribute_simple(val, attr):
return fb(rv(val, attr), attr)


@register.filter
def format_attribute_basic(val, attr):
return fb(val, attr)


@register.filter
def rendered_high_is_good(at):
return hg(at.high_is_good, at.id)


@register.filter()
def delta(d, attr):
return d.get(attr, None)["delta"]
5 changes: 5 additions & 0 deletions backend/abyssal_modules/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
abyssal_modules.views.TypedModuleList.as_view(),
name="type_module_list",
),
path(
"type/<int:type_id>/hof/",
abyssal_modules.views.HallOfFameView.as_view(),
name="type_hall_of_fame",
),
path(
"type/<int:type_id>/assets/",
abyssal_modules.views.TypeAssetModuleList.as_view(),
Expand Down
38 changes: 37 additions & 1 deletion backend/abyssal_modules/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from wand.compat import nested

from abyssal_modules.models.modules import Module, ModuleType, StaticModule
from abyssal_modules.models.attributes import TypeAttribute
from abyssal_modules.models.attributes import TypeAttribute, ModuleAttributeView
from abyssal_modules.models.characters import EveCharacter
from abyssal_modules.models.mutators import Mutator, MutatorAttribute
from eve_esi import ESI
Expand Down Expand Up @@ -138,6 +138,42 @@ def get(self, request, type_id):
)


class HallOfFameView(View):
def get(self, request, type_id):
try:
module_type = ModuleType.objects.get(id=type_id)
except ModuleType.DoesNotExist:
raise Http404("Module type does not exist.")

mutators = Mutator.objects.filter(result=module_type).order_by(
"item_type__name"
)
modules = StaticModule.objects.filter(type=module_type)
attributes = TypeAttribute.objects.filter(
mutatorattribute__mutator__result=module_type
).distinct("attribute")

hof_dict = {}

for k in attributes:
qs = ModuleAttributeView.objects.filter(
module__type=module_type, attribute=k.attribute
)

d1 = qs.order_by("value")[:10]
d2 = qs.order_by("-value")[:10]

hig = correct_high_is_good(k.high_is_good, k.id)

hof_dict[k.id] = (k.attribute, d2 if hig else d1, d1 if hig else d2)

return render(
request,
"abyssal_modules/hall_of_fame.html",
{"module_type": module_type, "hof": hof_dict},
)


class ModuleView(DetailView):
model = Module
template_name = "abyssal_modules/module.html"
Expand Down

0 comments on commit e7e4777

Please sign in to comment.