Skip to content

Commit

Permalink
Help ensure occurrences always have detections
Browse files Browse the repository at this point in the history
  • Loading branch information
mihow committed Dec 7, 2023
1 parent 1e97b23 commit a9b9591
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ami/main/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,8 @@ class OccurrenceViewSet(DefaultViewSet):
"""

queryset = (
Occurrence.objects.annotate(
Occurrence.objects.filter(detections=None)
.annotate(
detections_count=models.Count("detections", distinct=True),
duration=models.Max("detections__timestamp") - models.Min("detections__timestamp"),
first_appearance_time=models.Min("detections__timestamp__time"),
Expand Down
6 changes: 6 additions & 0 deletions ami/main/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1567,6 +1567,12 @@ def save(self, update_determination=True, *args, **kwargs):
save=True,
)

if self.determination and not self.determination_score:
# This may happen for legacy occurrences that were created
# before the determination_score field was added
self.determination_score = self.get_determination_score()
self.save(update_determination=False)

class Meta:
ordering = ["-determination_score"]

Expand Down

0 comments on commit a9b9591

Please sign in to comment.