Skip to content

Commit

Permalink
get prev/next annotation tasks by audio start date order rather than …
Browse files Browse the repository at this point in the history
…task id

Evolution of seed to match production reality
  • Loading branch information
ElodieENSTA committed Jan 17, 2024
1 parent 48b1419 commit 17c3932
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
2 changes: 1 addition & 1 deletion backend/api/management/commands/seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def _create_annotation_campaigns(self):
campaign.datasets.add(dataset)
campaign.spectro_configs.add(dataset.spectro_configs.first())
tasks = []
for file in dataset.files.all():
for file in dataset.files.all().order_by("?"):
for user in self.users:
task = AnnotationTask(
dataset_file=file,
Expand Down
42 changes: 25 additions & 17 deletions backend/api/serializers/annotation_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,32 +184,41 @@ def get_prevAnnotations(self, task):
return AnnotationTaskResultSerializer(queryset, many=True).data

def get_prevAndNextAnnotation(self, task):
id__lt = (
taskMetadatum = (
AnnotationTask.objects.filter(id=task.id)
.first()
.dataset_file.audio_metadatum
)
id_prev = (
AnnotationTask.objects.filter(
annotation_campaign=task.annotation_campaign.id,
annotator=task.annotator.id,
id__lt=task.id,
dataset_file__audio_metadatum__start__lt=taskMetadatum.start,
)
.order_by("id")
.order_by("dataset_file__audio_metadatum__start")
.reverse()
.first()
)
id__gt = AnnotationTask.objects.filter(
annotation_campaign=task.annotation_campaign.id,
annotator=task.annotator.id,
id__gt=task.id,
).first()

if id__lt is None:
id__lt = ""
id_next = (
AnnotationTask.objects.filter(
annotation_campaign=task.annotation_campaign.id,
annotator=task.annotator.id,
dataset_file__audio_metadatum__start__gt=taskMetadatum.start,
)
.order_by("dataset_file__audio_metadatum__start")
.first()
)

if id_prev is None:
id_prev = ""
else:
id__lt = id__lt.id
if id__gt is None:
id__gt = ""
id_prev = id_prev.id
if id_next is None:
id_next = ""
else:
id__gt = id__gt.id
id_next = id_next.id

return {"prev": id__lt, "next": id__gt}
return {"prev": id_prev, "next": id_next}

@extend_schema_field(AnnotationCommentSerializer(many=True))
def get_taskComment(self, task):
Expand Down Expand Up @@ -334,7 +343,6 @@ class AnnotationTaskOneResultUpdateSerializer(AnnotationTaskUpdateSerializer):
"""

def update(self, instance, validated_data):

instance = self._create_results(instance, validated_data)

return instance
Expand Down

0 comments on commit 17c3932

Please sign in to comment.