Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions games/achievements.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime
import zoneinfo
from collections import Counter
from enum import StrEnum

from django.db.models import Q
Expand Down Expand Up @@ -188,6 +189,36 @@ def get_level(user):
return AchievementLevel.NO_LEVEL


class TheMoreTheMerrierAchievement(Achievement):
name = "The More The Merrier"
description = "Play atleast 5/10/15/20 games with equally as many unique players"
icon = "merrier.svg"

def get_level(user):
played_with_count = Counter()
for game in user.games.filter():
for player in game.players.all():
if player != user:
played_with_count[player.username] += 1

top20 = sorted(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use played_with_count.most_common()

({"x": k, "y": v} for k, v in played_with_count.items()),
key=lambda x: -x["y"],
)[:30]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 30?

if len(top20) < 20:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic is wrong. If a player has only ever played with the same 5 players, they should be able to get the base level.

return AchievementLevel.NO_LEVEL
if top20[19].get("y") >= 20:
return AchievementLevel.GOLD
elif top20[14].get("y") >= 15:
return AchievementLevel.SILVER
elif top20[9].get("y") >= 10:
return AchievementLevel.BRONZE
elif top20[4].get("y") >= 5:
return AchievementLevel.BASE
else:
return AchievementLevel.NO_LEVEL


class PilfingerAchievement(Achievement):
name = "Pilfinger"
description = "Stille stille stille, Pille pille pille"
Expand Down
13 changes: 13 additions & 0 deletions web/static/achievements/merrier.svg
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think something is wrong with the icon

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading