Skip to content

Commit

Permalink
feat: Refactor validate_empty_frames for Issue
Browse files Browse the repository at this point in the history
  • Loading branch information
nalquas committed Dec 2, 2024
1 parent 1ebbc05 commit 1dce0d4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
7 changes: 4 additions & 3 deletions raillabel_providerkit/validation/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from dataclasses import dataclass
from enum import Enum
from uuid import UUID


class IssueType(Enum):
Expand All @@ -17,9 +18,9 @@ class IssueType(Enum):
class IssueIdentifiers:
"""Information for locating an issue."""

annotation: str | None = None
frame: str | None = None
object: str | None = None
annotation: UUID | None = None
frame: int | None = None
object: UUID | None = None
sensor: str | None = None


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,25 @@

import raillabel

from raillabel_providerkit.validation import Issue, IssueIdentifiers, IssueType

def validate_empty_frames(scene: raillabel.Scene) -> list[str]:
"""Validate whether all frames of a scene have at least one annotation.
Parameters
----------
scene : raillabel.Scene
Scene, that should be validated.

Returns
-------
list[str]
list of all empty frame errors in the scene. If an empty list is returned, then there are no
errors present.
def validate_empty_frames(scene: raillabel.Scene) -> list[Issue]:
"""Validate whether all frames of a scene have at least one annotation.
If an empty list is returned, then there are no errors present.
"""
errors: list[str] = []
errors = []

for frame_uid, frame in scene.frames.items():
if _is_frame_empty(frame):
errors.append("Frame " + str(frame_uid) + " has no annotations!")
errors.append(
Issue(
type=IssueType.EMPTY_FRAMES,
reason="This frame has no annotations.",
identifiers=IssueIdentifiers(frame=frame_uid),
)
)

return errors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
_is_frame_empty,
validate_empty_frames,
)
from raillabel_providerkit.validation import Issue, IssueIdentifiers, IssueType


def test_is_frame_empty__true(empty_frame):
Expand Down Expand Up @@ -59,10 +60,12 @@ def test_validate_empty_frames__error_message_contains_indentifying_info(empty_f
0: empty_frame,
}

error_message = validate_empty_frames(scene)[0].lower()
assert "frame" in error_message
assert "0" in error_message
assert "empty" in error_message or "no annotations" in error_message
actual = validate_empty_frames(scene)[0]
assert actual == Issue(
type=IssueType.EMPTY_FRAMES,
reason="This frame has no annotations.",
identifiers=IssueIdentifiers(frame=0),
)


if __name__ == "__main__":
Expand Down

0 comments on commit 1dce0d4

Please sign in to comment.