Skip to content

Commit

Permalink
Merge pull request #1848 from gtech-mulearn/dev
Browse files Browse the repository at this point in the history
percentail
  • Loading branch information
adnankattekaden authored Dec 22, 2023
2 parents 785cf8f + db6319e commit 9c7652d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
12 changes: 5 additions & 7 deletions api/dashboard/profile/profile_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,11 @@ class Meta:
)

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

def get_roles(self, obj):
return list({link.role.title for link in obj.user_role_link_user.filter(verified=True)})
Expand Down
21 changes: 19 additions & 2 deletions api/register/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,13 @@ class UserSerializer(serializers.ModelSerializer):
role = serializers.PrimaryKeyRelatedField(
queryset=Role.objects.all(), required=False, write_only=True
)
area_of_interest = serializers.PrimaryKeyRelatedField(
queryset=InterestGroup.objects.all(), many=True, required=False
)

def create(self, validated_data):
role = validated_data.pop("role", None)

area_of_interest = validated_data.pop("area_of_interest", None)

validated_data["muid"] = register_helper.generate_muid(
validated_data["full_name"]
Expand Down Expand Up @@ -294,6 +297,19 @@ def create(self, validated_data):
**additional_values,
)

if area_of_interest:
UserIgLink.objects.bulk_create(
{
UserIgLink(
user=user,
ig=ig,
created_by=user,
created_at=DateTimeUtils.get_current_utc_time(),
)
for ig in area_of_interest
}
)

return user

class Meta:
Expand All @@ -306,7 +322,8 @@ class Meta:
"dob",
"gender",
"role",
"district"
"district",
"area_of_interest",
]

class RegisterSerializer(serializers.Serializer):
Expand Down
2 changes: 1 addition & 1 deletion utils/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class RoleType(Enum):
SUSPEND = "Suspended"
STUDENT = "Student"
ENABLER = "Enabler"
IG_FACILITATOR = "IG Facilitator"
TECH_TEAM = 'Tech Team'
IG_LEAD = 'IG Lead'
CAMPUS_ACTIVATION_TEAM = "Campus Activation Team"
LEAD_ENABLER = "Lead Enabler"

Expand Down

0 comments on commit 9c7652d

Please sign in to comment.