-
Notifications
You must be signed in to change notification settings - Fork 14
Framework for admins to trigger and review post-processing methods #1289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mihow
wants to merge
14
commits into
main
Choose a base branch
from
feat/post-processing-admin-scaffolding
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
8701333
docs(post-processing): design spec for admin scaffolding precursor PR
mihow 29447e7
feat(post-processing): admin scaffolding precursor
mihow a1c8600
docs(post-processing): add PR #1289 admin smoke screenshots
mihow 59a7d4b
Merge branch 'main' into feat/post-processing-admin-scaffolding
mihow 93bd529
chore: host PR screenshots on S3 instead of committing to repo
mihow 89778ea
refactor(post-processing): extract shared admin-action factory
mihow 9b4b7b3
fix(post-processing): refuse "select all across pages" in admin trigger
mihow abcb446
refactor(post-processing): address re-review on the action factory
mihow 329489e
test(post-processing): prune redundant tests, cover atomicity and abs…
mihow beacb3f
feat(post-processing): per-occurrence trigger and job stage metrics
mihow 3d74ed9
fix(post-processing): dedup occurrences_updated across flush batches
mihow b0e50fd
Merge remote-tracking branch 'origin/main' into feat/post-processing-…
mihow d977b7a
test: cut post-processing test fixture cost
mihow 8ba683a
Merge remote-tracking branch 'origin/main' into feat/post-processing-…
mihow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| """Form base for admin actions that trigger post-processing tasks. | ||
|
|
||
| Each post-processing task surfaces its tunable knobs as a Django form. The | ||
| form's ``cleaned_data`` becomes the ``config`` payload on the resulting Job | ||
| (after validation against the task's pydantic ``config_schema``). | ||
|
|
||
| Algorithm scope (which queryset/events/collection the action runs against) | ||
| lives outside the form because it varies per admin entry-point. | ||
| """ | ||
| from __future__ import annotations | ||
|
|
||
| from django import forms | ||
|
|
||
|
|
||
| class BasePostProcessingActionForm(forms.Form): | ||
| """Marker base for post-processing admin action forms. | ||
|
|
||
| Subclasses declare task-specific fields. Override ``to_config()`` if the | ||
| 1:1 ``cleaned_data → config`` mapping needs adjustment (e.g. drop empty | ||
| optional fields, derive computed values, rename keys). | ||
| """ | ||
|
|
||
| def to_config(self) -> dict: | ||
| """Return ``cleaned_data`` shaped for ``Job.params['config']``.""" | ||
| return dict(self.cleaned_data) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from django import forms | ||
|
|
||
| from ami.ml.post_processing.admin.forms import BasePostProcessingActionForm | ||
| from ami.ml.post_processing.small_size_filter import SmallSizeFilterConfig | ||
|
|
||
|
|
||
| class SmallSizeFilterActionForm(BasePostProcessingActionForm): | ||
| """Knobs surfaced when an admin triggers Small Size Filter.""" | ||
|
|
||
| size_threshold = forms.FloatField( | ||
| label="Size threshold", | ||
| initial=SmallSizeFilterConfig.__fields__["size_threshold"].default, | ||
| min_value=0.0, | ||
| max_value=1.0, | ||
| help_text=( | ||
| "Minimum bounding-box area as a fraction of the source image area " | ||
| "(width × height). Detections smaller than this are flagged as " | ||
| "'Not identifiable'. Default 0.0008 ≈ 0.08% of frame area." | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
| ), | ||
| ) | ||
|
|
||
| def clean_size_threshold(self) -> float: | ||
| v = self.cleaned_data["size_threshold"] | ||
| if not (0.0 < v < 1.0): | ||
| raise forms.ValidationError("size_threshold must be in (0, 1) exclusive.") | ||
| return v | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| """Tests for ``BasePostProcessingActionForm`` + concrete ``SmallSizeFilterActionForm``.""" | ||
| from django.test import TestCase | ||
|
|
||
| from ami.ml.post_processing.admin.forms import BasePostProcessingActionForm | ||
| from ami.ml.post_processing.admin.small_size_filter_form import SmallSizeFilterActionForm | ||
|
|
||
|
|
||
| class _OneFieldForm(BasePostProcessingActionForm): | ||
| from django import forms | ||
|
|
||
| threshold = forms.FloatField(initial=0.5) | ||
|
|
||
|
|
||
| class TestBasePostProcessingActionForm(TestCase): | ||
| def test_to_config_returns_cleaned_data(self): | ||
| form = _OneFieldForm(data={"threshold": "0.25"}) | ||
| self.assertTrue(form.is_valid()) | ||
| self.assertEqual(form.to_config(), {"threshold": 0.25}) | ||
|
|
||
|
|
||
| class TestSmallSizeFilterActionForm(TestCase): | ||
| def test_default_initial_matches_config_default(self): | ||
| form = SmallSizeFilterActionForm() | ||
| self.assertEqual(form.fields["size_threshold"].initial, 0.0008) | ||
|
|
||
| def test_valid_threshold_passes(self): | ||
| form = SmallSizeFilterActionForm(data={"size_threshold": "0.001"}) | ||
| self.assertTrue(form.is_valid()) | ||
| self.assertEqual(form.to_config(), {"size_threshold": 0.001}) | ||
|
|
||
| def test_threshold_above_one_rejected(self): | ||
| form = SmallSizeFilterActionForm(data={"size_threshold": "1.5"}) | ||
| self.assertFalse(form.is_valid()) | ||
| self.assertIn("size_threshold", form.errors) | ||
|
|
||
| def test_threshold_zero_rejected(self): | ||
| # 0.0 is excluded (open interval); django's min_value=0.0 admits zero, | ||
| # so the clean_size_threshold check is the gate. | ||
| form = SmallSizeFilterActionForm(data={"size_threshold": "0.0"}) | ||
| self.assertFalse(form.is_valid()) | ||
| self.assertIn("size_threshold", form.errors) | ||
|
|
||
| def test_threshold_at_one_rejected(self): | ||
| form = SmallSizeFilterActionForm(data={"size_threshold": "1.0"}) | ||
| self.assertFalse(form.is_valid()) | ||
| self.assertIn("size_threshold", form.errors) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| """Tests for the pydantic ``config_schema`` contract on ``BasePostProcessingTask``.""" | ||
| import pydantic | ||
| import pytest | ||
| from django.test import TestCase | ||
|
|
||
| from ami.ml.post_processing.base import BasePostProcessingTask | ||
| from ami.ml.post_processing.small_size_filter import SmallSizeFilterConfig, SmallSizeFilterTask | ||
|
|
||
|
|
||
| class TestConfigSchemaContract(TestCase): | ||
| """``__init_subclass__`` enforces ``config_schema``; ``__init__`` validates against it.""" | ||
|
|
||
| def test_subclass_without_config_schema_raises(self): | ||
| with pytest.raises(TypeError, match="config_schema"): | ||
|
|
||
| class Missing(BasePostProcessingTask): | ||
| key = "missing" | ||
| name = "Missing schema" | ||
|
|
||
| def run(self) -> None: | ||
| pass | ||
|
|
||
| def test_valid_config_builds_basemodel_instance(self): | ||
| task = SmallSizeFilterTask(source_image_collection_id=1, size_threshold=0.001) | ||
| self.assertIsInstance(task.config, SmallSizeFilterConfig) | ||
| config: SmallSizeFilterConfig = task.config # type: ignore[assignment] | ||
| self.assertEqual(config.size_threshold, 0.001) | ||
| self.assertEqual(config.source_image_collection_id, 1) | ||
|
|
||
| def test_default_value_applies_when_omitted(self): | ||
| task = SmallSizeFilterTask(source_image_collection_id=1) | ||
| config: SmallSizeFilterConfig = task.config # type: ignore[assignment] | ||
| self.assertEqual(config.size_threshold, 0.0008) | ||
|
|
||
| def test_invalid_config_raises_at_init(self): | ||
| with pytest.raises(pydantic.ValidationError): | ||
| SmallSizeFilterTask(source_image_collection_id=1, size_threshold=2.0) | ||
|
|
||
| def test_missing_required_field_raises(self): | ||
| with pytest.raises(pydantic.ValidationError): | ||
| SmallSizeFilterTask(size_threshold=0.001) | ||
|
|
||
| def test_unknown_keys_rejected(self): | ||
| with pytest.raises(pydantic.ValidationError): | ||
| SmallSizeFilterTask(source_image_collection_id=1, unknown_field="oops") |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.