Skip to content

Commit

Permalink
Fix create no ground truth when exists
Browse files Browse the repository at this point in the history
  • Loading branch information
xavierfav committed Apr 18, 2018
1 parent 8f8a45c commit e25f5b1
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions datasets/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit e25f5b1

Please sign in to comment.