Skip to content

Commit

Permalink
get_labor_control_worktime関数の修正 (#356)
Browse files Browse the repository at this point in the history
* get_labor_control_worktime: 502 errorが発生しても処理が継続できるようにする

* format

* update swagger

* auto saveを辞める

* update

* version up
  • Loading branch information
yuji38kwmt committed Sep 13, 2021
1 parent 42ded10 commit 72954ed
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 26 deletions.
6 changes: 0 additions & 6 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@
".venv/lib/python3.8/site-packages/"
],
"python.analysis.completeFunctionParens": true,
"[python]": {
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
},
},
"python.testing.autoTestDiscoverOnSaveEnabled": false,

}
2 changes: 1 addition & 1 deletion annofabapi/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.47.0"
__version__ = "0.47.1"
28 changes: 14 additions & 14 deletions annofabapi/dataclass/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,51 +173,51 @@ class FullAnnotationAdditionalData(DataClassJsonMixin):
class FullAnnotationDetail(DataClassJsonMixin):
""" """

annotation_id: Optional[str]
annotation_id: str
"""アノテーションID。[値の制約についてはこちら。](#section/API-Convention/APIID)<br> annotation_type が classification の場合は label_id と同じ値が格納されます。 """

user_id: Optional[str]
user_id: str
""""""

label_id: Optional[str]
label_id: str
""""""

label_name: Optional[InternationalizationMessage]
label_name: InternationalizationMessage
""""""

annotation_type: Optional[AnnotationType]
annotation_type: AnnotationType
""""""

data_holding_type: Optional[AnnotationDataHoldingType]
data_holding_type: AnnotationDataHoldingType
""""""

data: FullAnnotationData
""""""

additional_data_list: Optional[List[FullAnnotationAdditionalData]]
additional_data_list: List[FullAnnotationAdditionalData]
""""""


@dataclass
class FullAnnotation(DataClassJsonMixin):
""" """

project_id: Optional[str]
project_id: str
"""プロジェクトID。[値の制約についてはこちら。](#section/API-Convention/APIID) """

task_id: Optional[str]
task_id: str
"""タスクID。[値の制約についてはこちら。](#section/API-Convention/APIID) """

task_phase: Optional[TaskPhase]
task_phase: TaskPhase
""""""

task_phase_stage: Optional[int]
task_phase_stage: int
""""""

task_status: Optional[TaskStatus]
task_status: TaskStatus
""""""

input_data_id: Optional[str]
input_data_id: str
"""入力データID。[値の制約についてはこちら。](#section/API-Convention/APIID) """

input_data_name: Optional[str]
Expand All @@ -229,7 +229,7 @@ class FullAnnotation(DataClassJsonMixin):
updated_datetime: Optional[str]
""""""

annotation_format_version: Optional[str]
annotation_format_version: str
"""アノテーションフォーマットのバージョンです。 アノテーションフォーマットとは、プロジェクト個別のアノテーション仕様ではなく、AnnoFabのアノテーション構造のことです。 したがって、アノテーション仕様を更新しても、このバージョンは変化しません。 バージョンの読み方と更新ルールは、業界慣習の[Semantic Versioning](https://semver.org/)にもとづきます。 JSONに出力されるアノテーションフォーマットのバージョンは、アノテーションZIPが作成される時点のものが使われます。 すなわち、`1.0.0`の時点のタスクで作成したアノテーションであっても、フォーマットが `1.0.1` に上がった次のZIP作成時では `1.0.1` となります。 バージョンを固定してZIPを残しておきたい場合は、プロジェクトが完了した時点でZIPをダウンロードして保管しておくか、またはプロジェクトを「停止中」にします。 """


Expand Down
45 changes: 43 additions & 2 deletions annofabapi/wrapper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# pylint: disable=too-many-lines
import asyncio
import copy
import datetime
import logging
import mimetypes
import time
Expand Down Expand Up @@ -2025,6 +2026,7 @@ def _get_working_description_from_labor(labor: Dict[str, Any]) -> Optional[str]:

