From e7e4777258b40fbda5062420bea8c2cc132adcf3 Mon Sep 17 00:00:00 2001 From: Stephen Nicholas Swatman Date: Wed, 7 Feb 2024 16:15:25 +0100 Subject: [PATCH] Add hall of fame --- .../abyssal_modules/hall_of_fame.html | 80 +++++++++++++++++++ .../abyssal_modules/module_tabs.html | 3 + .../templatetags/module_stats.py | 9 ++- backend/abyssal_modules/urls.py | 5 ++ backend/abyssal_modules/views.py | 38 ++++++++- 5 files changed, 133 insertions(+), 2 deletions(-) create mode 100644 backend/abyssal_modules/templates/abyssal_modules/hall_of_fame.html diff --git a/backend/abyssal_modules/templates/abyssal_modules/hall_of_fame.html b/backend/abyssal_modules/templates/abyssal_modules/hall_of_fame.html new file mode 100644 index 0000000..e41a3bb --- /dev/null +++ b/backend/abyssal_modules/templates/abyssal_modules/hall_of_fame.html @@ -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 %} +
+
+
+

+ {{ module_type.name }} +

+
+
+
+{% endblock %} + +{% block content_tabs %} +
+{% include "abyssal_modules/module_tabs.html" with active_page="hall_of_fame" %} +
+{% endblock %} + +{% block content %} +
+ {% for k, v in hof.items %} +

{{ v.0.name }}

+ +
+
+

Best Modules

+ + + + + + + + + + + {% for c in v.1 %} + + + + + + {% endfor %} + +
#Module {{ v.0.name }}
{{ forloop.counter }}Module {{ c.module_id }}{{ c.value|format_attribute_simple:k }} {{ v.0.unit_str }}
+
+
+

Worst Modules

+ + + + + + + + + + + {% for c in v.2 %} + + + + + + {% endfor %} + +
#Module {{ v.0.name }}
{{ forloop.counter }}Module {{ c.module_id }}{{ c.value|format_attribute_simple:k }} {{ v.0.unit_str }}
+
+
+ {% endfor %} +
+{% endblock %} diff --git a/backend/abyssal_modules/templates/abyssal_modules/module_tabs.html b/backend/abyssal_modules/templates/abyssal_modules/module_tabs.html index 28af626..fc7a827 100644 --- a/backend/abyssal_modules/templates/abyssal_modules/module_tabs.html +++ b/backend/abyssal_modules/templates/abyssal_modules/module_tabs.html @@ -11,4 +11,7 @@ + diff --git a/backend/abyssal_modules/templatetags/module_stats.py b/backend/abyssal_modules/templatetags/module_stats.py index 5703b84..afc7b80 100644 --- a/backend/abyssal_modules/templatetags/module_stats.py +++ b/backend/abyssal_modules/templatetags/module_stats.py @@ -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, ) @@ -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"] diff --git a/backend/abyssal_modules/urls.py b/backend/abyssal_modules/urls.py index e4e9a5b..08f0482 100644 --- a/backend/abyssal_modules/urls.py +++ b/backend/abyssal_modules/urls.py @@ -28,6 +28,11 @@ abyssal_modules.views.TypedModuleList.as_view(), name="type_module_list", ), + path( + "type//hof/", + abyssal_modules.views.HallOfFameView.as_view(), + name="type_hall_of_fame", + ), path( "type//assets/", abyssal_modules.views.TypeAssetModuleList.as_view(), diff --git a/backend/abyssal_modules/views.py b/backend/abyssal_modules/views.py index 085f21d..7a243cf 100644 --- a/backend/abyssal_modules/views.py +++ b/backend/abyssal_modules/views.py @@ -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 @@ -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"