From e25f5b16376ad5eb60458eddaeccbb9590c417d7 Mon Sep 17 00:00:00 2001 From: xavierfav Date: Wed, 18 Apr 2018 17:02:49 +0200 Subject: [PATCH] Fix create no ground truth when exists --- datasets/models.py | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/datasets/models.py b/datasets/models.py index 4f2f72b2..c26445e2 100644 --- a/datasets/models.py +++ b/datasets/models.py @@ -681,14 +681,18 @@ def __str__(self): def propagate_annotation(self): propagate_to_parents = self.taxonomy_node.taxonomy.get_all_propagate_to_parents(self.taxonomy_node.node_id) for parent in propagate_to_parents: - GroundTruthAnnotation.objects.get_or_create(start_time=self.start_time, - end_time=self.end_time, - ground_truth=self.ground_truth, - created_by=self.created_by, - sound_dataset=self.sound_dataset, - taxonomy_node=parent, - from_candidate_annotation=self.from_candidate_annotation, - from_propagation=True) + annotation_exists = GroundTruthAnnotation.objects.filter(sound_dataset=self.sound_dataset, + taxonomy_node=parent) \ + .count() > 0 + if not annotation_exists: + GroundTruthAnnotation.objects.get_or_create(start_time=self.start_time, + end_time=self.end_time, + ground_truth=self.ground_truth, + created_by=self.created_by, + sound_dataset=self.sound_dataset, + taxonomy_node=parent, + from_candidate_annotation=self.from_candidate_annotation, + from_propagation=True) # choices for quality control test used in Vote and User Profile @@ -728,17 +732,21 @@ def save(self, request=False, *args, **kwargs): if ground_truth_state in (0.5, 1.0): candidate_annotation.ground_truth = ground_truth_state candidate_annotation.save() - ground_truth_annotation, created = GroundTruthAnnotation.objects.get_or_create( - start_time=candidate_annotation.start_time, - end_time=candidate_annotation.end_time, - ground_truth=candidate_annotation.ground_truth, - created_by=candidate_annotation.created_by, - sound_dataset=candidate_annotation.sound_dataset, - taxonomy_node=candidate_annotation.taxonomy_node, - from_candidate_annotation=candidate_annotation, - from_propagation=False) - if created: - ground_truth_annotation.propagate_annotation() + annotation_exists = GroundTruthAnnotation.objects.filter(sound_dataset=candidate_annotation.sound_dataset, + taxonomy_node=candidate_annotation.taxonomy_node)\ + .count() > 0 + if not annotation_exists: + ground_truth_annotation, created = GroundTruthAnnotation.objects.get_or_create( + start_time=candidate_annotation.start_time, + end_time=candidate_annotation.end_time, + ground_truth=candidate_annotation.ground_truth, + created_by=candidate_annotation.created_by, + sound_dataset=candidate_annotation.sound_dataset, + taxonomy_node=candidate_annotation.taxonomy_node, + from_candidate_annotation=candidate_annotation, + from_propagation=False) + if created: + ground_truth_annotation.propagate_annotation() class CategoryComment(models.Model):