Skip to content

Commit

Permalink
Refactor Killstats System
Browse files Browse the repository at this point in the history
  • Loading branch information
Geuthur committed Aug 14, 2024
1 parent 58643ca commit 353018a
Show file tree
Hide file tree
Showing 6 changed files with 223 additions and 222 deletions.
21 changes: 8 additions & 13 deletions killstats/api/killboard/alliance/killboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@

from ninja import NinjaAPI

# Django
from django.utils.translation import gettext_lazy as _

# AA Killstats
from killstats.api import schema
from killstats.api.account_manager import AccountManager
Expand Down Expand Up @@ -43,30 +40,28 @@ def get_killstats(request, month, year, alliance_id: int):
alliances = [alliance_id]

killmail_year = (
Killmail.objects.select_related("victim", "victim_ship")
Killmail.objects.prefetch_related("victim", "victim_ship")
.filter(killmail_date__year=year)
.order_by("-killmail_date")
)

killmail_year = killmail_year.filter_alliances(alliances)
).filter_entities(alliances)

killmail_month = killmail_year.filter(
killmail_date__year=year,
killmail_date__month=month,
)

account = AccountManager(alliances=alliances)
mains, all_chars = account.get_mains_alts()

kills, totalvalue, losses, totalvalue_loss = killboard_process_kills(
killmail_month, mains, all_chars
killmail_month, alliances
)

date = KillboardDate(month, year)

stats = killboard_dashboard(killmail_year, date, mains, all_chars)
account = AccountManager(alliances=alliances)
mains, _ = account.get_mains_alts()

stats = killboard_dashboard(killmail_year, date, alliances)

shame, fame = killboard_hall(killmail_month, mains)
shame, fame = killboard_hall(killmail_month, alliances, mains)

output = []
output.append(
Expand Down
21 changes: 9 additions & 12 deletions killstats/api/killboard/corporation/killboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@

from ninja import NinjaAPI

# Django
from django.utils.translation import gettext_lazy as _

# AA Killstats
from killstats.api import schema
from killstats.api.account_manager import AccountManager
Expand Down Expand Up @@ -42,30 +39,30 @@ def get_killstats(request, month, year, corporation_id: int):
corporations = [corporation_id]

killmail_year = (
Killmail.objects.select_related("victim", "victim_ship")
Killmail.objects.prefetch_related("victim", "victim_ship")
.filter(killmail_date__year=year)
.order_by("-killmail_date")
)

killmail_year = killmail_year.filter_corporations(corporations)
killmail_filtered = killmail_year.filter_entities(corporations)

killmail_month = killmail_year.filter(
killmail_month = killmail_filtered.filter(
killmail_date__year=year,
killmail_date__month=month,
)

account = AccountManager(corporations=corporations)
mains, all_chars = account.get_mains_alts()

kills, totalvalue, losses, totalvalue_loss = killboard_process_kills(
killmail_month, mains, all_chars
killmail_month, corporations
)

date = KillboardDate(month, year)

stats = killboard_dashboard(killmail_year, date, mains, all_chars)
account = AccountManager(corporations=corporations)
mains, _ = account.get_mains_alts()

stats = killboard_dashboard(killmail_filtered, date, corporations)

shame, fame = killboard_hall(killmail_month, mains)
shame, fame = killboard_hall(killmail_month, corporations, mains)

output = []
output.append(
Expand Down
Loading

0 comments on commit 353018a

Please sign in to comment.