Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added achievement for playing multiple games with different players #81

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 as many different 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(
({"x": k, "y": v} for k, v in played_with_count.items()),
key=lambda x: -x["y"],
)[:30]
if len(top20) < 20:
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
Loading