Skip to content

Conversation

annavik
Copy link
Member

@annavik annavik commented Sep 12, 2025

Summary

In #929, we setup a view to make it possible to adjust default filters for a project. In this PR, we apply the filter for score threshold. The changes includes both frontend and backend updates.

Related Issues

Fixes #926

List of Changes

  • Added get_default_classification_threshold(project, request) to read threshold from project settings (falling back to request params if apply_defaults=false).

  • Added filter_by_score_threshold() filtering queryset method to OccurrenceQuerySet.

  • Applied default threshold filtering in:

    OccurrenceViewSet

    TaxonViewSet

    SourceImageViewSet

    SourceImageCollectionViewSet

    EventViewSet

    SummaryView

  • Removed OccurrenceDeterminationScoreFilter.

Detailed Description

This PR is the first step toward using default project-level settings filters across the platform.
It introduces support for applying the project’s configured default classification score threshold to multiple API endpoints. When a threshold is defined in the project settings, all relevant endpoints (Occurrences, Taxa, Events, Source Images, Collections, and Summary) automatically filter out records below that threshold.

At the same time, flexibility is preserved: users can bypass the defaults by passing apply_defaults=false in their request, which reverts filtering behavior back to the per-request classification_threshold parameter.

How to Test the Changes

  1. Go to the Project Details admin page and set a default classification score threshold.

  2. Check that the Occurrence, Taxon, Event, and Summary endpoints all respect the threshold.

  3. Add ?apply_defaults=false to API requests and confirm that results are no longer filtered by the project defaults.

  4. Remove the flag (or set apply_defaults=true) and confirm that defaults are applied again.

Screenshots

TBD

Deployment Notes

TBD

Checklist

  • I have tested these changes appropriately.
  • I have added and/or modified relevant tests.
  • I updated relevant documentation or comments.
  • I have verified that this PR follows the project's coding standards.
  • Any dependent changes have already been merged to main."

Copy link

netlify bot commented Sep 12, 2025

Deploy Preview for antenna-preview canceled.

Name Link
🔨 Latest commit 5404cfd
🔍 Latest deploy log https://app.netlify.com/projects/antenna-preview/deploys/68e6fe3040f89a000800a435

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@mihow mihow requested a review from Copilot September 17, 2025 07:09
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 17 out of 17 changed files in this pull request and generated 1 comment.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Collaborator

@mihow mihow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Add a few automated tests. Try testing the summary view counts like we did in the Draft Projects PR.
  • I see that the taxa in the taxa list view are showing with scores less than the default threshold.
image

@mohamedelabbas1996
Copy link
Contributor

mohamedelabbas1996 commented Sep 18, 2025

  • I see that the taxa in the taxa list view are showing with scores less than the default threshold.

This is weird since the default score threshold filter is already applied in get_taxa_observed

.filter_by_score_threshold(project, self.request) # type: ignore

@mihow
Copy link
Collaborator

mihow commented Oct 1, 2025

@annavik I committed an experiment that uses the project threshold to color code the bounding boxes in the session detail view (with the help of Claude Sonnet 4!). Below is an example of the session detail when the threshold is set to zero and when it is set to 0.8.

With the new global threshold filter, the red color is never visible. So the new idea here is that the color thresholds should be applied after the project threshold. Scale the color thresholds to the low/medium/high scores that remain after the hard cut off is made from the project threshold.

Is it possible to pass the color thresholds to the identification component in the nova library?

image image image image

@annavik
Copy link
Member Author

annavik commented Oct 6, 2025

Suggestions for FE fixes:

  • Maybe revert the dynamic color change?
  • Present detections that are not passing default filtering with a grey color
  • Include information popover in session detail view (to present default filters and color thresholds)
  • Hide configuration link for default filters if the user cannot edit the project

@mihow
Copy link
Collaborator

mihow commented Oct 6, 2025

I implemented my latest suggestion. Screenshots below. Let's discuss today!

  • Continue to return all detections from the API as we currently are
  • Remove the occurrence data from detections if the occurrences don't pass the default filters (no determination, no classification score)
  • Render the detections which are missing occurrence data as gray boxes with no hover state or link actions
  • Use the color coding just for detections that have occurrences with classification scores
image image image image

@annavik
Copy link
Member Author

annavik commented Oct 6, 2025

Conclusions after meeting:

  • In session detail view we will hide detections where the occurrence is not passing filtering criteria
  • We will still make it possible to see all detections on demand
  • We will keep color coding as is (hard coded)

mihow added 2 commits October 6, 2025 18:57
…core threshold

This reverts the dynamic color coding feature introduced in commits:
- a006d3d
- 7d9675c
- 4e89b31

Changes reverted:
- Remove calculateDynamicScoreThresholds() and getScoreColorClass() functions
- Remove projectScoreThreshold prop from Frame and FrameDetections components
- Remove neutral color styling for detections below threshold
- Restore static SCORE_THRESHOLDS usage (WARNING: 0.8, ALERT: 0.6)

Preserved changes:
- Keep projectId parameter for capture details endpoint (from 15db557)
@mihow
Copy link
Collaborator

mihow commented Oct 7, 2025

@annavik I reverted the dynamic color coding, and they gray/neutral coloring, and I am now returning occurrence data for all detections that have it. Use the new occurrence_meets_criteria property on each detection with a capture response to determine whether to render that detection when the Apply Default Filters toggle is on. Let me know if that works!

http://localhost:4000/api/v2/captures/331210/?project_id=24
image

@annavik annavik force-pushed the feat/apply-score-filter branch from 7e6af40 to 4f07b64 Compare October 7, 2025 12:57
@mihow mihow requested a review from Copilot October 9, 2025 00:15
@mihow mihow merged commit 162cd28 into main Oct 9, 2025
8 of 10 checks passed
@mihow mihow deleted the feat/apply-score-filter branch October 9, 2025 00:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement the Score threshold filter in the backend

3 participants