Browse Source

add confirmed count to statistics api response

pull/1495/head
youichiro 3 years ago
parent
commit
778729588f
1 changed files with 17 additions and 0 deletions
  1. 17
      backend/api/views/statistics.py

17
backend/api/views/statistics.py

@ -1,5 +1,6 @@
import collections
from django.conf import settings
from django.db.models import Count, Q
from django.shortcuts import get_object_or_404
from rest_framework.permissions import IsAuthenticated
@ -30,6 +31,10 @@ class StatisticsAPI(APIView):
progress = self.progress(project=p)
response.update(progress)
if not include or 'confirmed_count' in include:
confirmed_count = self.confirmed_count(p)
response['confirmed_count'] = confirmed_count
if include:
response = {key: value for (key, value) in response.items() if key in include}
@ -59,3 +64,15 @@ class StatisticsAPI(APIView):
def label_per_data(self, project):
annotation_class = project.get_annotation_class()
return annotation_class.objects.get_label_per_data(project=project)
def confirmed_count(self, project):
confirmed_count = {
settings.ROLE_ANNOTATOR: 0,
settings.ROLE_ANNOTATION_APPROVER: 0,
settings.ROLE_PROJECT_ADMIN: 0,
}
for doc in project.examples.all():
role_names = list(set([state.confirmed_user_role.name for state in doc.states.all()]))
for role_name in role_names:
confirmed_count[role_name] += 1
return confirmed_count
Loading…
Cancel
Save