Skip to content

Commit 027418a

Browse files
authored
Merge branch 'HumanSignal:develop' into feature/timeline-sync
2 parents 7bbcb63 + 27ec936 commit 027418a

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

label_studio/projects/models.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,10 @@ def _update_tasks_states(
418418
f'{self.maximum_annotations} and percentage {self.overlap_cohort_percentage}'
419419
)
420420
# if only maximum annotations parameter is tweaked
421-
if maximum_annotations_changed and (not overlap_cohort_percentage_changed or self.maximum_annotations == 1):
422-
tasks_with_overlap = self.tasks.filter(overlap__gt=1)
421+
if maximum_annotations_changed and not overlap_cohort_percentage_changed:
422+
# if there are tasks with overlap > 1 and maximum annotations has not been set to 1, preserve the cohort.
423+
# but if maximum_annotations is set to 1, then all tasks should be affected (since there is no longer a distinct cohort)
424+
tasks_with_overlap = self.tasks.filter(overlap__gt=1) if self.maximum_annotations > 1 else self.tasks.all()
423425
if tasks_with_overlap.exists():
424426
# if there is a part with overlapped tasks, affect only them
425427
tasks_with_overlap.update(overlap=self.maximum_annotations)
@@ -433,8 +435,17 @@ def _update_tasks_states(
433435
bulk_update_stats_project_tasks(tasks_with_overlap, project=self)
434436

435437
# if cohort slider is tweaked
436-
elif overlap_cohort_percentage_changed and self.maximum_annotations > 1:
437-
self._rearrange_overlap_cohort()
438+
elif overlap_cohort_percentage_changed:
439+
if self.maximum_annotations == 1:
440+
if maximum_annotations_changed:
441+
self.tasks.update(overlap=1)
442+
bulk_update_stats_project_tasks(self.tasks.all(), project=self)
443+
else:
444+
logger.info(
445+
f'Project {str(self)}: cohort percentage was changed but maximum annotations was not and is 1; taking no action'
446+
)
447+
else:
448+
self._rearrange_overlap_cohort()
438449

439450
# if adding/deleting tasks and cohort settings are applied
440451
elif tasks_number_changed and self.overlap_cohort_percentage < 100 and self.maximum_annotations > 1:

label_studio/tasks/models.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,17 +1395,14 @@ def bulk_update_stats_project_tasks(tasks, project=None):
13951395

13961396
with transaction.atomic():
13971397
use_overlap = project._can_use_overlap()
1398-
maximum_annotations = project.maximum_annotations
13991398
# update filters if we can use overlap
14001399
if use_overlap:
14011400
# following definition of `completed_annotations` above, count cancelled annotations
14021401
# as completed if project is in IGNORE_SKIPPED mode
14031402
completed_annotations_f_expr = F('total_annotations')
14041403
if project.skip_queue == project.SkipQueue.IGNORE_SKIPPED:
14051404
completed_annotations_f_expr += F('cancelled_annotations')
1406-
finished_q = Q(GreaterThanOrEqual(completed_annotations_f_expr, maximum_annotations)) | Q(
1407-
GreaterThanOrEqual(completed_annotations_f_expr, 1), overlap=1
1408-
)
1405+
finished_q = Q(GreaterThanOrEqual(completed_annotations_f_expr, F('overlap')))
14091406
finished_tasks = tasks.filter(finished_q)
14101407
finished_tasks_ids = finished_tasks.values_list('id', flat=True)
14111408
tasks.update(is_labeled=Q(id__in=finished_tasks_ids))

label_studio/tests/test_projects.tavern.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ stages:
192192

193193
---
194194

195-
test_name: test_overlap_change_to_1
195+
test_name: test_overlap_change_to_1_and_adjust_cohort_percentage
196196

197197
strict: False
198198

@@ -243,16 +243,12 @@ stages:
243243
url: '{django_live_url}/api/projects/{project_pk}/import?return_task_ids=true&preannotated_from_fields=bbox'
244244
response:
245245
status_code: 201
246-
save:
247-
json:
248-
first_task: "task_ids[0]"
249-
second_task: "task_ids[1]"
250-
- name: update_project_to_1
246+
- name: update_project_to_1_and_adjust_cohort_percentage
251247
request:
252248
url: "{django_live_url}/api/projects/{project_pk}"
253249
json:
254250
maximum_annotations: 1
255-
overlap_cohort_percentage: 0
251+
overlap_cohort_percentage: 40
256252
method: PATCH
257253
headers:
258254
content-type: application/json

0 commit comments

Comments
 (0)