Skip to content

Commit

Permalink
Merge pull request #2017 from gtech-mulearn/dev
Browse files Browse the repository at this point in the history
Updated launchpad leaderboard
  • Loading branch information
Kochouseph26John authored Jun 6, 2024
2 parents 6da4934 + 643c356 commit 6b08add
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions api/launchpad/launchpad_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from db.organization import UserOrganizationLink
from db.task import KarmaActivityLog


class Leaderboard(APIView):
def get(self, request):
total_karma_subquery = KarmaActivityLog.objects.filter(
Expand All @@ -25,27 +26,33 @@ def get(self, request):
task__hashtag='#lp24-introduction',
).values('user')

allowed_org_types = UserOrganizationLink.objects.filter(
org__org_type__in=["College", "School", "Company"])

allowed_org_types = ["College", "School", "Company"]

users = User.objects.filter(
karma_activity_log_user__task__event="launchpad",
karma_activity_log_user__appraiser_approved=True,
id__in=intro_task_completed_users,
user_organization_link_org__in=allowed_org_types,
).annotate(
karma=Subquery(total_karma_subquery, output_field=IntegerField()),
org=F("user_organization_link_user__org__title"),
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"),
).order_by("-karma")

karma_activity_log_user__task__event="launchpad",
karma_activity_log_user__appraiser_approved=True,
id__in=intro_task_completed_users
).prefetch_related(
Prefetch(
"user_organization_link_user",
queryset=UserOrganizationLink.objects.filter(org__org_type__in=allowed_org_types),
)
).filter(
user_organization_link_user__id__in=UserOrganizationLink.objects.filter(
org__org_type__in=allowed_org_types
).values("id")
).annotate(
karma=Subquery(total_karma_subquery, output_field=IntegerField()),
org=F("user_organization_link_user__org__title"),
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"),
).order_by("-karma")

paginated_queryset = CommonUtils.get_paginated_queryset(
users,
request,
["full_name","karma", "org", "district_name", "state"],
["full_name", "karma", "org", "district_name", "state"],
sort_fields={
"karma": "karma",
"time_": "time_",
Expand All @@ -57,4 +64,4 @@ def get(self, request):
)
return CustomResponse().paginated_response(
data=serializer.data, pagination=paginated_queryset.get("pagination")
)
)

0 comments on commit 6b08add

Please sign in to comment.