Skip to content

Commit

Permalink
Merge pull request #2032 from gtech-mulearn/jelanmathewjames-patch-1
Browse files Browse the repository at this point in the history
rank in launchpad leaderboard
  • Loading branch information
jelanmathewjames authored Jun 7, 2024
2 parents d0ebe80 + 19e9685 commit 3f1e323
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion api/launchpad/launchpad_views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.db.models import Sum, Max, Prefetch, F, OuterRef, Subquery, IntegerField
from django.db.models import Sum, Max, Prefetch, F, OuterRef, Subquery, Window, IntegerField
from django.db.models.functions import RowNumber
from django.db import connection
from rest_framework.views import APIView

Expand Down Expand Up @@ -47,6 +48,11 @@ def get(self, request):
district_name=F("user_organization_link_user__org__district__name"),
state=F("user_organization_link_user__org__district__zone__state__name"),
time_=Max("karma_activity_log_user__created_at"),
).annotate(
rank=Window(
expression=RowNumber(),
order_by=F('karma').desc(), F('time_').asc()
)
).order_by("-karma", "time_")

paginated_queryset = CommonUtils.get_paginated_queryset(
Expand Down

0 comments on commit 3f1e323

Please sign in to comment.