diff --git a/django/stats/migrations/0021_add_john_wick_award.py b/django/stats/migrations/0021_add_john_wick_award.py new file mode 100644 index 0000000..196ca8f --- /dev/null +++ b/django/stats/migrations/0021_add_john_wick_award.py @@ -0,0 +1,25 @@ +from django.db import migrations + + +def forwards(apps, schema_editor): + MatchBadgeType = apps.get_model('stats', 'MatchBadgeType') + MatchBadgeType.objects.using(schema_editor.connection.alias).bulk_create( + [ + MatchBadgeType(pk='john-wick-award', name='John Wick Award'), + ] + ) + + +def backwards(apps, schema_editor): + MatchBadgeType = apps.get_model('stats', 'MatchBadgeType') + MatchBadgeType.objects.using(schema_editor.connection.alias).filter(pk='john-wick-award').delete() + + +class Migration(migrations.Migration): + dependencies = [ + ('stats', '0020_rename_completed_timestamp_updatetask_completion_timestamp'), + ] + + operations = [ + migrations.RunPython(forwards, backwards), + ] diff --git a/django/stats/models.py b/django/stats/models.py index 2a8c624..f41ce5e 100644 --- a/django/stats/models.py +++ b/django/stats/models.py @@ -1050,6 +1050,7 @@ def award(participation, **kwargs): MatchBadge.award_margin_badge( participation, 'peach', order = 'adr', margin = 0.67, emoji = '🍑', max_adr = 50, max_kd = 0.5, **kwargs, ) + MatchBadge.award_john_wick_award(participation, **kwargs) @staticmethod def award_with_history(participation, old_participations): @@ -1142,6 +1143,22 @@ def award_margin_badge(participation, badge_type_slug, order, margin, emoji, mut for m in participation.player.squad_memberships.all(): m.squad.notify_on_discord(text) + @staticmethod + def award_john_wick_award(participation, mute_discord = False): + badge_type = MatchBadgeType.objects.get(slug = 'john-wick-award') + if MatchBadge.objects.filter(badge_type=badge_type, participation=participation).exists(): + return + if participation.kd > 2 * participation.adr / 100: + log.info(f'{participation.player.name} received the {badge_type.name}') + MatchBadge.objects.create(badge_type = badge_type, participation = participation) + text = ( + f'☠️ <{participation.player.steamid}> bagged the **{badge_type.name}** ' + f'on *{participation.pmatch.map_name}*!' + ) + if not mute_discord: + for m in participation.player.squad_memberships.all(): + m.squad.notify_on_discord(text) + class Meta: verbose_name = 'Match-based badge' verbose_name_plural = 'Match-based badges' diff --git a/django/stats/templates/stats/squads.html b/django/stats/templates/stats/squads.html index 0203927..90c3243 100644 --- a/django/stats/templates/stats/squads.html +++ b/django/stats/templates/stats/squads.html @@ -83,6 +83,12 @@
Be the red lantern of your team with K/D ≤0.5, ADR ≤50, and a substantial deficit in ADR.
+
+
+
John Wick Award
+
Gain a surprisingly high K/D ratio, compared to the ADR.
+
+ diff --git a/django/stats/tests.py b/django/stats/tests.py index 8bc2ae6..0654023 100644 --- a/django/stats/tests.py +++ b/django/stats/tests.py @@ -426,6 +426,30 @@ def test_peach_price__kd_and_adr_too_high(self): models.MatchBadge.award(self.mp5) self.assertEqual(len(models.MatchBadge.objects.filter(badge_type = 'peach', participation = self.mp5)), 0) + def test_john_wick_award(self): + """ + Test the 🏅 John Wick Award when the constraint ✅ "K/D > 2 * ADR / 100" is met. + """ + mp1 = self.pmatch.get_participation('76561197967680028') + mp1.kills = 10 + mp1.deaths = 1 + mp1.adr = 400 + mp1.save() + models.MatchBadge.award(mp1) + self.assertEqual(len(models.MatchBadge.objects.filter(badge_type = 'john-wick-award', participation = mp1)), 1) + + def test_john_wick_award_not_met(self): + """ + Test the 🏅 John Wick Award when the constraint ❌ "K/D > 2 * ADR / 100" is not met. + """ + mp1 = self.pmatch.get_participation('76561197967680028') + mp1.kills = 10 + mp1.deaths = 1 + mp1.adr = 600 + mp1.save() + models.MatchBadge.award(mp1) + self.assertEqual(len(models.MatchBadge.objects.filter(badge_type = 'john-wick-award', participation = mp1)), 0) + class MatchBadge__award_with_history(TestCase): diff --git a/django/stats/views.py b/django/stats/views.py index 3fed59d..3171efa 100644 --- a/django/stats/views.py +++ b/django/stats/views.py @@ -60,6 +60,7 @@ 'rising-star', 'ace', 'quad-kill', + 'john-wick-award', ]