From aeadf1d1ff68292758ae612195bea22332aa1a60 Mon Sep 17 00:00:00 2001 From: Adnan Kattekaden Date: Wed, 15 Nov 2023 17:22:16 +0530 Subject: [PATCH] lc dashboard fix --- api/common/common_views.py | 86 +++----------------------------------- 1 file changed, 6 insertions(+), 80 deletions(-) diff --git a/api/common/common_views.py b/api/common/common_views.py index 27aaeebe..e0fc4799 100644 --- a/api/common/common_views.py +++ b/api/common/common_views.py @@ -17,103 +17,29 @@ from .serializer import StudentInfoSerializer, CollegeInfoSerializer -# class LcDashboardAPI(APIView): -# def get(self, request): -# date = request.query_params.get("date") -# if date: -# learning_circle_count = LearningCircle.objects.filter(created_at__gt=date).count() -# total_no_enrollment = UserCircleLink.objects.filter(accepted=True, created_at__gt=date).count() -# user_circle_link_count = UserCircleLink.objects.filter(created_at__gt=date, circle=OuterRef('pk')).values( -# 'circle_id').annotate( -# total_users=Count('id')).values('total_users') -# -# query = InterestGroup.objects.annotate( -# total_circles=Count("learning_circle_ig", distinct=True), -# total_users=Subquery(user_circle_link_count, output_field=models.IntegerField()) -# ).values("name", "total_circles", "total_users") -# -# circle_count_by_ig = ( -# query.values("name") -# .order_by("name") -# .annotate( -# total_circles=Count("learning_circle_ig", distinct=True), -# total_users=Count("learning_circle_ig__user_circle_link_circle", distinct=True), -# ) -# ) -# unique_user_count = ( -# UserCircleLink.objects.filter(created_at__gt=date, accepted=True) -# .values("user") -# .distinct() -# .count() -# ) -# else: -# learning_circle_count = LearningCircle.objects.all().count() -# total_no_enrollment = UserCircleLink.objects.filter(accepted=True).count() -# -# user_circle_link_count = UserCircleLink.objects.filter(circle=OuterRef('pk')).values('circle_id').annotate( -# total_users=Count('id')).values('total_users') -# -# query = InterestGroup.objects.annotate( -# total_circles=Count("learning_circle_ig", distinct=True), -# total_users=Subquery(user_circle_link_count, output_field=models.IntegerField()) -# ).values("name", "total_circles", "total_users") -# -# circle_count_by_ig = ( -# query.values("name") -# .order_by("name") -# .annotate( -# total_circles=Count("learning_circle_ig", distinct=True), -# total_users=Count("learning_circle_ig__user_circle_link_circle", distinct=True), -# ) -# ) -# -# unique_user_count = ( -# UserCircleLink.objects.filter(accepted=True) -# .values("user") -# .distinct() -# .count() -# ) -# -# return CustomResponse( -# response={ -# "lc_count": learning_circle_count, -# "total_enrollment": total_no_enrollment, -# "circle_count_by_ig": circle_count_by_ig, -# "unique_users": unique_user_count, -# } -# ).get_success_response() -# class LcDashboardAPI(APIView): def get(self, request): date = request.query_params.get("date") if date: learning_circle_count = LearningCircle.objects.filter(created_at__gt=date).count() total_no_enrollment = UserCircleLink.objects.filter(accepted=True, created_at__gt=date).count() - - user_circle_link_count = UserCircleLink.objects.filter( - circle=OuterRef('pk'), - created_at__gt=date - ).values('circle_id').annotate( - total_users=Count('id') - ).values('total_users') + user_circle_link_count = UserCircleLink.objects.filter(created_at__gt=date, circle=OuterRef('pk')).values( + 'circle_id').annotate( + total_users=Count('id')).values('total_users') query = InterestGroup.objects.annotate( total_circles=Count("learning_circle_ig", distinct=True), - total_users=Coalesce(Subquery(user_circle_link_count, output_field=models.IntegerField()), 0), - ).filter( - learning_circle_ig__created_at__gt=date + total_users=Subquery(user_circle_link_count, output_field=models.IntegerField()) ).values("name", "total_circles", "total_users") circle_count_by_ig = ( - query.filter(learning_circle_ig__created_at__gt=date) - .values("name") + query.values("name") .order_by("name") .annotate( total_circles=Count("learning_circle_ig", distinct=True), - total_users=Coalesce(Count("learning_circle_ig__user_circle_link_circle", distinct=True), 0), + total_users=Count("learning_circle_ig__user_circle_link_circle", distinct=True), ) ) - unique_user_count = ( UserCircleLink.objects.filter(created_at__gt=date, accepted=True) .values("user")