Skip to content

Commit 6455754

Browse files
committed
Fix progress bar so that it shows number of labelled documents for seq2seq and added field to allow for seq2seq export.
1 parent 50c7078 commit 6455754

3 files changed

Lines changed: 12 additions & 5 deletions

File tree

app/api/serializers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,5 +160,5 @@ class Seq2seqAnnotationSerializer(serializers.ModelSerializer):
160160

161161
class Meta:
162162
model = Seq2seqAnnotation
163-
fields = ('id', 'text', 'user', 'document')
163+
fields = ('id', 'text', 'user', 'document', 'prob')
164164
read_only_fields = ('user',)

app/api/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ def render(self, data, accepted_media_type=None, renderer_context=None):
373373
ensure_ascii=self.ensure_ascii,
374374
allow_nan=not self.strict) + '\n'
375375

376+
376377
class JSONPainter(object):
377378

378379
def paint(self, documents):
@@ -406,6 +407,7 @@ def paint_labels(documents, labels):
406407
data.append(d)
407408
return data
408409

410+
409411
class CSVPainter(JSONPainter):
410412

411413
def paint(self, documents):

app/api/views.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from rest_framework_csv.renderers import CSVRenderer
1616

1717
from .filters import DocumentFilter
18-
from .models import Project, Label, Document
18+
from .models import Project, Label, Document, Seq2seqAnnotation
1919
from .permissions import IsAdminUserAndWriteOnly, IsProjectUser, IsOwnAnnotation
2020
from .serializers import ProjectSerializer, LabelSerializer, DocumentSerializer, UserSerializer
2121
from .serializers import ProjectPolymorphicSerializer
@@ -90,9 +90,14 @@ def label_per_data(self, project):
9090
annotation_class = project.get_annotation_class()
9191
docs = project.documents.all()
9292
annotations = annotation_class.objects.filter(document_id__in=docs.all())
93-
for d in annotations.values('label__text', 'user__username').annotate(Count('label'), Count('user')):
94-
label_count[d['label__text']] += d['label__count']
95-
user_count[d['user__username']] += d['user__count']
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']
96101
return label_count, user_count
97102

98103

0 commit comments

Comments
 (0)