Skip to content

Commit 6653dd2

Browse files
robot-ci-heartexTravis1282dredivarisAndrejOrosbmartel
committed
fix: OPTIC-79: Add queueTotal to lsfProperties from project (#4742)
* [submodules] Build static HumanSignal/dm2 Workflow run: https://github.com/HumanSignal/label-studio/actions/runs/6099175716 * [submodules] Build static HumanSignal/label-studio-frontend Workflow run: https://github.com/HumanSignal/label-studio/actions/runs/6099186034 * [submodules] Build static HumanSignal/dm2 Workflow run: https://github.com/HumanSignal/label-studio/actions/runs/6126697671 * [submodules] Build static HumanSignal/label-studio-frontend Workflow run: https://github.com/HumanSignal/label-studio/actions/runs/6191135530 * [submodules] Build static HumanSignal/dm2 Workflow run: https://github.com/HumanSignal/label-studio/actions/runs/6191149554 * [submodules] Build static HumanSignal/dm2 Workflow run: https://github.com/HumanSignal/label-studio/actions/runs/6199486597 * [submodules] Build static HumanSignal/label-studio-frontend Workflow run: https://github.com/HumanSignal/label-studio/actions/runs/6201782822 * [submodules] Build static HumanSignal/label-studio-frontend Workflow run: https://github.com/HumanSignal/label-studio/actions/runs/6215277169 * [submodules] Build static HumanSignal/label-studio-frontend Workflow run: https://github.com/HumanSignal/label-studio/actions/runs/6237615551 * [submodules] Build static HumanSignal/label-studio-frontend Workflow run: https://github.com/HumanSignal/label-studio/actions/runs/6250094239 * [submodules] Build static HumanSignal/label-studio-frontend Workflow run: https://github.com/HumanSignal/label-studio/actions/runs/6250115389 * Add queue_total and queue_done fields to project serializer * [submodules] Build static HumanSignal/label-studio-frontend Workflow run: https://github.com/HumanSignal/label-studio/actions/runs/6403602996 * docs: LSF Update Workflow run: https://github.com/HumanSignal/label-studio/actions/runs/6403602996 * ci: Build frontend Workflow run: https://github.com/HumanSignal/label-studio/actions/runs/6403661920 * [submodules] Build static HumanSignal/dm2 Workflow run: https://github.com/HumanSignal/label-studio/actions/runs/6410235609 * [submodules] Build static HumanSignal/label-studio-frontend Workflow run: https://github.com/HumanSignal/label-studio/actions/runs/6410289300 * [submodules] Build static HumanSignal/dm2 Workflow run: https://github.com/HumanSignal/label-studio/actions/runs/6421795914 * merge develop --------- Co-authored-by: Travis1282 <travisjosephclark@gmail.com> Co-authored-by: Andreas Divaris <dredivaris@gmail.com> Co-authored-by: AndrejOros <AndrejOros@users.noreply.github.com> Co-authored-by: robot-ci-heartex <robot-ci-heartex@users.noreply.github.com> Co-authored-by: Brandon Martel <brandonmartel@gmail.com>
1 parent 3e81dbc commit 6653dd2

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

label_studio/projects/serializers.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
"""
33
import bleach
44
from constants import SAFE_HTML_ATTRIBUTES, SAFE_HTML_TAGS
5+
from django.db.models import Q
56
from projects.models import Project, ProjectImport, ProjectOnboarding, ProjectReimport, ProjectSummary
67
from rest_flex_fields import FlexFieldsModelSerializer
78
from rest_framework import serializers
89
from rest_framework.serializers import SerializerMethodField
10+
from tasks.models import Task
911
from users.serializers import UserSimpleSerializer
1012

1113

@@ -66,6 +68,16 @@ class ProjectSerializer(FlexFieldsModelSerializer):
6668
)
6769
finished_task_number = serializers.IntegerField(default=None, read_only=True, help_text='Finished tasks')
6870

71+
queue_total = serializers.SerializerMethodField()
72+
queue_done = serializers.SerializerMethodField()
73+
74+
@property
75+
def user_id(self):
76+
try:
77+
return self.context['request'].user.id
78+
except KeyError:
79+
return next(iter(self.context['user_cache']))
80+
6981
@staticmethod
7082
def get_config_has_control_tags(project):
7183
return len(project.get_parsed_config()) > 0
@@ -141,6 +153,8 @@ class Meta:
141153
'reveal_preannotations_interactively',
142154
'pinned_at',
143155
'finished_task_number',
156+
'queue_total',
157+
'queue_done',
144158
]
145159

146160
def validate_label_config(self, value):
@@ -152,6 +166,27 @@ def validate_label_config(self, value):
152166
self.instance.validate_config(value)
153167
return value
154168

169+
def get_queue_total(self, project):
170+
remain = project.tasks.filter(
171+
Q(is_labeled=False) & ~Q(annotations__completed_by_id=self.user_id)
172+
| Q(annotations__completed_by_id=self.user_id)
173+
).distinct()
174+
return remain.count()
175+
176+
def get_queue_done(self, project):
177+
tasks_filter = {
178+
'project': project,
179+
'annotations__completed_by_id': self.user_id,
180+
}
181+
182+
if project.skip_queue == project.SkipQueue.REQUEUE_FOR_ME:
183+
tasks_filter['annotations__was_cancelled'] = False
184+
185+
already_done_tasks = Task.objects.filter(**tasks_filter)
186+
result = already_done_tasks.distinct().count()
187+
188+
return result
189+
155190

156191
class ProjectOnboardingSerializer(serializers.ModelSerializer):
157192
class Meta:

0 commit comments

Comments
 (0)