Browse Source

Merge pull request #678 from tusharmakkar08/master

Updated statistics page user data graph
pull/684/head
Hiroki Nakayama 4 years ago
committed by GitHub
parent
commit
2ab8f62ef8
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 4 deletions
  1. 1
      .gitignore
  2. 20
      app/api/views.py

1
.gitignore

@ -4,6 +4,7 @@
.DS_Store
.AppleDouble
.LSOverride
.idea
# Icon must end with two \r
Icon

20
app/api/views.py

@ -1,3 +1,4 @@
import collections
import json
from django.conf import settings
from django.contrib.auth.models import User
@ -75,12 +76,13 @@ class StatisticsAPI(APIView):
include = set(request.GET.getlist('include'))
response = {}
if not include or 'label' in include or 'user' in include:
if not include or 'label' in include:
label_count, user_count = self.label_per_data(p)
response['label'] = label_count
response['user'] = user_count
# TODO: Make user_label count chart
response['user_label'] = user_count
if not include or 'total' in include or 'remaining' in include:
if not include or 'total' in include or 'remaining' in include or 'user' in include:
progress = self.progress(project=p)
response.update(progress)
@ -89,17 +91,27 @@ class StatisticsAPI(APIView):
return Response(response)
@staticmethod
def _get_user_completion_data(annotation_class, annotation_filter):
all_annotation_objects = annotation_class.objects.filter(annotation_filter)
set_user_data = collections.defaultdict(set)
for ind_obj in all_annotation_objects.values('user__username', 'document__id'):
set_user_data[ind_obj['user__username']].add(ind_obj['document__id'])
return {i: len(set_user_data[i]) for i in set_user_data}
def progress(self, project):
docs = project.documents
annotation_class = project.get_annotation_class()
total = docs.count()
annotation_filter = Q(document_id__in=docs.all())
user_data = self._get_user_completion_data(annotation_class, annotation_filter)
if not project.collaborative_annotation:
annotation_filter &= Q(user_id=self.request.user)
done = annotation_class.objects.filter(annotation_filter)\
.aggregate(Count('document', distinct=True))['document__count']
remaining = total - done
return {'total': total, 'remaining': remaining}
return {'total': total, 'remaining': remaining, 'user': user_data}
def label_per_data(self, project):
annotation_class = project.get_annotation_class()

Loading…
Cancel
Save