You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
1.1 KiB

  1. from collections import Counter
  2. from django.db.models import Manager, Count
  3. class AnnotationManager(Manager):
  4. def get_label_per_data(self, project):
  5. label_count = Counter()
  6. user_count = Counter()
  7. docs = project.documents.all()
  8. annotations = self.filter(document_id__in=docs.all())
  9. for d in annotations.values('label__text', 'user__username').annotate(Count('label'), Count('user')):
  10. label_count[d['label__text']] += d['label__count']
  11. user_count[d['user__username']] += d['user__count']
  12. return label_count, user_count
  13. class Seq2seqAnnotationManager(Manager):
  14. def get_label_per_data(self, project):
  15. label_count = Counter()
  16. user_count = Counter()
  17. docs = project.documents.all()
  18. annotations = self.filter(document_id__in=docs.all())
  19. for d in annotations.values('text', 'user__username').annotate(Count('text'), Count('user')):
  20. label_count[d['text']] += d['text__count']
  21. user_count[d['user__username']] += d['user__count']
  22. return label_count, user_count