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 .DS_Store
.AppleDouble .AppleDouble
.LSOverride .LSOverride
.idea
# Icon must end with two \r # Icon must end with two \r
Icon Icon

20
app/api/views.py

@ -1,3 +1,4 @@
import collections
import json import json
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import User from django.contrib.auth.models import User
@ -75,12 +76,13 @@ class StatisticsAPI(APIView):
include = set(request.GET.getlist('include')) include = set(request.GET.getlist('include'))
response = {} 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) label_count, user_count = self.label_per_data(p)
response['label'] = label_count 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) progress = self.progress(project=p)
response.update(progress) response.update(progress)
@ -89,17 +91,27 @@ class StatisticsAPI(APIView):
return Response(response) 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): def progress(self, project):
docs = project.documents docs = project.documents
annotation_class = project.get_annotation_class() annotation_class = project.get_annotation_class()
total = docs.count() total = docs.count()
annotation_filter = Q(document_id__in=docs.all()) annotation_filter = Q(document_id__in=docs.all())
user_data = self._get_user_completion_data(annotation_class, annotation_filter)
if not project.collaborative_annotation: if not project.collaborative_annotation:
annotation_filter &= Q(user_id=self.request.user) annotation_filter &= Q(user_id=self.request.user)
done = annotation_class.objects.filter(annotation_filter)\ done = annotation_class.objects.filter(annotation_filter)\
.aggregate(Count('document', distinct=True))['document__count'] .aggregate(Count('document', distinct=True))['document__count']
remaining = total - done remaining = total - done
return {'total': total, 'remaining': remaining}
return {'total': total, 'remaining': remaining, 'user': user_data}
def label_per_data(self, project): def label_per_data(self, project):
annotation_class = project.get_annotation_class() annotation_class = project.get_annotation_class()

Loading…
Cancel
Save