Skip to content

Commit

Permalink
Merge pull request #1992 from gtech-mulearn/dev
Browse files Browse the repository at this point in the history
update annotate total karma in launchpad leaderboard
  • Loading branch information
jelanmathewjames authored Jun 1, 2024
2 parents 5521f6f + c4d549b commit c6ebdeb
Showing 1 changed file with 8 additions and 25 deletions.
33 changes: 8 additions & 25 deletions api/launchpad/launchpad_views.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,29 @@
from django.db.models import (
Sum,
Max,
Prefetch,
When,
Case,
IntegerField,
CharField,
F,
OuterRef,
Subquery,
)
from django.db.models.functions import Coalesce
from django.db.models import Q, Sum, Max

from rest_framework.views import APIView

from .serializers import LaunchpadLeaderBoardSerializer
from utils.response import CustomResponse
from utils.utils import CommonUtils
from db.user import User
from db.organization import Organization, District, State
from db.task import KarmaActivityLog


class Leaderboard(APIView):
def get(self, request):
karma_subquery = (
KarmaActivityLog.objects.filter(
user=OuterRef("id"),
task__event="launchpad",
appraiser_approved=True,
)
.annotate(total_karma=Sum("karma"))
.values("total_karma")
)
users = (
User.objects.filter(
karma_activity_log_user__task__event="launchpad",
karma_activity_log_user__appraiser_approved=True,
karma_activity_log_user__task__hashtag="#lp24-introduction",
)
.annotate(
karma=Subquery(karma_subquery, output_field=IntegerField()),
karma=Sum(
"karma_activity_log_user__karma",
filter=Q(
karma_activity_log_user__task__event="launchpad",
karma_activity_log_user__appraiser_approved=True,
),
),
time_=Max("karma_activity_log_user__created_at"),
)
.order_by("-karma", "time_")
Expand Down

0 comments on commit c6ebdeb

Please sign in to comment.