From 62c1ed56448167da000d826b6f26e8fd286b4800 Mon Sep 17 00:00:00 2001 From: tusharmakkar08 Date: Wed, 8 Apr 2020 16:50:18 +0530 Subject: [PATCH 1/2] Added user completed data --- .gitignore | 1 + app/api/views.py | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 205f4f1c..d5b7c557 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ .DS_Store .AppleDouble .LSOverride +.idea # Icon must end with two \r Icon diff --git a/app/api/views.py b/app/api/views.py index a781577a..4a8b560c 100644 --- a/app/api/views.py +++ b/app/api/views.py @@ -1,3 +1,4 @@ +import collections import json from django.conf import settings from django.contrib.auth.models import User @@ -78,7 +79,8 @@ class StatisticsAPI(APIView): if not include or 'label' in include or 'user' 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: progress = self.progress(project=p) @@ -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() From 0c2cc3909b6b2c072d554ff53c374bc0a8b08290 Mon Sep 17 00:00:00 2001 From: tusharmakkar08 Date: Wed, 8 Apr 2020 18:52:22 +0530 Subject: [PATCH 2/2] Fixing test case --- app/api/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/api/views.py b/app/api/views.py index 4a8b560c..afa030f4 100644 --- a/app/api/views.py +++ b/app/api/views.py @@ -76,13 +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 # 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)