Skip to content

Commit

Permalink
Merge pull request #2184 from gtech-mulearn/dev-server
Browse files Browse the repository at this point in the history
Dev server
  • Loading branch information
jelanmathewjames authored Jul 29, 2024
2 parents f8904c4 + c015241 commit 6850275
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
49 changes: 47 additions & 2 deletions api/launchpad/launchpad_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from rest_framework.views import APIView

from .serializers import LaunchpadLeaderBoardSerializer, LaunchpadParticipantsSerializer, LaunchpadUserListSerializer,\
CollegeDataSerializer, LaunchpadUserSerializer, UserProfileUpdateSerializer, LaunchpadUpdateUserSerializer,LaunchPadRankSerializer
CollegeDataSerializer, LaunchpadUserSerializer, UserProfileUpdateSerializer, LaunchpadUpdateUserSerializer,LaunchPadRankSerializer,\
TaskCompletedLeaderBoardSerializer
from api.dashboard.profile.profile_serializer import UserProfileSerializer , LinkSocials ,UserLevelSerializer ,UserLogSerializer

from utils.response import CustomResponse
Expand All @@ -14,7 +15,7 @@
from utils.permission import JWTUtils
from db.user import User, UserRoleLink , Role , Socials
from db.organization import UserOrganizationLink, Organization
from db.task import KarmaActivityLog , Level
from db.task import KarmaActivityLog, Level, TaskList, Wallet
from db.launchpad import LaunchPadUsers, LaunchPadUserCollegeLink , LaunchPad


Expand Down Expand Up @@ -76,6 +77,50 @@ def get(self, request):
data=serializer.data, pagination=paginated_queryset.get("pagination")
)

class TaskCompletedLeaderboard(APIView):
def get(self, request):

launchpad_tasks = TaskList.objects.filter(event='launchpad').values('id')

completed_tasks_counts = KarmaActivityLog.objects.filter(
task__event='launchpad',
appraiser_approved=True,
).values('user').annotate(
completed_tasks=Count('task', distinct=True)
).filter(completed_tasks=launchpad_tasks.count())

completed_users = completed_tasks_counts.values('user')

wallet_subquery = Wallet.objects.filter(
user=OuterRef('id')
).values('karma')[:1]

users = User.objects.filter(
karma_activity_log_user__task__event="launchpad",
karma_activity_log_user__appraiser_approved=True,
id__in=completed_users
).annotate(
karma=Subquery(wallet_subquery,output_field=IntegerField()),
time_=Max("karma_activity_log_user__created_at"),
).order_by("-karma", "time_")

rank_list = list(users)
for index, user in enumerate(rank_list):
user.rank = index + 1

paginated_queryset = CommonUtils.get_paginated_queryset(
users,
request,
["full_name", "karma", "org", "district_name", "state"]
)

serializer = TaskCompletedLeaderBoardSerializer(
paginated_queryset.get("queryset"),
many=True
)
return CustomResponse().paginated_response(
data=serializer.data, pagination=paginated_queryset.get("pagination")
)

class ListParticipantsAPI(APIView):
def get(self, request):
Expand Down
8 changes: 8 additions & 0 deletions api/launchpad/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ def get_rank(self, obj):

return rank

class TaskCompletedLeaderBoardSerializer(serializers.ModelSerializer):
rank = serializers.IntegerField()
karma = serializers.IntegerField()

class Meta:
model = User
fields = ("muid", "rank", "full_name", "karma")


class LaunchpadParticipantsSerializer(serializers.ModelSerializer):
org = serializers.CharField(allow_null=True, allow_blank=True)
Expand Down
1 change: 1 addition & 0 deletions api/launchpad/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

urlpatterns = [
path('leaderboard/', launchpad_views.Leaderboard.as_view()),
path('task-completed-leaderboard/', launchpad_views.TaskCompletedLeaderboard.as_view()),
path('list-participants/', launchpad_views.ListParticipantsAPI.as_view()),
path('launchpad-details/', launchpad_views.LaunchpadDetailsCount.as_view()),
path('college-data/', launchpad_views.CollegeData.as_view()),
Expand Down

0 comments on commit 6850275

Please sign in to comment.