Skip to content

Commit

Permalink
Merge pull request #1357 from gtech-mulearn/dev-server
Browse files Browse the repository at this point in the history
kkem college wise report
  • Loading branch information
adnankattekaden authored Oct 17, 2023
2 parents cc7e817 + 04da809 commit e58f252
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions api/common/common_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from utils.types import IntegrationType, OrganizationType
from utils.utils import CommonUtils
from .serializer import StudentInfoSerializer

from collections import defaultdict

class LcDashboardAPI(APIView):

Expand All @@ -21,7 +21,9 @@ def get(self, request):
learning_circle_count = LearningCircle.objects.filter(created_at__gt=date).count()
total_no_enrollment = UserCircleLink.objects.filter(accepted=True, created_at__gt=date).count()
circle_count_by_ig = LearningCircle.objects.filter(created_at__gt=date).values(
ig_name=F('ig__name')).annotate(total_circles=Count('id'))
ig_name=F('ig__name')).annotate(total_circles=Count('id'),
total_users=Count('ig__learningcircle__usercirclelink__user',
distinct=True))
unique_user_count = UserCircleLink.objects.filter(accepted=True, created_at__gt=date).values(
'user').distinct().count()
else:
Expand Down Expand Up @@ -125,11 +127,24 @@ def get(self, request):
class CollegeWiseLcReport(APIView):

def get(self, request):
learning_circles_info = LearningCircle.objects.filter(org__org_type=OrganizationType.COLLEGE.value).annotate(
user_count=Count('usercirclelink'),
org_name=F('org__title')
).values('name', 'user_count', 'org_name')
return CustomResponse(response=learning_circles_info).get_success_response()
learning_circles_info = LearningCircle.objects.filter(org__org_type=OrganizationType.COLLEGE.value) \
.values('org__title', 'name') \
.annotate(user_count=Count('usercirclelink')) \
.order_by('org__title')

org_learning_circles = defaultdict(list)

for info in learning_circles_info:
org_name = info['org__title']
org_learning_circles[org_name].append({
'name': info['name'],
'user_count': info['user_count']
})

result_list = [{"org_name": org_name, "learning_circles": circles} for org_name, circles in
org_learning_circles.items()]

return CustomResponse(response=result_list).get_success_response()


class GlobalCountAPI(APIView):
Expand Down

0 comments on commit e58f252

Please sign in to comment.