Skip to content

Commit f91a415

Browse files
authored
差し戻された際のタスク履歴を特定するutilを作成しました (#709)
* 仮コミット * テストコードの追加 * poetry update * add docs
1 parent bea73d9 commit f91a415

File tree

5 files changed

+337
-90
lines changed

5 files changed

+337
-90
lines changed

annofabapi/util/task_history.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from typing import Any
2+
3+
import isodate
4+
5+
from annofabapi.pydantic_models.task_phase import TaskPhase
6+
7+
8+
def find_rejected_task_history_indices(task_history_list: list[dict[str, Any]]) -> list[int]:
9+
"""
10+
差し戻されたタスク履歴のインデックス番号(0始まり)を返します。
11+
12+
Args:
13+
task_history_list: `get_task_histories` APIのレスポンス
14+
15+
Returns:
16+
差し戻されたタスク履歴のインデックス番号のリスト
17+
"""
18+
index_list = []
19+
for index, history in enumerate(task_history_list):
20+
# 検査/受入フェーズで作業が行われているか
21+
if not (
22+
history["phase"] in {TaskPhase.INSPECTION.value, TaskPhase.ACCEPTANCE.value}
23+
and isodate.parse_duration(history["accumulated_labor_time_milliseconds"]).total_seconds() > 0
24+
and history["account_id"] is not None
25+
and history["started_datetime"] is not None
26+
and history["ended_datetime"] is not None
27+
):
28+
continue
29+
# 直後の履歴が教師付フェーズならば、差し戻されたとみなす
30+
next_index = index + 1
31+
if next_index >= len(task_history_list):
32+
# 対象の履歴は最後の履歴
33+
continue
34+
35+
next_history = task_history_list[next_index]
36+
if next_history["phase"] == TaskPhase.ANNOTATION.value:
37+
index_list.append(index)
38+
39+
return index_list

docs/api_reference/util.rst

+9
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ annofabapi.util.attribute\_restrictions module
2020
:undoc-members:
2121
:show-inheritance:
2222

23+
annofabapi.util.task\_history module
24+
---------------------------------
25+
26+
.. automodule:: annofabapi.util.task_history
27+
:members:
28+
:undoc-members:
29+
:show-inheritance:
30+
31+
2332
annofabapi.util.type\_util module
2433
---------------------------------
2534

0 commit comments

Comments
 (0)