Skip to content

Commit

Permalink
adde &limit to limit number of user in top users
Browse files Browse the repository at this point in the history
  • Loading branch information
knoriy committed Nov 19, 2023
1 parent f571a1c commit 5299792
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions django_dataset_collection_tool/audio_recorder/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,11 @@ def get(self, request, *args, **kwargs):
paid_param = request.GET.get('paid', None)
is_paid = False

try:
limit_param = int(request.GET.get('limit', 10))
except ValueError:
raise PermissionDenied(detail="Invalid 'limit' parameter value.")

base_query = Utterances.objects.filter(status='Awaiting Review')
if paid_param:
is_paid = paid_param.lower() == 'true'
Expand All @@ -474,8 +479,8 @@ def get(self, request, *args, **kwargs):

# Top users
top_users_query = base_query.filter(author__profile__paid=is_paid).values('author__username').annotate(submission_count=Count('author')).order_by('-submission_count')
if not is_paid:
top_users_query = top_users_query[:10]
if limit_param > 0:
top_users_query = top_users_query[:limit_param]
top_users = [{'author__username': user['author__username'], 'submission_count': user['submission_count']} for user in top_users_query]

# Emotion and sub-emotion counting (assuming a JSON field or similar structure)
Expand All @@ -489,6 +494,7 @@ def get(self, request, *args, **kwargs):
sub_emotion_counts[emotion][sub_emotion] += 1

return RestResponse({
'limit': limit_param,
'total_samples': total_samples,
'status_distribution': status_distribution,
'avg_time_spent': avg_time_spent,
Expand Down

0 comments on commit 5299792

Please sign in to comment.