def get_labor_control_worktime(
self,
*,
organization_id: Optional[str] = None,
project_id: Optional[str] = None,
account_id: Optional[str] = None,
Expand Down Expand Up @@ -2070,8 +2072,47 @@ def _to_new_data(labor: Dict[str, Any]) -> Dict[str, Any]:
"from": from_date,
"to": to_date,
}
labor_list, _ = self.api.get_labor_control(query_params)
return [_to_new_data(e) for e in labor_list]
try:
labor_list, _ = self.api.get_labor_control(query_params)
return [_to_new_data(e) for e in labor_list]
except requests.HTTPError as e:
# "502 Server Error"が発生するときは、取得するレスポンスが大きすぎる可能性があるので、取得期間を分割する。
# ただし、取得する期間が指定されている場合のみ
# 注意:5XX系のエラーだと、backoffでリトライがタイムアウトしてから、この関数で処理される
DATE_FORMAT = "%Y-%m-%d"
if e.response.status_code == requests.codes.bad_gateway and from_date is not None and to_date is not None:
dt_from_date = datetime.datetime.strptime(from_date, DATE_FORMAT)
dt_to_date = datetime.datetime.strptime(to_date, DATE_FORMAT)
diff_days = (dt_to_date - dt_from_date).days

dt_new_to_date = dt_from_date + datetime.timedelta(days=diff_days // 2)
dt_new_from_date = dt_new_to_date + datetime.timedelta(days=1)
logger.debug(
"取得対象の期間が広すぎるため、データを取得できませんでした。"
f"取得対象の期間を{from_date}~{dt_new_to_date.strftime(DATE_FORMAT)}, "
f"{dt_new_from_date.strftime(DATE_FORMAT)}~{to_date}に分割して、再度取得します。"
)
tmp_list = []
tmp1 = self.get_labor_control_worktime(
organization_id=organization_id,
project_id=project_id,
account_id=account_id,
from_date=from_date,
to_date=dt_new_to_date.strftime(DATE_FORMAT),
)
tmp_list.extend(tmp1)

tmp2 = self.get_labor_control_worktime(
organization_id=organization_id,
project_id=project_id,
account_id=account_id,
from_date=dt_new_from_date.strftime(DATE_FORMAT),
to_date=to_date,
)
tmp_list.extend(tmp2)
return tmp_list

raise e

def get_labor_control_availability(
self, account_id: str, from_date: Optional[str] = None, to_date: Optional[str] = None
Expand Down
18 changes: 18 additions & 0 deletions generate/swagger/swagger-api-components.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4162,6 +4162,15 @@ components:
is_foo_bar_buz: true
FullAnnotation:
type: object
required:
- project_id
- task_id
- task_phase
- task_phase_stage
- task_status
- input_data_id
- details
- annotation_format_version
properties:
project_id:
$ref: "#/components/schemas/ProjectId"
Expand Down Expand Up @@ -4190,6 +4199,15 @@ components:
$ref: "#/components/schemas/AnnotationFormatVersion"
FullAnnotationDetail:
type: object
required:
- annotation_id
- user_id
- label_id
- label_name
- annotation_type
- data_holding_type
- data
- additional_data_list
properties:
annotation_id:
$ref: "#/components/schemas/AnnotationId"
Expand Down
2 changes: 1 addition & 1 deletion generate/swagger/swagger.v2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ info:
上記例 `account_id_count` は、タスクのフィールド `account_id` でタスクを分類したところ「`account_id` が `c5eee002` であるタスクが9件、`9f110e48` であるタスクが5件、`b25dfeb3` であるタスクが1件」だったという結果を表しています。
version: 0.120.0
version: 0.121.0
title: AnnoFab Web API
x-logo:
url: "https://annofab.com/resource/images/logo_landscape.png"
Expand Down
2 changes: 1 addition & 1 deletion generate/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ info:
上記例 `account_id_count` は、タスクのフィールド `account_id` でタスクを分類したところ「`account_id` が `c5eee002` であるタスクが9件、`9f110e48` であるタスクが5件、`b25dfeb3` であるタスクが1件」だったという結果を表しています。
また、AggregationResultの集約の件数は、合計で10000件以下に制限されており、それを超える件数がある場合は上位10000件が取得されます。もし、省略された部分を取得したい場合は、検索条件を縛って結果に上る集約の数を減らしてください。
version: 0.120.0
version: 0.121.0
title: AnnoFab Web API
x-logo:
url: "https://annofab.com/resource/images/logo_landscape.png"
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "annofabapi"
version = "0.47.0"
version = "0.47.1"
description = "Python Clinet Library of AnnoFab WebAPI (https://annofab.com/docs/api/)"
authors = ["yuji38kwmt"]
license = "MIT"
Expand Down

0 comments on commit 72954ed

Please sign in to comment.