Skip to content

Commit

Permalink
Merge pull request #1687 from gtech-mulearn/dev
Browse files Browse the repository at this point in the history
[feat] percentaile
  • Loading branch information
adnankattekaden authored Dec 1, 2023
2 parents d6d61e4 + 26cd960 commit 67b9529
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions api/dashboard/profile/profile_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class UserProfileSerializer(serializers.ModelSerializer):
interest_groups = serializers.SerializerMethodField()
org_district_id = serializers.SerializerMethodField()
profile_pic = serializers.SerializerMethodField()
percentile = serializers.SerializerMethodField()

class Meta:
model = User
Expand All @@ -78,8 +79,19 @@ class Meta:
"profile_pic",
"interest_groups",
"is_public",
"percentile",
)

def get_percentile(self, obj):
try:
user_count = Wallet.objects.filter(karma__lt=obj.wallet_user.karma).count()
usr_count = User.objects.all().count()
if usr_count == 0:
return 0
return (user_count * 100) / usr_count
except Exception as e:
return 0

def get_profile_pic(self, obj):
fs = FileSystemStorage()
path = f'user/profile/{obj.id}.png'
Expand Down

0 comments on commit 67b9529

Please sign in to comment.