|
1 | | -from collections import Counter |
2 | | - |
3 | 1 | from django.conf import settings |
4 | 2 | from django.shortcuts import get_object_or_404, redirect |
5 | 3 | from django_filters.rest_framework import DjangoFilterBackend |
|
15 | 13 | from rest_framework_csv.renderers import CSVRenderer |
16 | 14 |
|
17 | 15 | from .filters import DocumentFilter |
18 | | -from .models import Project, Label, Document, Seq2seqAnnotation |
| 16 | +from .models import Project, Label, Document |
19 | 17 | from .permissions import IsAdminUserAndWriteOnly, IsProjectUser, IsOwnAnnotation |
20 | 18 | from .serializers import ProjectSerializer, LabelSerializer, DocumentSerializer, UserSerializer |
21 | 19 | from .serializers import ProjectPolymorphicSerializer |
@@ -85,20 +83,8 @@ def progress(self, project): |
85 | 83 | return {'total': total, 'remaining': remaining} |
86 | 84 |
|
87 | 85 | def label_per_data(self, project): |
88 | | - label_count = Counter() |
89 | | - user_count = Counter() |
90 | 86 | annotation_class = project.get_annotation_class() |
91 | | - docs = project.documents.all() |
92 | | - annotations = annotation_class.objects.filter(document_id__in=docs.all()) |
93 | | - if annotation_class == Seq2seqAnnotation: |
94 | | - for d in annotations.values('text', 'user__username').annotate(Count('text'), Count('user')): |
95 | | - label_count[d['text']] += d['text__count'] |
96 | | - user_count[d['user__username']] += d['user__count'] |
97 | | - else: |
98 | | - for d in annotations.values('label__text', 'user__username').annotate(Count('label'), Count('user')): |
99 | | - label_count[d['label__text']] += d['label__count'] |
100 | | - user_count[d['user__username']] += d['user__count'] |
101 | | - return label_count, user_count |
| 87 | + return annotation_class.objects.get_label_per_data(project=project) |
102 | 88 |
|
103 | 89 |
|
104 | 90 | class ApproveLabelsAPI(APIView): |
|
0 commit comments