From a495247766922cc154b53307b6e565f29143d532 Mon Sep 17 00:00:00 2001 From: Kethankrk Date: Tue, 13 Aug 2024 18:01:24 +0530 Subject: [PATCH 1/2] Added total karma count and pow count --- api/common/common_consumer.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/api/common/common_consumer.py b/api/common/common_consumer.py index 9858089a..191ddaf0 100644 --- a/api/common/common_consumer.py +++ b/api/common/common_consumer.py @@ -2,7 +2,7 @@ from django.db.models.signals import post_save, post_delete from django.dispatch import receiver -from django.db.models import Count +from django.db.models import Count, Sum from django.db.models.functions import Coalesce from channels.generic.websocket import WebsocketConsumer @@ -12,7 +12,7 @@ from db.learning_circle import LearningCircle from db.learning_circle import UserCircleLink from db.organization import Organization -from db.task import InterestGroup +from db.task import InterestGroup, KarmaActivityLog from db.user import User, UserRoleLink from utils.types import IntegrationType, OrganizationType @@ -48,6 +48,10 @@ def interest_groups_count(self): def learning_circles_count(self): learning_circles_count = LearningCircle.objects.all().count() return learning_circles_count + + def karma_pow_count(self): + karma_pow_count = KarmaActivityLog.objects.aaggregate(karma_count=Sum('karma'), pow_count=Count('id')) + return karma_pow_count def get_data(self, sender): if sender == None: @@ -56,7 +60,8 @@ def get_data(self, sender): 'org_type_counts': self.org_type_counts(), 'enablers_mentors_count': self.enablers_mentors_count(), 'ig_count': self.interest_groups_count(), - 'learning_circle_count': self.learning_circles_count() + 'learning_circle_count': self.learning_circles_count(), + 'karma_pow_count': self.karma_pow_count() } elif sender == User: self.data['members'] = self.members_count() From 111c85fbee4b4909c04f67233d477c673001fe6f Mon Sep 17 00:00:00 2001 From: Kethankrk Date: Tue, 13 Aug 2024 18:50:22 +0530 Subject: [PATCH 2/2] Fixed karma pow total function error --- api/common/common_consumer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/common/common_consumer.py b/api/common/common_consumer.py index 191ddaf0..36516aa8 100644 --- a/api/common/common_consumer.py +++ b/api/common/common_consumer.py @@ -50,7 +50,7 @@ def learning_circles_count(self): return learning_circles_count def karma_pow_count(self): - karma_pow_count = KarmaActivityLog.objects.aaggregate(karma_count=Sum('karma'), pow_count=Count('id')) + karma_pow_count = KarmaActivityLog.objects.aggregate(karma_count=Coalesce(Sum('karma'), 0), pow_count=Count('id')) return karma_pow_count def get_data(self, sender):