Skip to content

Conversation

mihow
Copy link
Collaborator

@mihow mihow commented May 7, 2025

Summary

Add fields required for tracking which classifications are used for determinations. Currently it's not possible to know which algorithm or detection were used to determine the final species & score of an Occurrence. This adds fields to track that data. This will primarily be used to choose the most representative occurrence for a taxon, as well as the most representative detection for an occurrence.

Also as a consequence, this should speed up occurrence list requests greatly since is eliminates n+1 queries by saving the best classification & identification on the model instead of calculating them on the fly.

The update_occurrence_determination method was getting long and confusing, so this PR also refactors that method and adds a suite of tests.

Copy link

netlify bot commented May 7, 2025

Deploy Preview for antenna-preview canceled.

Name Link
🔨 Latest commit 9f33749
🔍 Latest deploy log https://app.netlify.com/sites/antenna-preview/deploys/6821931f82e996000828f1f7

@mihow mihow changed the base branch from main to deployments/ood.antenna.insectai.org May 7, 2025 21:47
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

This PR updates the Occurrence model to include additional fields for tracking determination data and refactors the update_occurrence_determination function to improve clarity and maintainability. It also adds comprehensive tests to ensure that classifications and identifications update the occurrence determination as expected.

  • Added new fields (favorite, best_detection, best_prediction, best_identification) to support determination tracking.
  • Refactored the update_occurrence_determination function with a task_logger and field update batching.
  • Added tests to validate behavior when using classifications and identifications.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
ami/main/tests/test_occurrence_determination.py Added tests to validate occurrence determination logic.
ami/main/tests/init.py Added module docstring for test package.
ami/main/models.py Added new fields and refactored methods (including update_occurrence_determination).
Comments suppressed due to low confidence (2)

ami/main/models.py:2466

  • The get_best_identification method lacks an implementation; consider adding logic to retrieve and return the most recent human identification.
def get_best_identification(self) -> Identification | None:

ami/main/models.py:2611

  • [nitpick] Resetting determination_score to None in this branch may be unintended; please verify that clearing this field when no identification or prediction exists aligns with the desired behavior.
if occurrence.determination_score is not None:

Copy link

netlify bot commented May 11, 2025

Deploy Preview for antenna-ood canceled.

Name Link
🔨 Latest commit 9f33749
🔍 Latest deploy log https://app.netlify.com/sites/antenna-ood/deploys/6821931f868e620008df1250

@mihow mihow marked this pull request as ready for review May 12, 2025 06:20
@mihow mihow changed the title [Draft] Update Occurrence model to determine best examples Update Occurrence model to determine best examples May 12, 2025
@mihow mihow requested a review from Copilot May 12, 2025 06:29
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

This PR refactors and extends the Occurrence model to track and determine the best examples by adding new fields and reworking methods for obtaining the best detection, prediction, and identification. Key changes include the addition of new foreign key fields (best_detection, best_prediction, best_identification) to Occurrence, refactoring of cached property methods into explicit getters for these values, and an update to the update_occurrence_determination method that now returns a tuple with updated fields.

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
ami/main/tests/init.py Added module docstring for tests.
ami/main/models.py Refactored methods to determine best detection, prediction, and identification; updated update_occurrence_determination and removed cached property cache invalidation.
ami/main/migrations/0065_detection_favorite_occurrence_best_detection_and_more.py Added new fields supporting best example selections.
ami/main/migrations/0066_populate_cached_occurence_fields.py Added migration to populate cached occurrence fields via a management command.
ami/main/management/commands/update_occurrence_determinations.py Added a new management command for updating occurrence determination fields.
ami/main/api/serializers.py Updated predictions field to use the get_best_predictions method as source.

@mihow mihow changed the title Update Occurrence model to determine best examples Update Occurrence model to save best examples May 13, 2025
@mihow mihow changed the title Update Occurrence model to save best examples Update Occurrence model to determine & save best examples May 13, 2025
@mihow mihow merged commit 3d5efa9 into deployments/ood.antenna.insectai.org May 13, 2025
6 checks passed
@mihow mihow deleted the feat/occurrence-determination-fields branch May 13, 2025 15:12
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.

1 participant