Skip to content

Commit

Permalink
Merge pull request #2050 from jelanmathewjames/dev
Browse files Browse the repository at this point in the history
refactor: launchpad leaderboard
  • Loading branch information
jelanmathewjames authored Jun 11, 2024
2 parents 8c19cb2 + edc5587 commit bbbc6e5
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions api/launchpad/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from db.user import User
from db.organization import UserOrganizationLink
from db.task import KarmaActivityLog
import json

class LaunchpadLeaderBoardSerializer(serializers.ModelSerializer):
rank = serializers.SerializerMethodField()
Expand Down Expand Up @@ -50,12 +51,14 @@ def get_rank(self, obj):
).annotate(
karma=Subquery(total_karma_subquery, output_field=IntegerField()),
time_=Max("karma_activity_log_user__created_at"),
).order_by("-karma", "time_").annotate(
rank=Window(
expression=Rank(),
order_by=[F("karma").desc(), F("time_").asc()]
)
)

return users.get(id=obj.id).rank
).order_by("-karma", "time_")

# high complexity
rank = 0
for data in users:
rank += 1
if data.id == obj.id:
break

return rank

0 comments on commit bbbc6e5

Please sign in to comment.