Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speech task freeze #1135

Merged
merged 5 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions backend/dataset/migrations/0047_speechconversation_freeze_task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.14 on 2024-12-31 01:54

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('dataset', '0046_merge_20240416_2233'),
]

operations = [
migrations.AddField(
model_name='speechconversation',
name='freeze_task',
field=models.BooleanField(default=False, help_text='Field to Indicate whether the current task is frozen by the administrator to prevent being annotated.', verbose_name='freeze_task'),
),
]
7 changes: 7 additions & 0 deletions backend/dataset/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Model definitions for Dataset Management
"""

from django.db import models
from users.models import User, LANG_CHOICES
from organizations.models import Organization
Expand Down Expand Up @@ -485,6 +486,12 @@ class SpeechConversation(DatasetBase):
help_text=("Prepopulated prediction for the implemented models"),
)

freeze_task = models.BooleanField(
verbose_name="freeze_task",
default=False,
help_text="Field to Indicate whether the current task is frozen by the administrator to prevent being annotated.",
)

def __str__(self):
return str(self.id)

Expand Down
93 changes: 77 additions & 16 deletions backend/projects/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
from .models import *
from .registry_helper import ProjectRegistry
from dataset import models as dataset_models
from django.db.models import Exists, OuterRef

from dataset.models import (
DatasetInstance,
Expand Down Expand Up @@ -658,9 +659,9 @@ def get_supercheck_reports(proj_id, userid, start_date, end_date):
result["Rejected Word Count"] = rejected_word_count
elif proj_type in get_audio_project_types():
result["Validated Segments Duration"] = validated_audio_duration
result[
"Validated With Changes Segments Duration"
] = validated_with_changes_audio_duration
result["Validated With Changes Segments Duration"] = (
validated_with_changes_audio_duration
)
result["Rejected Segments Duration"] = rejected_audio_duration
result["Total Raw Audio Duration"] = total_raw_audio_duration
result["Average Word Error Rate R/S"] = round(avg_word_error_rate, 2)
Expand Down Expand Up @@ -912,9 +913,9 @@ def convert_prediction_json_to_annotation_result(
}
if proj_type == "AcousticNormalisedTranscriptionEditing":
text_dict["from_name"] = "verbatim_transcribed_json"
text_dict_acoustic[
"from_name"
] = "acoustic_normalised_transcribed_json"
text_dict_acoustic["from_name"] = (
"acoustic_normalised_transcribed_json"
)

id = f"shoonya_{idx}s{generate_random_string(13 - len(str(idx)))}"
label_dict["id"] = id
Expand Down Expand Up @@ -2219,9 +2220,9 @@ def create(self, request, *args, **kwargs):
if automatic_annotation_creation_mode != None:
if proj.metadata_json == None:
proj.metadata_json = {}
proj.metadata_json[
"automatic_annotation_creation_mode"
] = automatic_annotation_creation_mode
proj.metadata_json["automatic_annotation_creation_mode"] = (
automatic_annotation_creation_mode
)
if proj.project_type == "AcousticNormalisedTranscriptionEditing":
if proj.metadata_json == None:
proj.metadata_json = {}
Expand Down Expand Up @@ -2391,13 +2392,29 @@ def assign_new_tasks(self, request, pk, *args, **kwargs):
annotation_status__exact=UNLABELED, completed_by=cur_user
)
annotation_tasks = [anno.task.id for anno in proj_annotations]
pending_tasks = (
Task.objects.filter(project_id=pk)
.filter(annotation_users=cur_user.id)
.filter(task_status__in=[INCOMPLETE, UNLABELED])
.filter(id__in=annotation_tasks)
.count()
)
if project.project_type in get_audio_project_types():
pending_tasks = (
Task.objects.filter(project_id=pk)
.filter(annotation_users=cur_user.id)
.filter(task_status__in=[INCOMPLETE, UNLABELED])
.filter(id__in=annotation_tasks)
.filter(
Exists(
SpeechConversation.objects.filter(
id=OuterRef("input_data_id"), freeze_task=False
)
)
)
.count()
)
else:
pending_tasks = (
Task.objects.filter(project_id=pk)
.filter(annotation_users=cur_user.id)
.filter(task_status__in=[INCOMPLETE, UNLABELED])
.filter(id__in=annotation_tasks)
.count()
)
# assigned_tasks_queryset = Task.objects.filter(project_id=pk).filter(annotation_users=cur_user.id)
# assigned_tasks = assigned_tasks_queryset.count()
# completed_tasks = Annotation_model.objects.filter(task__in=assigned_tasks_queryset).filter(completed_by__exact=cur_user.id).count()
Expand Down Expand Up @@ -2434,6 +2451,15 @@ def assign_new_tasks(self, request, pk, *args, **kwargs):
.exclude(annotation_users=cur_user.id)
.annotate(annotator_count=Count("annotation_users"))
)
if project.project_type in get_audio_project_types():
tasks = tasks.filter(
Exists(
SpeechConversation.objects.filter(
id=OuterRef("input_data_id"), freeze_task=False
)
)
)

tasks = tasks.filter(
annotator_count__lt=project.required_annotators_per_task
).distinct()
Expand Down Expand Up @@ -2701,13 +2727,24 @@ def assign_new_review_tasks(self, request, pk, *args, **kwargs):
except Exception as e:
continue
# check if the project contains eligible tasks to pull

tasks = (
Task.objects.filter(project_id=pk)
.filter(task_status=ANNOTATED)
.filter(review_user__isnull=True)
.exclude(annotation_users=cur_user.id)
.distinct()
)

if project.project_type in get_audio_project_types():
tasks = tasks.filter(
Exists(
SpeechConversation.objects.filter(
id=OuterRef("input_data_id"), freeze_task=False
)
)
)

if not tasks:
project.release_lock(REVIEW_LOCK)
return Response(
Expand Down Expand Up @@ -2910,6 +2947,16 @@ def assign_new_supercheck_tasks(self, request, pk, *args, **kwargs):
.exclude(review_user=cur_user.id)
.distinct()
)

if project.project_type in get_audio_project_types():
tasks = tasks.filter(
Exists(
SpeechConversation.objects.filter(
id=OuterRef("input_data_id"), freeze_task=False
)
)
)

if not tasks:
project.release_lock(SUPERCHECK_LOCK)
return Response(
Expand All @@ -2923,12 +2970,26 @@ def assign_new_supercheck_tasks(self, request, pk, *args, **kwargs):
sup_exp_rev_tasks_count = (
Task.objects.filter(project_id=pk)
.filter(task_status__in=[REVIEWED, EXPORTED, SUPER_CHECKED])
.filter(
Exists(
SpeechConversation.objects.filter(
id=OuterRef("input_data_id"), freeze_task=False
)
)
)
.distinct()
.count()
)
sup_exp_tasks_count = (
Task.objects.filter(project_id=pk)
.filter(task_status__in=[SUPER_CHECKED, EXPORTED])
.filter(
Exists(
SpeechConversation.objects.filter(
id=OuterRef("input_data_id"), freeze_task=False
)
)
)
.distinct()
.count()
)
Expand Down
Loading