Skip to content

差し戻された際のタスク履歴を特定するutilを作成しました #709

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

Merged
merged 4 commits into from
Mar 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions annofabapi/util/task_history.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from typing import Any

import isodate

from annofabapi.pydantic_models.task_phase import TaskPhase


def find_rejected_task_history_indices(task_history_list: list[dict[str, Any]]) -> list[int]:
"""
差し戻されたタスク履歴のインデックス番号(0始まり)を返します。

Args:
task_history_list: `get_task_histories` APIのレスポンス

Returns:
差し戻されたタスク履歴のインデックス番号のリスト
"""
index_list = []
for index, history in enumerate(task_history_list):
# 検査/受入フェーズで作業が行われているか
if not (
history["phase"] in {TaskPhase.INSPECTION.value, TaskPhase.ACCEPTANCE.value}
and isodate.parse_duration(history["accumulated_labor_time_milliseconds"]).total_seconds() > 0
and history["account_id"] is not None
and history["started_datetime"] is not None
and history["ended_datetime"] is not None
):
continue
# 直後の履歴が教師付フェーズならば、差し戻されたとみなす
next_index = index + 1
if next_index >= len(task_history_list):
# 対象の履歴は最後の履歴
continue

next_history = task_history_list[next_index]
if next_history["phase"] == TaskPhase.ANNOTATION.value:
index_list.append(index)

return index_list
9 changes: 9 additions & 0 deletions docs/api_reference/util.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ annofabapi.util.attribute\_restrictions module
:undoc-members:
:show-inheritance:

annofabapi.util.task\_history module
---------------------------------

.. automodule:: annofabapi.util.task_history
:members:
:undoc-members:
:show-inheritance:


annofabapi.util.type\_util module
---------------------------------

Expand Down
Loading