Skip to content

Commit

Permalink
[ext] add project count fields to webhooks (#1335)
Browse files Browse the repository at this point in the history
* [ext] add fields from `Project.objects.with_counts()` to project webhooks payload.
  • Loading branch information
chiganov authored Aug 20, 2021
1 parent 316cac9 commit 33a7e18
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions label_studio/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ def for_user(self, user):
def with_counts(self):
return self.annotate(
task_number=Count('tasks', distinct=True),
finished_task_number=Count(
'tasks', distinct=True,
filter=Q(tasks__is_labeled=True)
),
total_predictions_number=Count('tasks__predictions', distinct=True),
total_annotations_number=Count(
'tasks__annotations__id', distinct=True,
Expand Down
14 changes: 14 additions & 0 deletions label_studio/webhooks/serializers_for_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ class Meta:


class ProjectWebhookSerializer(serializers.ModelSerializer):

task_number = serializers.IntegerField(read_only=True)
finished_task_number = serializers.IntegerField(read_only=True)
total_predictions_number = serializers.IntegerField(read_only=True)
total_annotations_number = serializers.IntegerField(read_only=True)
num_tasks_with_annotations = serializers.IntegerField(read_only=True)
useful_annotation_number = serializers.IntegerField(read_only=True)
ground_truth_number = serializers.IntegerField(read_only=True)
skipped_annotations_number = serializers.IntegerField(read_only=True)

def to_representation(self, instance):
instance = Project.objects.with_counts().filter(id=instance.id)[0]
return super().to_representation(instance)

class Meta:
model = Project
fields = '__all__'
Expand Down

0 comments on commit 33a7e18

Please sign in to comment.