Skip to content

Commit

Permalink
Merge pull request #1751 from gtech-mulearn/dev-server
Browse files Browse the repository at this point in the history
lc
  • Loading branch information
adnankattekaden authored Dec 5, 2023
2 parents c12a068 + 08b4e42 commit 03cc012
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 8 deletions.
36 changes: 33 additions & 3 deletions api/common/common_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,21 @@ def get(self, request):

class CollegeWiseLcReportCSV(APIView):
def get(self, request):
learning_circle_count_subquery = (
LearningCircle.objects.filter(org__org_type=OrganizationType.COLLEGE.value)
.values(org_title=F("org__title"))
.annotate(learning_circle_count=Count("id"))
.filter(org_title=OuterRef("org_title"))
.values("learning_circle_count")
[:1]
)

learning_circles_info = (
LearningCircle.objects.filter(org__org_type=OrganizationType.COLLEGE.value)
.values(org_title=F("org__title"))
.annotate(
learning_circle_count=Count("id"), user_count=Count("user_circle_link_circle")
learning_circle_count=Subquery(learning_circle_count_subquery),
user_count=Count("user_circle_link_circle__user"),
)
.order_by("org_title")
)
Expand All @@ -241,20 +251,40 @@ class CollegeWiseLcReport(APIView):
def get(self, request):
date = request.query_params.get('date')
if date:
learning_circle_count_subquery = (
LearningCircle.objects.filter(org__org_type=OrganizationType.COLLEGE.value, created_at__date=date)
.values(org_title=F("org__title"))
.annotate(learning_circle_count=Count("id"))
.filter(org_title=OuterRef("org_title"))
.values("learning_circle_count")
[:1]
)

learning_circles_info = (
LearningCircle.objects.filter(org__org_type=OrganizationType.COLLEGE.value, created_at__date=date)
.values(org_title=F("org__title"))
.annotate(
learning_circle_count=Count("id"), user_count=Count("user_circle_link_user")
learning_circle_count=Subquery(learning_circle_count_subquery),
user_count=Count("user_circle_link_circle__user")
)
.order_by("org_title")
)
else:
learning_circle_count_subquery = (
LearningCircle.objects.filter(org__org_type=OrganizationType.COLLEGE.value)
.values(org_title=F("org__title"))
.annotate(learning_circle_count=Count("id"))
.filter(org_title=OuterRef("org_title"))
.values("learning_circle_count")
[:1]
)

learning_circles_info = (
LearningCircle.objects.filter(org__org_type=OrganizationType.COLLEGE.value)
.values(org_title=F("org__title"))
.annotate(
learning_circle_count=Count("id"), user_count=Count("user_circle_link_user")
learning_circle_count=Subquery(learning_circle_count_subquery),
user_count=Count("user_circle_link_circle__user"),
)
.order_by("org_title")
)
Expand Down
34 changes: 31 additions & 3 deletions api/dashboard/discord_moderator/discord_mod_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from db.task import KarmaActivityLog
from django.utils import timezone
from utils.utils import DateTimeUtils
from django.db.models import Count, Q


class TaskList(APIView):
Expand All @@ -27,10 +28,37 @@ def get(self, request):
tasks = KarmaActivityLog.objects.filter(created_at = date)
peerpending = tasks.filter(peer_approved = False).count()
appraiserpending = tasks.filter(appraiser_approved = False).count()
data = {'peer-pending':peerpending,'appraiser-pending':appraiserpending}
data = {'peer_pending':peerpending,'appraise_pending':appraiserpending}
return CustomResponse(response = data).get_success_response()

peerpending = KarmaActivityLog.objects.filter(peer_approved = False).count()
appraiserpending = KarmaActivityLog.objects.filter(appraiser_approved = False).count()
data = {'peer-pending':peerpending,'appraiser-pending':appraiserpending}
return CustomResponse(response = data).get_success_response()
data = {'peer_pending':peerpending,'appraise_pending':appraiserpending}
return CustomResponse(response = data).get_success_response()

class LeaderBoard(APIView):
authentication_classes = [CustomizePermission]

def get(self, request):
choice = request.query_params.get("option")
if choice == "peer":
data = {}
logs_with_peer_approval = KarmaActivityLog.objects.filter(Q(peer_approved_by__isnull=False) & ~Q(peer_approved_by = ''))
for obj in logs_with_peer_approval:
if data.get(obj.peer_approved_by.fullname) == None:
data[obj.peer_approved_by.fullname] = {"count":0,"muid":obj.peer_approved_by.muid }
data[obj.peer_approved_by.fullname]['count']+=1
return CustomResponse(response=data).get_success_response()

elif choice == "appraiser":
data = {}
logs_with_appraiser_approval = KarmaActivityLog.objects.filter(Q(appraiser_approved_by__isnull = False) & ~Q(appraiser_approved_by = ''))
for obj in logs_with_appraiser_approval:
if data.get(obj.appraiser_approved_by.fullname) == None:
data[obj.appraiser_approved_by.fullname] = {"count":0,"muid":obj.peer_approved_by.muid}
data[obj.appraiser_approved_by.fullname]['count']+=1
return CustomResponse(response=data).get_success_response()

else:
return CustomResponse(response="Bad Request").get_success_response()

3 changes: 1 addition & 2 deletions api/dashboard/discord_moderator/serializer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from rest_framework import serializers
from db.task import KarmaActivityLog

from db.user import User

class KarmaActivityLogSerializer(serializers.ModelSerializer):
fullname = serializers.CharField(source = 'user.fullname')
Expand All @@ -22,4 +22,3 @@ def get_status(self,obj):
return "Pending"



1 change: 1 addition & 0 deletions api/dashboard/discord_moderator/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
urlpatterns = [
path('tasklist/', discord_mod_views.TaskList.as_view()),
path('pendingcounts/', discord_mod_views.PendingTasks.as_view()),
path('leaderboard/', discord_mod_views.LeaderBoard.as_view()),

]

0 comments on commit 03cc012

Please sign in to comment.