Skip to content

Commit

Permalink
labor関係の関数を非推奨にする (#369)
Browse files Browse the repository at this point in the history
* labor関係のwebapiを非推奨にする

* udpate

* update README

* travis_retry を追加
  • Loading branch information
yuji38kwmt committed Oct 29, 2021
1 parent 83ddadd commit 0a293b5
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ python:
- "3.9"
install:
- pip install poetry
- poetry install
- travis_retry poetry install
script:
- make lint
- pytest tests/test_local*.py
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
### 2022-01-01 以降
* Python3.6のサポートを停止し、対応するPythonバージョンを3.7以上にします。

### 2022-02-01 以降
* 以下の関数を非推奨にします。WebAPIが将来的に廃止されるためです。
* AnnofabApi.get_labor_control
* Wrapper.get_labor_control_worktime
* Wrapper.get_labor_control_availability


# Features
cURLやPostmanなどよりも簡単にAnnoFab Web APIにアクセスできます。

Expand Down
2 changes: 1 addition & 1 deletion annofabapi/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.48.3"
__version__ = "0.49.0"
4 changes: 4 additions & 0 deletions annofabapi/api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import logging
import warnings
from typing import Any, Dict, Optional, Tuple

import requests
Expand Down Expand Up @@ -314,6 +315,7 @@ def refresh_token(self) -> Optional[Tuple[Dict[str, Any], requests.Response]]:
def get_labor_control(self, query_params: Optional[Dict[str, Any]] = None) -> Tuple[Any, requests.Response]:
"""労務管理関連データを一括で取得します。
.. deprecated:: 2022-02-01 以降に削除する予定です
Args:
query_params: Query Parameters
Expand All @@ -323,6 +325,8 @@ def get_labor_control(self, query_params: Optional[Dict[str, Any]] = None) -> Tu
"""
warnings.warn("deprecated", FutureWarning)

url_path = "/labor-control"
http_method = "GET"
keyword_params: Dict[str, Any] = {
Expand Down
30 changes: 18 additions & 12 deletions annofabapi/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2054,28 +2054,28 @@ def wait_until_job_is_executable(
# Public Method : Labor Control
#########################################
@staticmethod
def _get_actual_worktime_hour_from_labor(labor: Dict[str, Any]) -> Optional[float]:
def _get_actual_worktime_hour_from_labor(labor: Dict[str, Any]) -> float:
working_time_by_user = labor["values"]["working_time_by_user"]
if working_time_by_user is None:
return None
return 0

actual_worktime = working_time_by_user.get("results")
if actual_worktime is None:
return None
return 0
else:
return actual_worktime / 3600 / 1000

@staticmethod
def _get_plan_worktime_hour_from_labor(labor: Dict[str, Any]) -> Optional[float]:
def _get_plan_worktime_hour_from_labor(labor: Dict[str, Any]) -> float:
working_time_by_user = labor["values"]["working_time_by_user"]
if working_time_by_user is None:
return None
return 0

actual_worktime = working_time_by_user.get("plans")
if actual_worktime is None:
return None
plan_worktime = working_time_by_user.get("plans")
if plan_worktime is None:
return 0
else:
return actual_worktime / 3600 / 1000
return plan_worktime / 3600 / 1000

@staticmethod
def _get_working_description_from_labor(labor: Dict[str, Any]) -> Optional[str]:
Expand All @@ -2097,6 +2097,8 @@ def get_labor_control_worktime(
実績作業時間(actual_worktime)と予定作業時間(plan_worktime)を扱いやすいフォーマットで取得する。
ただし、organization_id または project_id のいずれかを指定する必要がある。
.. deprecated:: 2022-02-01 以降に削除する予定です
Args:
organization_id: 絞り込み対象の組織ID
project_id: 絞り込み対象のプロジェクトID
Expand All @@ -2112,8 +2114,9 @@ def get_labor_control_worktime(
* date
* actual_worktime:実績作業時間[hour]
* plan_worktime:予定作業時間[hour]
* working_description:実績に関するコメント
* working_description:実績に関するコメント(optional)
"""
warnings.warn("deprecated", FutureWarning)

def _to_new_data(labor: Dict[str, Any]) -> Dict[str, Any]:
labor["actual_worktime"] = self._get_actual_worktime_hour_from_labor(labor)
Expand All @@ -2134,7 +2137,7 @@ def _to_new_data(labor: Dict[str, Any]) -> Dict[str, Any]:
}
try:
labor_list, _ = self.api.get_labor_control(query_params)
return [_to_new_data(e) for e in labor_list]
return [_to_new_data(elm) for elm in labor_list if elm["account_id"] is not None]
except requests.HTTPError as e:
# "502 Server Error"が発生するときは、取得するレスポンスが大きすぎる可能性があるので、取得期間を分割する。
# ただし、取得する期間が指定されている場合のみ
Expand Down Expand Up @@ -2180,6 +2183,8 @@ def get_labor_control_availability(
"""
労務管理の予定稼働時間を取得する。
.. deprecated:: 2022-02-01 以降に削除する予定です
Args:
account_id: 絞り込み対象のアカウントID
from_date: 絞り込み対象の開始日(YYYY-MM-DD)
Expand All @@ -2191,6 +2196,7 @@ def get_labor_control_availability(
* date
* availability:予定稼働時間[hour]
"""
warnings.warn("deprecated", FutureWarning)

def _to_new_data(labor: Dict[str, Any]) -> Dict[str, Any]:
labor["availability"] = self._get_plan_worktime_hour_from_labor(labor)
Expand All @@ -2204,7 +2210,7 @@ def _to_new_data(labor: Dict[str, Any]) -> Dict[str, Any]:
"to": to_date,
}
labor_list, _ = self.api.get_labor_control(query_params)
return [_to_new_data(e) for e in labor_list]
return [_to_new_data(e) for e in labor_list if e["account_id"] is not None]

def put_labor_control_actual_worktime(
self,
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.48.3"
version = "0.49.0"
description = "Python Clinet Library of AnnoFab WebAPI (https://annofab.com/docs/api/)"
authors = ["yuji38kwmt"]
license = "MIT"
Expand Down

0 comments on commit 0a293b5

Please sign in to comment.