Skip to content

Commit

Permalink
fix: fallback to non-terminal classifications if need be (non-moth)
Browse files Browse the repository at this point in the history
  • Loading branch information
mihow committed Dec 19, 2024
1 parent d40cc52 commit 3d3fb87
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
31 changes: 29 additions & 2 deletions ami/main/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,38 @@ def get_queryset(self, request: HttpRequest) -> QuerySet[Any]:
class OccurrenceAdmin(admin.ModelAdmin[Occurrence]):
"""Admin panel example for ``Occurrence`` model."""

list_display = ("id", "determination", "project", "deployment", "event")
list_display = (
"id",
"determination",
"project",
"deployment",
"event",
"detections_count",
"created_at",
"updated_at",
)

def get_queryset(self, request: HttpRequest) -> QuerySet[Any]:
qs = super().get_queryset(request)
return qs.select_related("determination", "project", "deployment", "event")
qs = qs.select_related("determination", "project", "deployment", "event")
# Add detections count to queryset
qs = qs.annotate(detections_count=models.Count("detections"))
# Add min, max and avg detection__classifications counts to queryset
# qs = qs.annotate(
# min_detection_classifications=models.Min("detections__classifications"),
# max_detection_classifications=models.Max("detections__classifications"),
# avg_detection_classifications=models.Avg("detections__classifications"),
# )
return qs

@admin.display(
description="Detections",
ordering="detections_count",
)
def detections_count(self, obj) -> int:
return obj.detections_count

ordering = ("-created_at",)


@admin.register(Classification)
Expand Down
6 changes: 4 additions & 2 deletions ami/main/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2065,9 +2065,11 @@ def best_prediction(self):
"""
Use the best prediction as the best identification if there are no human identifications.
Only consider terminal classifications (the final output of a pipeline, not intermediate models).
Uses the highest scoring classification (from any algorithm) as the best prediction.
Considers terminal classifications first, then non-terminal ones.
(Terminal classifications are the final classifications of a pipeline, non-terminal are intermediate models.)
"""
return self.predictions().filter(terminal=True).order_by("-score").first()
return self.predictions().order_by("-terminal", "-score").first()

@functools.cached_property
def best_identification(self):
Expand Down

0 comments on commit 3d3fb87

Please sign in to comment.