Skip to content

Commit

Permalink
make adjustments for codereview feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
bmartel committed Nov 29, 2024
1 parent 7966afa commit c730e49
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions label_studio/data_manager/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
)
from django.conf import settings
from django.db.models import Sum
from django.db.models.functions import Coalesce
from django.utils.decorators import method_decorator
from django_filters.rest_framework import DjangoFilterBackend
from drf_yasg import openapi
Expand Down Expand Up @@ -226,14 +227,12 @@ def sync_paginate_queryset(self, queryset, request, view=None):
return super().paginate_queryset(queryset, request, view)

def paginate_totals_queryset(self, queryset, request, view=None):
totals = queryset.values('id', 'total_predictions', 'total_annotations', 'cancelled_annotations').aggregate(
total_annotations=Sum('total_annotations') - Sum('cancelled_annotations'),
total_predictions=Sum('total_predictions'),
totals = queryset.values('id').aggregate(
total_annotations=Coalesce(Sum('total_annotations'), 0),
total_predictions=Coalesce(Sum('total_predictions'), 0),
)
# if the total is None, set it to 0
# the default value of the aggregate function is None
self.total_annotations = totals['total_annotations'] or 0
self.total_predictions = totals['total_predictions'] or 0
self.total_annotations = totals['total_annotations']
self.total_predictions = totals['total_predictions']
return super().paginate_queryset(queryset, request, view)

def paginate_queryset(self, queryset, request, view=None):
Expand Down

0 comments on commit c730e49

Please sign in to comment.