Skip to content

Commit

Permalink
Merge pull request #1517 from gtech-mulearn/dev
Browse files Browse the repository at this point in the history
fix lc report
  • Loading branch information
adnankattekaden authored Nov 4, 2023
2 parents b43644d + 2ea8520 commit daa3500
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 32 deletions.
19 changes: 11 additions & 8 deletions api/common/common_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.db.models import Sum, F, Case, When, Value, CharField, Count, Q
from django.db.models.functions import Coalesce
from rest_framework.views import APIView

from django.db import models
from db.learning_circle import LearningCircle
from db.learning_circle import UserCircleLink
from db.organization import Organization
Expand All @@ -14,7 +14,7 @@
from utils.types import IntegrationType, OrganizationType, RoleType
from utils.utils import CommonUtils
from .serializer import StudentInfoSerializer, CollegeInfoSerializer

from django.db.models import Count, Subquery, OuterRef

class LcDashboardAPI(APIView):
def get(self, request):
Expand All @@ -27,20 +27,23 @@ def get(self, request):
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("learningcircle"),
total_users=Count("learningcircle__usercirclelink__user", distinct=True),
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("learningcircle", distinct=True),
total_users=Count(
"learningcircle__usercirclelink__user", distinct=True
),
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")
Expand Down
2 changes: 1 addition & 1 deletion api/common/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
path('college-wise-lc-report/csv/', common_views.CollegeWiseLcReportCSV.as_view()),
path('lc-report/csv/', common_views.LcReportDownloadAPI.as_view()),
path('global-count/', common_views.GlobalCountAPI.as_view()),
path('gta-sandshore/',common_views.GTASANDSHOREAPI.as_view())
path('gta-sandshore/', common_views.GTASANDSHOREAPI.as_view())
]
54 changes: 31 additions & 23 deletions db/learning_circle.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,27 @@
from db.task import InterestGroup, Organization
from db.user import User


# fmt: off
# noinspection PyPep8

class LearningCircle(models.Model):
id = models.CharField(primary_key=True, max_length=36, default=uuid.uuid4())
name = models.CharField(max_length=255, unique=True)
circle_code= models.CharField(unique=True, max_length=36)
ig = models.ForeignKey(InterestGroup, on_delete=models.CASCADE)
org = models.ForeignKey(Organization, on_delete=models.CASCADE, blank=True, null=True)
name = models.CharField(max_length=255, unique=True)
circle_code = models.CharField(unique=True, max_length=36)
ig = models.ForeignKey(InterestGroup, on_delete=models.CASCADE, blank=True, null=True,
related_name="learning_circle_ig")
org = models.ForeignKey(Organization, on_delete=models.CASCADE, blank=True, null=True,
related_name="learning_circle_org")
meet_place = models.CharField(max_length=255, blank=True, null=True)
meet_time = models.CharField(max_length=10, blank=True, null=True)
day = models.CharField(max_length=20, blank=True, null=True)
note = models.CharField(max_length=500, blank=True, null=True)
updated_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column="updated_by", related_name="learning_circle_updated_by")
meet_time = models.CharField(max_length=10, blank=True, null=True)
day = models.CharField(max_length=20, blank=True, null=True)
note = models.CharField(max_length=500, blank=True, null=True)
updated_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column="updated_by",
related_name="learning_circle_updated_by")
updated_at = models.DateTimeField(auto_now=True)
created_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column="created_by", related_name="learning_circle_created_by")
created_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column="created_by",
related_name="learning_circle_created_by")
created_at = models.DateTimeField(auto_now=True)

class Meta:
Expand All @@ -29,14 +34,14 @@ class Meta:


class UserCircleLink(models.Model):
id = models.CharField(primary_key=True, max_length=36)
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='user_circle_link_user')
circle = models.ForeignKey(LearningCircle, on_delete=models.CASCADE, related_name='user_circle_link_circle')
lead = models.BooleanField(default=False)
is_invited = models.BooleanField(default=False)
accepted = models.BooleanField()
id = models.CharField(primary_key=True, max_length=36)
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='user_circle_link_user')
circle = models.ForeignKey(LearningCircle, on_delete=models.CASCADE, related_name='user_circle_link_circle')
lead = models.BooleanField(default=False)
is_invited = models.BooleanField(default=False)
accepted = models.BooleanField()
accepted_at = models.DateTimeField(blank=True, null=True)
created_at = models.DateTimeField(auto_now=True)
created_at = models.DateTimeField(auto_now=True)

class Meta:
managed = False
Expand All @@ -45,15 +50,18 @@ class Meta:

class CircleMeetingLog(models.Model):
id = models.CharField(primary_key=True, max_length=36, default=uuid.uuid4(), unique=True)
circle = models.ForeignKey(LearningCircle, on_delete=models.CASCADE, related_name='circle_meeting_log_learning_circle')
meet_time = models.DateTimeField()
circle = models.ForeignKey(LearningCircle, on_delete=models.CASCADE,
related_name='circle_meeting_log_learning_circle')
meet_time = models.DateTimeField()
meet_place = models.CharField(max_length=255, blank=True, null=True)
day = models.CharField(max_length=20)
attendees = models.CharField(max_length=216)
agenda = models.CharField(max_length=500)
created_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column='created_by', related_name='circle_meeting_log_created_by')
day = models.CharField(max_length=20)
attendees = models.CharField(max_length=216)
agenda = models.CharField(max_length=500)
created_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column='created_by',
related_name='circle_meeting_log_created_by')
created_at = models.DateTimeField(auto_now=True)
updated_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column='updated_by', related_name='circle_meeting_log_updated_by')
updated_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column='updated_by',
related_name='circle_meeting_log_updated_by')
updated_at = models.DateTimeField(auto_now=True)

class Meta:
Expand Down
1 change: 1 addition & 0 deletions utils/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class RoleType(Enum):
ENABLER = "Enabler"
IG_FACILITATOR = "IG Facilitator"
TECH_TEAM = 'Tech Team'
CAMPUS_ACTIVATION_TEAM = "Campus Activation Team"


class OrganizationType(Enum):
Expand Down

0 comments on commit daa3500

Please sign in to comment.