-
-
Notifications
You must be signed in to change notification settings - Fork 11
feat(sequences): re-run cone matching when relabeling back to wildfire_smoke #585
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
MateoLostanlen
wants to merge
6
commits into
main
Choose a base branch
from
feat/relabel-wildfire-reattach
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 all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d72a9ef
refactor: expose attach_sequence_to_alert helper
MateoLostanlen 4a62eea
feat(sequences): re-attach sequence to alert when label reverts to wi…
MateoLostanlen 0189cc0
test(sequences): cover wildfire-relabel re-attach branch
MateoLostanlen bb5893b
fix(sequences): anchor relabel re-attach window on the sequence's own…
MateoLostanlen 7a3542d
Merge branch 'main' into feat/relabel-wildfire-reattach
MateoLostanlen c5b1820
Merge branch 'main' into feat/relabel-wildfire-reattach
MateoLostanlen 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
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
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |||||
| from sqlmodel import delete, func, select | ||||||
| from sqlmodel.ext.asyncio.session import AsyncSession | ||||||
|
|
||||||
| from app.api.api_v1.endpoints.detections import attach_sequence_to_alert | ||||||
| from app.api.dependencies import get_alert_crud, get_camera_crud, get_detection_crud, get_jwt, get_sequence_crud | ||||||
| from app.core.time import utcnow | ||||||
| from app.crud import AlertCRUD, CameraCRUD, DetectionCRUD, SequenceCRUD | ||||||
|
|
@@ -38,6 +39,18 @@ async def verify_org_rights( | |||||
| raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Access forbidden.") | ||||||
|
|
||||||
|
|
||||||
| async def _detach_sequence_from_alerts(sequence_id: int, session: AsyncSession, alerts: AlertCRUD) -> None: | ||||||
| alert_ids_res = await session.exec(select(AlertSequence.alert_id).where(AlertSequence.sequence_id == sequence_id)) | ||||||
| alert_ids = list(alert_ids_res.all()) | ||||||
| if not alert_ids: | ||||||
| return | ||||||
| delete_links: Any = delete(AlertSequence).where(cast(Any, AlertSequence.sequence_id) == sequence_id) | ||||||
| await session.exec(delete_links) | ||||||
| await session.commit() | ||||||
| for aid in alert_ids: | ||||||
| await refresh_alert_state(aid, session, alerts) | ||||||
|
|
||||||
|
|
||||||
| def _serialize_sequence(sequence: Sequence, detections_count: int = 0) -> SequenceRead: | ||||||
| return SequenceRead(**sequence.model_dump(), detections_count=detections_count) | ||||||
|
|
||||||
|
|
@@ -217,11 +230,27 @@ async def label_sequence( | |||||
| if UserRole.ADMIN not in token_payload.scopes: | ||||||
| await verify_org_rights(token_payload.organization_id, sequence.camera_id, cameras) | ||||||
|
|
||||||
| previous_label = sequence.is_wildfire | ||||||
| updated = await sequences.update(sequence_id, payload) | ||||||
|
|
||||||
| # Reverting a previously non-wildfire label back to wildfire_smoke: re-run cone matching | ||||||
| if ( | ||||||
| payload.is_wildfire == AnnotationType.WILDFIRE_SMOKE | ||||||
| and previous_label is not None | ||||||
| and previous_label != AnnotationType.WILDFIRE_SMOKE | ||||||
| ): | ||||||
| await _detach_sequence_from_alerts(sequence_id, session, alerts) | ||||||
| camera = cast(Camera, await cameras.get(sequence.camera_id, strict=True)) | ||||||
| # Anchor the candidate window on the sequence's own time so old relabels still merge | ||||||
| await attach_sequence_to_alert( | ||||||
| updated, camera, cameras, sequences, alerts, reference_time=sequence.last_seen_at | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For consistency?
Suggested change
|
||||||
| ) | ||||||
| return updated | ||||||
|
|
||||||
| if payload.is_wildfire is None or payload.is_wildfire == AnnotationType.WILDFIRE_SMOKE: | ||||||
| return updated | ||||||
|
|
||||||
| # Sequence labeled as non-wildfire: detach it from its alerts and give it a fresh one. | ||||||
| alert_ids_res = await session.exec(select(AlertSequence.alert_id).where(AlertSequence.sequence_id == sequence_id)) | ||||||
| alert_ids = list(alert_ids_res.all()) | ||||||
|
|
||||||
|
|
||||||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this returns
None(eg no neighbour in the window or cones don't overlap?) , the sequence has zero alert links. I suggest adding a fallback to make sure we don't have orphan alters.If orphaning is the intended behaviour, a one-line comment is enough for me.