Add annotation_zip diff command#1634
Conversation
TitleAdd annotation_zip diff command Description
Changes walkthrough 📝
|
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
| from shapely.errors import ShapelyError | ||
| from shapely.geometry import Polygon | ||
|
|
||
| import annofabcli.common.cli |
| annotation_type_dict = { | ||
| "BoundingBox": "bounding_box", | ||
| "SinglePoint": "single_point", | ||
| "Range": "range", | ||
| "Points": "points", | ||
| } | ||
| if data_type in annotation_type_dict: | ||
| return annotation_type_dict[data_type] | ||
| if data_type == "Unknown" and _get_cuboid_data(data) is not None: |
There was a problem hiding this comment.
Suggestion: data_type "Points" はサポートされない annotation_type "points" にマッピングされており、polygon と polyline が区別できません。"Points" を削除するか、polygon と polyline を判別するロジックを追加してください。 [general, importance: 9]
| annotation_type_dict = { | |
| "BoundingBox": "bounding_box", | |
| "SinglePoint": "single_point", | |
| "Range": "range", | |
| "Points": "points", | |
| } | |
| if data_type in annotation_type_dict: | |
| return annotation_type_dict[data_type] | |
| if data_type == "Unknown" and _get_cuboid_data(data) is not None: | |
| annotation_type_dict = { | |
| "BoundingBox": "bounding_box", | |
| "SinglePoint": "single_point", | |
| "Range": "range", | |
| } | |
| # "Points" は annotation_type 指定がない場合に | |
| # polygon または polyline として扱うため、明示的な判別処理を追加してください |
| left_points = left_data["points"] | ||
| right_points = right_data["points"] | ||
| left_length = _point_list_length(left_points) | ||
| right_length = _point_list_length(right_points) | ||
| return { | ||
| "length_change_ratio": _change_ratio(left_length, right_length), | ||
| "start_point_distance": _euclidean_distance(left_points[0], right_points[0], keys=["x", "y"]), | ||
| "end_point_distance": _euclidean_distance(left_points[-1], right_points[-1], keys=["x", "y"]), | ||
| "midpoint_distance": _euclidean_distance(_point_list_center(left_points), _point_list_center(right_points), keys=["x", "y"]), |
There was a problem hiding this comment.
Suggestion: 空のポイントリストや要素数1のケースでインデックスエラーが発生する可能性があるため、リスト長をチェックして安全に処理してください。 [possible issue, importance: 5]
| left_points = left_data["points"] | |
| right_points = right_data["points"] | |
| left_length = _point_list_length(left_points) | |
| right_length = _point_list_length(right_points) | |
| return { | |
| "length_change_ratio": _change_ratio(left_length, right_length), | |
| "start_point_distance": _euclidean_distance(left_points[0], right_points[0], keys=["x", "y"]), | |
| "end_point_distance": _euclidean_distance(left_points[-1], right_points[-1], keys=["x", "y"]), | |
| "midpoint_distance": _euclidean_distance(_point_list_center(left_points), _point_list_center(right_points), keys=["x", "y"]), | |
| left_points = left_data["points"] | |
| right_points = right_data["points"] | |
| if len(left_points) < 2 or len(right_points) < 2: | |
| return {k: None for k in [ | |
| "length_change_ratio", | |
| "start_point_distance", | |
| "end_point_distance", | |
| "midpoint_distance", | |
| "point_count_diff", | |
| ]} | |
| start_point_distance = _euclidean_distance(left_points[0], right_points[0], keys=["x", "y"]) | |
| end_point_distance = _euclidean_distance(left_points[-1], right_points[-1], keys=["x", "y"]) | |
| midpoint_distance = _euclidean_distance(_point_list_center(left_points), _point_list_center(right_points), keys=["x", "y"]) |
There was a problem hiding this comment.
Pull request overview
annofabcli annotation_zip diff サブコマンドを追加し、2つのアノテーションZIP(または展開ディレクトリ)間で、アノテーションの追加・削除・変更差分を集計/詳細として出力できるようにするPRです。
Changes:
- 差分算出ロジック(サマリ/詳細、各種メトリクス算出)とCLI出力(CSV/JSON/pretty JSON)を追加
annotation_zip配下にdiffサブコマンドを登録- コマンドリファレンスと単体テストを追加
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
annofabcli/annotation_zip/diff_annotation.py |
差分生成・メトリクス計算・CSV/JSON出力・CLI引数定義を追加 |
annofabcli/annotation_zip/subcommand_annotation_zip.py |
annotation_zip に diff サブコマンドを追加登録 |
docs/command_reference/annotation_zip/diff.rst |
annotation_zip diff の使用方法/出力項目を追加 |
docs/command_reference/annotation_zip/index.rst |
diff をコマンド一覧に追加 |
tests/annotation_zip/test_diff_annotation.py |
差分コアロジックとCLI呼び出しのテストを追加 |
| annotation_type_dict = { | ||
| "BoundingBox": "bounding_box", | ||
| "SinglePoint": "single_point", | ||
| "Range": "range", | ||
| "Points": "points", | ||
| } | ||
| if data_type in annotation_type_dict: | ||
| return annotation_type_dict[data_type] | ||
| if data_type == "Unknown" and _get_cuboid_data(data) is not None: | ||
| return "3d_bounding_box" | ||
| return None |
|
|
||
|
|
Summary
annofabcli annotation_zip difffor comparing two annotation ZIPs or expanded annotation directoriesTests
make formatmake lintuv run pytest tests/annotation_zip