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.

49 lines
1.6 KiB

  1. from collections import Counter
  2. from django.conf import settings
  3. from django.db.models import Count, Manager
  4. class AnnotationManager(Manager):
  5. def get_label_per_data(self, project):
  6. label_count = Counter()
  7. user_count = Counter()
  8. docs = project.examples.all()
  9. annotations = self.filter(example_id__in=docs.all())
  10. for d in annotations.values('label__text', 'user__username').annotate(Count('label'), Count('user')):
  11. label_count[d['label__text']] += d['label__count']
  12. user_count[d['user__username']] += d['user__count']
  13. return label_count, user_count
  14. class Seq2seqAnnotationManager(Manager):
  15. def get_label_per_data(self, project):
  16. label_count = Counter()
  17. user_count = Counter()
  18. docs = project.examples.all()
  19. annotations = self.filter(example_id__in=docs.all())
  20. for d in annotations.values('text', 'user__username').annotate(Count('text'), Count('user')):
  21. label_count[d['text']] += d['text__count']
  22. user_count[d['user__username']] += d['user__count']
  23. return label_count, user_count
  24. class RoleMappingManager(Manager):
  25. def can_update(self, project: int, mapping_id: int, rolename: str):
  26. queryset = self.filter(
  27. project=project, role__name=settings.ROLE_PROJECT_ADMIN
  28. )
  29. if queryset.count() > 1:
  30. return True
  31. else:
  32. mapping = queryset.first()
  33. if mapping.id == mapping_id and rolename != settings.ROLE_PROJECT_ADMIN:
  34. return False
  35. return True