From 72ef1c14c9fabbdf9a1674a3fbf83157704b1a4e Mon Sep 17 00:00:00 2001 From: yuji38kwmt Date: Wed, 20 Oct 2021 17:11:06 +0900 Subject: [PATCH 01/12] update swagger --- generate/swagger/swagger-api-components.yaml | 55 ++++ generate/swagger/swagger.v2.yaml | 2 +- generate/swagger/swagger.yaml | 287 ++++++++++++++++++- 3 files changed, 337 insertions(+), 7 deletions(-) diff --git a/generate/swagger/swagger-api-components.yaml b/generate/swagger/swagger-api-components.yaml index 01790875..30d98a3a 100644 --- a/generate/swagger/swagger-api-components.yaml +++ b/generate/swagger/swagger-api-components.yaml @@ -1988,6 +1988,61 @@ components: description: ユーザごとの作業時間情報 items: $ref: "#/components/schemas/AccountWorktimeStatistics" + WorktimeStatisticsByAccount: + type: object + required: + - project_id + - account_id + - data_series + properties: + project_id: + $ref: "#/components/schemas/ProjectId" + account_id: + $ref: "#/components/schemas/AccountId" + data_series: + type: array + description: プロジェクトメンバーの日毎の作業時間統計データ + items: + $ref: "#/components/schemas/WorktimeStatisticsData" + WorktimeStatisticsByProject: + type: object + required: + - project_id + - data_series + properties: + project_id: + $ref: "#/components/schemas/ProjectId" + data_series: + type: array + description: プロジェクトの日毎の作業時間統計データ + items: + $ref: "#/components/schemas/WorktimeStatisticsData" + WorktimeStatisticsData: + type: object + required: + - date + - grouped_by_input + - grouped_by_task + - grouped_by_minute + properties: + date: + type: string + format: date + grouped_by_input: + description: ユーザごとの画像1個当たりの作業時間情報(動画プロジェクトの場合は空リスト) + type: array + items: + $ref: "#/components/schemas/WorktimeStatisticsItem" + grouped_by_task: + description: ユーザごとのタスク1個当たりの作業時間情報(動画プロジェクトの場合は空リスト) + type: array + items: + $ref: "#/components/schemas/WorktimeStatisticsItem" + grouped_by_minute: + description: ユーザごとの動画1分当たりの作業時間情報(画像プロジェクトの場合は空リスト) + type: array + items: + $ref: "#/components/schemas/WorktimeStatisticsItem" WorktimeStatisticsItem: type: object required: diff --git a/generate/swagger/swagger.v2.yaml b/generate/swagger/swagger.v2.yaml index d855b1e1..c298713d 100644 --- a/generate/swagger/swagger.v2.yaml +++ b/generate/swagger/swagger.v2.yaml @@ -115,7 +115,7 @@ info: 上記例 `account_id_count` は、タスクのフィールド `account_id` でタスクを分類したところ「`account_id` が `c5eee002` であるタスクが9件、`9f110e48` であるタスクが5件、`b25dfeb3` であるタスクが1件」だったという結果を表しています。 - version: 0.123.0 + version: 0.125.0 title: AnnoFab Web API x-logo: url: "https://annofab.com/resource/images/logo_landscape.png" diff --git a/generate/swagger/swagger.yaml b/generate/swagger/swagger.yaml index 7822f401..574c70c8 100644 --- a/generate/swagger/swagger.yaml +++ b/generate/swagger/swagger.yaml @@ -116,7 +116,7 @@ info: 上記例 `account_id_count` は、タスクのフィールド `account_id` でタスクを分類したところ「`account_id` が `c5eee002` であるタスクが9件、`9f110e48` であるタスクが5件、`b25dfeb3` であるタスクが1件」だったという結果を表しています。 また、AggregationResultの集約の件数は、合計で10000件以下に制限されており、それを超える件数がある場合は上位10000件が取得されます。もし、省略された部分を取得したい場合は、検索条件を縛って結果に上る集約の数を減らしてください。 - version: 0.123.0 + version: 0.125.0 title: AnnoFab Web API x-logo: url: "https://annofab.com/resource/images/logo_landscape.png" @@ -2592,11 +2592,56 @@ paths: $ref: "swagger-api-components.yaml#/components/responses/ErrorForbiddenResource" "503": $ref: "swagger-api-components.yaml#/components/responses/ErrorUnderMaintenance" - /projects/{project_id}/statistics/tasks: + /projects/{project_id}/statistics/tasks/daily: get: tags: - af-statistics summary: タスク集計取得 + description: | + 指定した期間の [タスク集計データ](#section/ArrayOfProjectTaskStatisticsHistory) を取得できるAPI。取得期間は最大3か月です。 + security: + - AllProjectMember: [] + operationId: getTaskDailyStatistics + parameters: + - name: project_id + in: path + description: プロジェクトID + required: true + schema: + $ref: "swagger-api-components.yaml#/components/schemas/ProjectId" + - name: from + in: query + description: 取得する統計の区間の開始日 - `YYYY-MM-DD` + required: true + schema: + type: string + - name: to + in: query + description: 取得する統計の区間の終了日 - `YYYY-MM-DD` 。この日は含まれます。 + required: true + schema: + type: string + responses: + "200": + description: 正常 + content: + application/json: + schema: + $ref: "swagger-api-components.yaml#/components/schemas/ArrayOfProjectTaskStatisticsHistory" + "400": + $ref: "swagger-api-components.yaml#/components/responses/ErrorInvalidRequest" + "401": + $ref: "swagger-api-components.yaml#/components/responses/ErrorUnauthorizedApi" + "404": + $ref: "swagger-api-components.yaml#/components/responses/ErrorMissingResource" + "503": + $ref: "swagger-api-components.yaml#/components/responses/ErrorUnderMaintenance" + /projects/{project_id}/statistics/tasks: + get: + deprecated: true + tags: + - af-statistics + summary: タスク集計ファイルへのURL取得 description: | [タスク集計データ](#section/ArrayOfProjectTaskStatisticsHistory) を取得するための認証済み一時URLを取得します。 security: @@ -2620,9 +2665,10 @@ paths: $ref: "swagger-api-components.yaml#/components/responses/ErrorUnderMaintenance" /projects/{project_id}/statistics/accounts: get: + deprecated: true tags: - af-statistics - summary: ユーザー別タスク集計取得 + summary: ユーザー別タスク集計ファイルへのURL取得 description: | [ユーザー別タスク集計データ](#section/ArrayOfProjectAccountStatistics) を取得するための認証済み一時URLを取得します。 security: @@ -2644,11 +2690,56 @@ paths: $ref: "swagger-api-components.yaml#/components/responses/ErrorMissingResource" "503": $ref: "swagger-api-components.yaml#/components/responses/ErrorUnderMaintenance" + /projects/{project_id}/statistics/accounts/daily: + get: + tags: + - af-statistics + summary: ユーザー別タスク集計取得 + description: | + 指定した期間の [ユーザー別タスク集計データ](#section/ArrayOfProjectAccountStatistics) を取得できるAPI。取得期間は最大3か月です。 + security: + - AllProjectMember: [ ] + operationId: getAccountDailyStatistics + parameters: + - name: project_id + in: path + description: プロジェクトID + required: true + schema: + $ref: "swagger-api-components.yaml#/components/schemas/ProjectId" + - name: from + in: query + description: 取得する統計の区間の開始日 - `YYYY-MM-DD` + required: true + schema: + type: string + - name: to + in: query + description: 取得する統計の区間の終了日 - `YYYY-MM-DD` 。この日は含まれます。 + required: true + schema: + type: string + responses: + "200": + description: 正常 + content: + application/json: + schema: + $ref: "swagger-api-components.yaml#/components/schemas/ArrayOfProjectAccountStatistics" + "400": + $ref: "swagger-api-components.yaml#/components/responses/ErrorInvalidRequest" + "401": + $ref: "swagger-api-components.yaml#/components/responses/ErrorUnauthorizedApi" + "404": + $ref: "swagger-api-components.yaml#/components/responses/ErrorMissingResource" + "503": + $ref: "swagger-api-components.yaml#/components/responses/ErrorUnderMaintenance" /projects/{project_id}/statistics/inspections: get: + deprecated: true tags: - af-statistics - summary: 検査コメント集計取得 + summary: 検査コメント集計ファイルへのURL取得 description: | [検査コメント集計データ](#section/ArrayOfInspectionStatistics) を取得するための認証済み一時URLを取得します。 security: @@ -2670,11 +2761,56 @@ paths: $ref: "swagger-api-components.yaml#/components/responses/ErrorMissingResource" "503": $ref: "swagger-api-components.yaml#/components/responses/ErrorUnderMaintenance" + /projects/{project_id}/statistics/inspections/daily: + get: + tags: + - af-statistics + summary: 検査コメント集計取得 + description: | + 指定した期間の [検査コメント集計データ](#section/ArrayOfInspectionStatistics) を取得できるAPI。取得期間は最大3か月です。 + security: + - AllProjectMember: [ ] + operationId: getInspectionDailyStatistics + parameters: + - name: project_id + in: path + description: プロジェクトID + required: true + schema: + $ref: "swagger-api-components.yaml#/components/schemas/ProjectId" + - name: from + in: query + description: 取得する統計の区間の開始日 - `YYYY-MM-DD` + required: true + schema: + type: string + - name: to + in: query + description: 取得する統計の区間の終了日 - `YYYY-MM-DD` 。この日は含まれます。 + required: true + schema: + type: string + responses: + "200": + description: 正常 + content: + application/json: + schema: + $ref: "swagger-api-components.yaml#/components/schemas/ArrayOfInspectionStatistics" + "400": + $ref: "swagger-api-components.yaml#/components/responses/ErrorInvalidRequest" + "401": + $ref: "swagger-api-components.yaml#/components/responses/ErrorUnauthorizedApi" + "404": + $ref: "swagger-api-components.yaml#/components/responses/ErrorMissingResource" + "503": + $ref: "swagger-api-components.yaml#/components/responses/ErrorUnderMaintenance" /projects/{project_id}/statistics/task-phases: get: + deprecated: true tags: - af-statistics - summary: フェーズ別タスク集計取得 + summary: フェーズ別タスク集計ファイルへのURL取得 description: | [フェーズ別タスク集計データ](#section/ArrayOfTaskPhaseStatistics) を取得するための認証済み一時URLを取得します。 security: @@ -2696,6 +2832,50 @@ paths: $ref: "swagger-api-components.yaml#/components/responses/ErrorMissingResource" "503": $ref: "swagger-api-components.yaml#/components/responses/ErrorUnderMaintenance" + /projects/{project_id}/statistics/task-phases/daily: + get: + tags: + - af-statistics + summary: フェーズ別タスク集計取得 + description: | + 指定した期間の [フェーズ別タスク集計データ](#section/ArrayOfTaskPhaseStatistics) を取得できるAPI。取得期間は最大3か月です。 + security: + - AllProjectMember: [ ] + operationId: getPhaseDailyStatistics + parameters: + - name: project_id + in: path + description: プロジェクトID + required: true + schema: + $ref: "swagger-api-components.yaml#/components/schemas/ProjectId" + - name: from + in: query + description: 取得する統計の区間の開始日 - `YYYY-MM-DD` + required: true + schema: + type: string + - name: to + in: query + description: 取得する統計の区間の終了日 - `YYYY-MM-DD` 。この日は含まれます。 + required: true + schema: + type: string + responses: + "200": + description: 正常 + content: + application/json: + schema: + $ref: "swagger-api-components.yaml#/components/schemas/ArrayOfTaskPhaseStatistics" + "400": + $ref: "swagger-api-components.yaml#/components/responses/ErrorInvalidRequest" + "401": + $ref: "swagger-api-components.yaml#/components/responses/ErrorUnauthorizedApi" + "404": + $ref: "swagger-api-components.yaml#/components/responses/ErrorMissingResource" + "503": + $ref: "swagger-api-components.yaml#/components/responses/ErrorUnderMaintenance" /projects/{project_id}/statistics/labels: get: tags: @@ -2724,9 +2904,10 @@ paths: $ref: "swagger-api-components.yaml#/components/responses/ErrorUnderMaintenance" /projects/{project_id}/statistics/worktimes: get: + deprecated: true tags: - af-statistics - summary: タスク作業時間集計取得 + summary: タスク作業時間集計ファイルへのURL取得 description: | [タスク作業時間集計データ](#section/ArrayOfWorktimeStatistics) を取得するための認証済み一時URLを取得します。 security: @@ -2748,6 +2929,100 @@ paths: $ref: "swagger-api-components.yaml#/components/responses/ErrorMissingResource" "503": $ref: "swagger-api-components.yaml#/components/responses/ErrorUnderMaintenance" + /projects/{project_id}/statistics/worktimes/daily: + get: + tags: + - af-statistics + summary: プロジェクト単位のフェーズ別タスク集計取得 + description: | + 指定したプロジェクトのタスク作業時間集計データを指定した期間分取得できるAPI。取得期間は最大3か月です。 + security: + - AllProjectMember: [ ] + operationId: getWorktimeDailyStatistics + parameters: + - name: project_id + in: path + description: プロジェクトID + required: true + schema: + $ref: "swagger-api-components.yaml#/components/schemas/ProjectId" + - name: from + in: query + description: 取得する統計の区間の開始日 - `YYYY-MM-DD` + required: true + schema: + type: string + - name: to + in: query + description: 取得する統計の区間の終了日 - `YYYY-MM-DD` 。この日は含まれます。 + required: true + schema: + type: string + responses: + "200": + description: 正常 + content: + application/json: + schema: + $ref: "swagger-api-components.yaml#/components/schemas/WorktimeStatisticsByProject" + "400": + $ref: "swagger-api-components.yaml#/components/responses/ErrorInvalidRequest" + "401": + $ref: "swagger-api-components.yaml#/components/responses/ErrorUnauthorizedApi" + "404": + $ref: "swagger-api-components.yaml#/components/responses/ErrorMissingResource" + "503": + $ref: "swagger-api-components.yaml#/components/responses/ErrorUnderMaintenance" + /projects/{project_id}/statistics/worktimes-by-account/{account_id}/daily: + get: + tags: + - af-statistics + summary: プロジェクトメンバー単位のフェーズ別タスク集計取得 + description: | + 指定したプロジェクトメンバーのタスク作業時間集計データを指定した期間分取得できるAPI。取得期間は最大3か月です。 + security: + - AllProjectMember: [ ] + operationId: getWorktimeDailyStatisticsByAccount + parameters: + - name: project_id + in: path + description: プロジェクトID + required: true + schema: + $ref: "swagger-api-components.yaml#/components/schemas/ProjectId" + - name: account_id + in: path + description: アカウントID + required: true + schema: + $ref: "swagger-api-components.yaml#/components/schemas/AccountId" + - name: from + in: query + description: 取得する統計の区間の開始日 - `YYYY-MM-DD` + required: true + schema: + type: string + - name: to + in: query + description: 取得する統計の区間の終了日 - `YYYY-MM-DD` 。この日は含まれます。 + required: true + schema: + type: string + responses: + "200": + description: 正常 + content: + application/json: + schema: + $ref: "swagger-api-components.yaml#/components/schemas/WorktimeStatisticsByAccount" + "400": + $ref: "swagger-api-components.yaml#/components/responses/ErrorInvalidRequest" + "401": + $ref: "swagger-api-components.yaml#/components/responses/ErrorUnauthorizedApi" + "404": + $ref: "swagger-api-components.yaml#/components/responses/ErrorMissingResource" + "503": + $ref: "swagger-api-components.yaml#/components/responses/ErrorUnderMaintenance" /projects/{project_id}/statistics/markers: get: tags: From 59b5f21bbf7c4c237abfe4618f807ef0dd2354a8 Mon Sep 17 00:00:00 2001 From: yuji38kwmt Date: Wed, 20 Oct 2021 17:12:22 +0900 Subject: [PATCH 02/12] update --- annofabapi/generated_api.py | 201 +++++++++++++++++++++++++++++++++++- annofabapi/models.py | 45 ++++++++ 2 files changed, 241 insertions(+), 5 deletions(-) diff --git a/annofabapi/generated_api.py b/annofabapi/generated_api.py index 40c32cf4..2fa4ae63 100644 --- a/annofabapi/generated_api.py +++ b/annofabapi/generated_api.py @@ -2370,10 +2370,41 @@ def put_project_member( # NOTE: This method is auto generated by OpenAPI Generator ######################################### - def get_account_statistics(self, project_id: str, **kwargs) -> Tuple[Any, requests.Response]: + def get_account_daily_statistics( + self, project_id: str, query_params: Optional[Dict[str, Any]] = None, **kwargs + ) -> Tuple[Any, requests.Response]: """ユーザー別タスク集計取得 + https://annofab.com/docs/api/#operation/getAccountDailyStatistics + + + authorizations: AllProjectMember + + + 指定した期間の [ユーザー別タスク集計データ](#section/ArrayOfProjectAccountStatistics) を取得できるAPI。取得期間は最大3か月です。 + + Args: + project_id (str): プロジェクトID (required) + query_params (Dict[str, Any]): Query Parameters + _from (str): 取得する統計の区間の開始日 - `YYYY-MM-DD` (required) + to (str): 取得する統計の区間の終了日 - `YYYY-MM-DD` 。この日は含まれます。 (required) + + Returns: + Tuple[List[ProjectAccountStatistics], requests.Response] + + + """ + url_path = f"/projects/{project_id}/statistics/accounts/daily" + http_method = "GET" + keyword_params: Dict[str, Any] = { + "query_params": query_params, + } + return self._request_wrapper(http_method, url_path, **keyword_params) + + def get_account_statistics(self, project_id: str, **kwargs) -> Tuple[Any, requests.Response]: + """ユーザー別タスク集計ファイルへのURL取得 https://annofab.com/docs/api/#operation/getAccountStatistics + .. deprecated:: X authorizations: AllProjectMember @@ -2388,15 +2419,47 @@ def get_account_statistics(self, project_id: str, **kwargs) -> Tuple[Any, reques """ + warnings.warn("deprecated", FutureWarning) url_path = f"/projects/{project_id}/statistics/accounts" http_method = "GET" keyword_params: Dict[str, Any] = {} return self._request_wrapper(http_method, url_path, **keyword_params) - def get_inspection_statistics(self, project_id: str, **kwargs) -> Tuple[Any, requests.Response]: + def get_inspection_daily_statistics( + self, project_id: str, query_params: Optional[Dict[str, Any]] = None, **kwargs + ) -> Tuple[Any, requests.Response]: """検査コメント集計取得 + https://annofab.com/docs/api/#operation/getInspectionDailyStatistics + + + authorizations: AllProjectMember + + + 指定した期間の [検査コメント集計データ](#section/ArrayOfInspectionStatistics) を取得できるAPI。取得期間は最大3か月です。 + + Args: + project_id (str): プロジェクトID (required) + query_params (Dict[str, Any]): Query Parameters + _from (str): 取得する統計の区間の開始日 - `YYYY-MM-DD` (required) + to (str): 取得する統計の区間の終了日 - `YYYY-MM-DD` 。この日は含まれます。 (required) + + Returns: + Tuple[List[InspectionStatistics], requests.Response] + + + """ + url_path = f"/projects/{project_id}/statistics/inspections/daily" + http_method = "GET" + keyword_params: Dict[str, Any] = { + "query_params": query_params, + } + return self._request_wrapper(http_method, url_path, **keyword_params) + + def get_inspection_statistics(self, project_id: str, **kwargs) -> Tuple[Any, requests.Response]: + """検査コメント集計ファイルへのURL取得 https://annofab.com/docs/api/#operation/getInspectionStatistics + .. deprecated:: X authorizations: AllProjectMember @@ -2411,6 +2474,7 @@ def get_inspection_statistics(self, project_id: str, **kwargs) -> Tuple[Any, req """ + warnings.warn("deprecated", FutureWarning) url_path = f"/projects/{project_id}/statistics/inspections" http_method = "GET" keyword_params: Dict[str, Any] = {} @@ -2462,10 +2526,71 @@ def get_markers(self, project_id: str, **kwargs) -> Tuple[Any, requests.Response keyword_params: Dict[str, Any] = {} return self._request_wrapper(http_method, url_path, **keyword_params) - def get_task_phase_statistics(self, project_id: str, **kwargs) -> Tuple[Any, requests.Response]: + def get_phase_daily_statistics( + self, project_id: str, query_params: Optional[Dict[str, Any]] = None, **kwargs + ) -> Tuple[Any, requests.Response]: """フェーズ別タスク集計取得 + https://annofab.com/docs/api/#operation/getPhaseDailyStatistics + + + authorizations: AllProjectMember + + + 指定した期間の [フェーズ別タスク集計データ](#section/ArrayOfTaskPhaseStatistics) を取得できるAPI。取得期間は最大3か月です。 + + Args: + project_id (str): プロジェクトID (required) + query_params (Dict[str, Any]): Query Parameters + _from (str): 取得する統計の区間の開始日 - `YYYY-MM-DD` (required) + to (str): 取得する統計の区間の終了日 - `YYYY-MM-DD` 。この日は含まれます。 (required) + + Returns: + Tuple[List[TaskPhaseStatistics], requests.Response] + + + """ + url_path = f"/projects/{project_id}/statistics/task-phases/daily" + http_method = "GET" + keyword_params: Dict[str, Any] = { + "query_params": query_params, + } + return self._request_wrapper(http_method, url_path, **keyword_params) + + def get_task_daily_statistics( + self, project_id: str, query_params: Optional[Dict[str, Any]] = None, **kwargs + ) -> Tuple[Any, requests.Response]: + """タスク集計取得 + https://annofab.com/docs/api/#operation/getTaskDailyStatistics + + + authorizations: AllProjectMember + + + 指定した期間の [タスク集計データ](#section/ArrayOfProjectTaskStatisticsHistory) を取得できるAPI。取得期間は最大3か月です。 + + Args: + project_id (str): プロジェクトID (required) + query_params (Dict[str, Any]): Query Parameters + _from (str): 取得する統計の区間の開始日 - `YYYY-MM-DD` (required) + to (str): 取得する統計の区間の終了日 - `YYYY-MM-DD` 。この日は含まれます。 (required) + + Returns: + Tuple[List[ProjectTaskStatisticsHistory], requests.Response] + + + """ + url_path = f"/projects/{project_id}/statistics/tasks/daily" + http_method = "GET" + keyword_params: Dict[str, Any] = { + "query_params": query_params, + } + return self._request_wrapper(http_method, url_path, **keyword_params) + + def get_task_phase_statistics(self, project_id: str, **kwargs) -> Tuple[Any, requests.Response]: + """フェーズ別タスク集計ファイルへのURL取得 https://annofab.com/docs/api/#operation/getTaskPhaseStatistics + .. deprecated:: X authorizations: AllProjectMember @@ -2480,15 +2605,17 @@ def get_task_phase_statistics(self, project_id: str, **kwargs) -> Tuple[Any, req """ + warnings.warn("deprecated", FutureWarning) url_path = f"/projects/{project_id}/statistics/task-phases" http_method = "GET" keyword_params: Dict[str, Any] = {} return self._request_wrapper(http_method, url_path, **keyword_params) def get_task_statistics(self, project_id: str, **kwargs) -> Tuple[Any, requests.Response]: - """タスク集計取得 + """タスク集計ファイルへのURL取得 https://annofab.com/docs/api/#operation/getTaskStatistics + .. deprecated:: X authorizations: AllProjectMember @@ -2503,15 +2630,78 @@ def get_task_statistics(self, project_id: str, **kwargs) -> Tuple[Any, requests. """ + warnings.warn("deprecated", FutureWarning) url_path = f"/projects/{project_id}/statistics/tasks" http_method = "GET" keyword_params: Dict[str, Any] = {} return self._request_wrapper(http_method, url_path, **keyword_params) + def get_worktime_daily_statistics( + self, project_id: str, query_params: Optional[Dict[str, Any]] = None, **kwargs + ) -> Tuple[Any, requests.Response]: + """プロジェクト単位のフェーズ別タスク集計取得 + https://annofab.com/docs/api/#operation/getWorktimeDailyStatistics + + + authorizations: AllProjectMember + + + 指定したプロジェクトのタスク作業時間集計データを指定した期間分取得できるAPI。取得期間は最大3か月です。 + + Args: + project_id (str): プロジェクトID (required) + query_params (Dict[str, Any]): Query Parameters + _from (str): 取得する統計の区間の開始日 - `YYYY-MM-DD` (required) + to (str): 取得する統計の区間の終了日 - `YYYY-MM-DD` 。この日は含まれます。 (required) + + Returns: + Tuple[WorktimeStatisticsByProject, requests.Response] + + + """ + url_path = f"/projects/{project_id}/statistics/worktimes/daily" + http_method = "GET" + keyword_params: Dict[str, Any] = { + "query_params": query_params, + } + return self._request_wrapper(http_method, url_path, **keyword_params) + + def get_worktime_daily_statistics_by_account( + self, project_id: str, account_id: str, query_params: Optional[Dict[str, Any]] = None, **kwargs + ) -> Tuple[Any, requests.Response]: + """プロジェクトメンバー単位のフェーズ別タスク集計取得 + https://annofab.com/docs/api/#operation/getWorktimeDailyStatisticsByAccount + + + authorizations: AllProjectMember + + + 指定したプロジェクトメンバーのタスク作業時間集計データを指定した期間分取得できるAPI。取得期間は最大3か月です。 + + Args: + project_id (str): プロジェクトID (required) + account_id (str): アカウントID (required) + query_params (Dict[str, Any]): Query Parameters + _from (str): 取得する統計の区間の開始日 - `YYYY-MM-DD` (required) + to (str): 取得する統計の区間の終了日 - `YYYY-MM-DD` 。この日は含まれます。 (required) + + Returns: + Tuple[WorktimeStatisticsByAccount, requests.Response] + + + """ + url_path = f"/projects/{project_id}/statistics/worktimes-by-account/{account_id}/daily" + http_method = "GET" + keyword_params: Dict[str, Any] = { + "query_params": query_params, + } + return self._request_wrapper(http_method, url_path, **keyword_params) + def get_worktime_statistics(self, project_id: str, **kwargs) -> Tuple[Any, requests.Response]: - """タスク作業時間集計取得 + """タスク作業時間集計ファイルへのURL取得 https://annofab.com/docs/api/#operation/getWorktimeStatistics + .. deprecated:: X authorizations: AllProjectMember @@ -2526,6 +2716,7 @@ def get_worktime_statistics(self, project_id: str, **kwargs) -> Tuple[Any, reque """ + warnings.warn("deprecated", FutureWarning) url_path = f"/projects/{project_id}/statistics/worktimes" http_method = "GET" keyword_params: Dict[str, Any] = {} diff --git a/annofabapi/models.py b/annofabapi/models.py index 98d15a40..bdbb8a57 100644 --- a/annofabapi/models.py +++ b/annofabapi/models.py @@ -4678,6 +4678,51 @@ class WebhookStatus(Enum): """ +WorktimeStatisticsByAccount = Dict[str, Any] +""" + + +Kyes of Dict + +* project_id: str + プロジェクトID。[値の制約についてはこちら。](#section/API-Convention/APIID) +* account_id: str + +* data_series: List[WorktimeStatisticsData] + プロジェクトメンバーの日毎の作業時間統計データ + +""" + +WorktimeStatisticsByProject = Dict[str, Any] +""" + + +Kyes of Dict + +* project_id: str + プロジェクトID。[値の制約についてはこちら。](#section/API-Convention/APIID) +* data_series: List[WorktimeStatisticsData] + プロジェクトの日毎の作業時間統計データ + +""" + +WorktimeStatisticsData = Dict[str, Any] +""" + + +Kyes of Dict + +* date: str + +* grouped_by_input: List[WorktimeStatisticsItem] + ユーザごとの画像1個当たりの作業時間情報(動画プロジェクトの場合は空リスト) +* grouped_by_task: List[WorktimeStatisticsItem] + ユーザごとのタスク1個当たりの作業時間情報(動画プロジェクトの場合は空リスト) +* grouped_by_minute: List[WorktimeStatisticsItem] + ユーザごとの動画1分当たりの作業時間情報(画像プロジェクトの場合は空リスト) + +""" + WorktimeStatisticsItem = Dict[str, Any] """ From 40f2270b31e6817bacd7bac5a7a434d8e0a0961b Mon Sep 17 00:00:00 2001 From: yuji38kwmt Date: Wed, 20 Oct 2021 17:14:51 +0900 Subject: [PATCH 03/12] update --- annofabapi/__version__.py | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/annofabapi/__version__.py b/annofabapi/__version__.py index 9181f432..d4ace94d 100644 --- a/annofabapi/__version__.py +++ b/annofabapi/__version__.py @@ -1 +1 @@ -__version__ = "0.48.2" +__version__ = "0.49.0" diff --git a/pyproject.toml b/pyproject.toml index d66fac92..fc1630fc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "annofabapi" -version = "0.48.2" +version = "0.49.0" description = "Python Clinet Library of AnnoFab WebAPI (https://annofab.com/docs/api/)" authors = ["yuji38kwmt"] license = "MIT" From f05bc748f4a519d5cb696a97e5d93b9509bb1cec Mon Sep 17 00:00:00 2001 From: yuji38kwmt Date: Wed, 20 Oct 2021 17:50:57 +0900 Subject: [PATCH 04/12] =?UTF-8?q?=E5=BB=83=E6=AD=A2=E4=BA=88=E5=AE=9A?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- annofabapi/wrapper.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/annofabapi/wrapper.py b/annofabapi/wrapper.py index a3d6353d..179208ac 100644 --- a/annofabapi/wrapper.py +++ b/annofabapi/wrapper.py @@ -998,6 +998,8 @@ def get_task_statistics(self, project_id: str) -> List[Any]: """ getTaskStatistics APIのLocation headerの中身を返す。 + .. deprecated:: 2022-1-25以降 + Args: project_id: プロジェクトID @@ -1005,6 +1007,7 @@ def get_task_statistics(self, project_id: str) -> List[Any]: """ + warnings.warn("deprecated", FutureWarning) _, response = self.api.get_task_statistics(project_id) result = self._request_location_header_url(response) if result is not None: @@ -1016,12 +1019,15 @@ def get_account_statistics(self, project_id: str) -> List[Any]: """ getAccountStatistics APIのLocation headerの中身を返す。 + .. deprecated:: 2022-1-25以降 + Args: project_id: Returns: """ + warnings.warn("deprecated", FutureWarning) _, response = self.api.get_account_statistics(project_id) result = self._request_location_header_url(response) if result is not None: @@ -1033,12 +1039,15 @@ def get_inspection_statistics(self, project_id: str) -> List[Any]: """ getInspectionStatistics APIのLocation headerの中身を返す。 + .. deprecated:: 2022-1-25以降 + Args: project_id: Returns: """ + warnings.warn("deprecated", FutureWarning) _, response = self.api.get_inspection_statistics(project_id) result = self._request_location_header_url(response) if result is not None: @@ -1050,12 +1059,15 @@ def get_task_phase_statistics(self, project_id: str) -> List[Any]: """ getTaskPhaseStatistics APIのLocation headerの中身を返す。 + .. deprecated:: 2022-1-25以降 + Args: project_id: Returns: """ + warnings.warn("deprecated", FutureWarning) _, response = self.api.get_task_phase_statistics(project_id) result = self._request_location_header_url(response) if result is not None: @@ -1085,6 +1097,8 @@ def get_worktime_statistics(self, project_id: str) -> List[Any]: タスク作業時間集計取得. Location Headerに記載されたURLのレスポンスをJSON形式で返す。 + .. deprecated:: 2022-1-25以降 + Args: project_id: プロジェクトID @@ -1092,6 +1106,7 @@ def get_worktime_statistics(self, project_id: str) -> List[Any]: タスク作業時間集計 """ + warnings.warn("deprecated", FutureWarning) _, response = self.api.get_worktime_statistics(project_id) result = self._request_location_header_url(response) if result is not None: From cdd5dcff7c1e2d1e7d005f66e6175dd684c27139 Mon Sep 17 00:00:00 2001 From: yuji38kwmt Date: Fri, 22 Oct 2021 10:11:09 +0900 Subject: [PATCH 05/12] add wrapper --- annofabapi/wrapper.py | 73 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 71 insertions(+), 2 deletions(-) diff --git a/annofabapi/wrapper.py b/annofabapi/wrapper.py index 179208ac..bbc03a4c 100644 --- a/annofabapi/wrapper.py +++ b/annofabapi/wrapper.py @@ -2,6 +2,7 @@ import asyncio import copy import datetime +import functools import hashlib import logging import mimetypes @@ -12,9 +13,11 @@ import warnings from dataclasses import dataclass from pathlib import Path -from typing import Any, Callable, Dict, List, Optional +from typing import Any, Callable, Dict, List, Optional, Tuple import requests +from dateutil.relativedelta import relativedelta +from requests import Response from annofabapi import AnnofabApi from annofabapi.exceptions import AnnofabApiException, CheckSumError @@ -1098,7 +1101,7 @@ def get_worktime_statistics(self, project_id: str) -> List[Any]: Location Headerに記載されたURLのレスポンスをJSON形式で返す。 .. deprecated:: 2022-1-25以降 - + Args: project_id: プロジェクトID @@ -1114,6 +1117,72 @@ def get_worktime_statistics(self, project_id: str) -> List[Any]: else: return [] + def _get_statistics_daily_xxx( + self, + function: Callable[[Dict[str, Any]], Tuple[List[Dict[str, Any]], Response]], + dt_from_date: datetime.date, + dt_to_date: datetime.date, + ) -> List[Dict[str, Any]]: + """statistics daily apiの結果を、3ヶ月ごと(webapiの制約の都合)に再帰的に取得する。 + + Args: + function (Callable): 実行する関数 + dt_from_date: 取得する期間の開始日 + dt_to_date: 取得する期間の終了日 + + Returns: + + """ + print(f"{dt_from_date=}, {dt_to_date=}") + results: List[Dict[str, Any]] = [] + dt_max_to_date = dt_from_date + relativedelta(months=3, days=-1) + dt_tmp_to_date = min(dt_max_to_date, dt_to_date) + + query_params = {"from": str(dt_from_date), "to": str(dt_tmp_to_date)} + tmp_result: List[Dict[str, Any]] = function(query_params)[0] + results.extend(tmp_result) + + dt_tmp_from_date = dt_tmp_to_date + datetime.timedelta(days=1) + + if dt_tmp_from_date <= dt_to_date: + tmp_result = self._get_statistics_daily_xxx(function, dt_from_date=dt_tmp_from_date, dt_to_date=dt_to_date) + results.extend(tmp_result) + + return results + + def _get_from_and_to_date_for_statistics_webapi( + self, project_id: str, from_date: Optional[str], to_date: Optional[str] + ) -> Tuple[datetime.date, datetime.date]: + """statistics webapi用に、from_date, to_dateを取得する。 + + Args: + project_id (str): プロジェクトID。プロジェクト作成日を取得する際に参照します。 + from_date (Optional[str]): 取得する統計の区間の開始日(YYYY-MM-DD)。Noneの場合は、プロジェクト作成日を開始日とみなします。 + to_date (Optional[str]): 取得する統計の区間の終了日(YYYY-MM-DD)。Noneの場合は、今日の日付を終了日とみなします。 + + Returns: + Tuple[datetime.date, datetime.date]: [description] + """ + if from_date is None: + project, _ = self.api.get_project(project_id) + from_date = project["created_datetime"][0:10] # "YYYY-MM-DD"の部分を抽出 + if to_date is None: + to_date = str(datetime.datetime.today().date()) + + DATE_FORMAT = "%Y-%m-%d" + dt_from_date = datetime.datetime.strptime(from_date, DATE_FORMAT).date() + dt_to_date = datetime.datetime.strptime(to_date, DATE_FORMAT).date() + return dt_from_date, dt_to_date + + def get_account_daily_statistics( + self, project_id: str, *, from_date: Optional[str] = None, to_date: Optional[str] = None + ) -> List[Dict[str, Any]]: + dt_from_date, dt_to_date = self._get_from_and_to_date_for_statistics_webapi( + project_id, from_date=from_date, to_date=to_date + ) + func = functools.partial(self.api.get_account_daily_statistics, project_id) + return self._get_statistics_daily_xxx(func, dt_from_date=dt_from_date, dt_to_date=dt_to_date) + ######################################### # Public Method : Supplementary ######################################### From 308ae3623374740b1f6ded4ff772c11c4a0c4364 Mon Sep 17 00:00:00 2001 From: yuji38kwmt Date: Fri, 22 Oct 2021 11:30:38 +0900 Subject: [PATCH 06/12] add --- annofabapi/wrapper.py | 69 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/annofabapi/wrapper.py b/annofabapi/wrapper.py index bbc03a4c..a8b57b01 100644 --- a/annofabapi/wrapper.py +++ b/annofabapi/wrapper.py @@ -1133,7 +1133,6 @@ def _get_statistics_daily_xxx( Returns: """ - print(f"{dt_from_date=}, {dt_to_date=}") results: List[Dict[str, Any]] = [] dt_max_to_date = dt_from_date + relativedelta(months=3, days=-1) dt_tmp_to_date = min(dt_max_to_date, dt_to_date) @@ -1177,12 +1176,80 @@ def _get_from_and_to_date_for_statistics_webapi( def get_account_daily_statistics( self, project_id: str, *, from_date: Optional[str] = None, to_date: Optional[str] = None ) -> List[Dict[str, Any]]: + """指定した期間の ユーザ別タスク集計データ を取得します。 + + Args: + project_id: プロジェクトID + from_date (Optional[str]): 取得する統計の区間の開始日(YYYY-MM-DD)。Noneの場合は、プロジェクト作成日を開始日とみなします。 + to_date (Optional[str]): 取得する統計の区間の終了日(YYYY-MM-DD)。Noneの場合は、今日の日付を終了日とみなします。 + + Returns: + ユーザ別タスク集計データ + """ dt_from_date, dt_to_date = self._get_from_and_to_date_for_statistics_webapi( project_id, from_date=from_date, to_date=to_date ) func = functools.partial(self.api.get_account_daily_statistics, project_id) return self._get_statistics_daily_xxx(func, dt_from_date=dt_from_date, dt_to_date=dt_to_date) + def get_inspection_daily_statistics(self, project_id: str, *, from_date: Optional[str] = None, to_date: Optional[str] = None) -> List[Dict[str, Any]]: + """ + 指定した期間の 検査コメント集計データ を取得します。 + + Args: + project_id: プロジェクトID + from_date (Optional[str]): 取得する統計の区間の開始日(YYYY-MM-DD)。Noneの場合は、プロジェクト作成日を開始日とみなします。 + to_date (Optional[str]): 取得する統計の区間の終了日(YYYY-MM-DD)。Noneの場合は、今日の日付を終了日とみなします。 + + Returns: + 検査コメント集計データ + + """ + + dt_from_date, dt_to_date = self._get_from_and_to_date_for_statistics_webapi( + project_id, from_date=from_date, to_date=to_date + ) + func = functools.partial(self.api.get_inspection_daily_statistics, project_id) + return self._get_statistics_daily_xxx(func, dt_from_date=dt_from_date, dt_to_date=dt_to_date) + + def get_phase_daily_statistics(self, project_id: str, *, from_date: Optional[str] = None, to_date: Optional[str] = None) -> List[Dict[str, Any]]: + """指定した期間の フェーズ別タスク集計データ を取得します。 + + Args: + project_id: プロジェクトID + from_date (Optional[str]): 取得する統計の区間の開始日(YYYY-MM-DD)。Noneの場合は、プロジェクト作成日を開始日とみなします。 + to_date (Optional[str]): 取得する統計の区間の終了日(YYYY-MM-DD)。Noneの場合は、今日の日付を終了日とみなします。 + + Returns: + フェーズ別タスク集計データ + + """ + dt_from_date, dt_to_date = self._get_from_and_to_date_for_statistics_webapi( + project_id, from_date=from_date, to_date=to_date + ) + func = functools.partial(self.api.get_phase_daily_statistics, project_id) + return self._get_statistics_daily_xxx(func, dt_from_date=dt_from_date, dt_to_date=dt_to_date) + + + def get_task_daily_statistics(self, project_id: str, *, from_date: Optional[str] = None, to_date: Optional[str] = None) -> List[Dict[str, Any]]: + """指定した期間の タスク集計データ を取得します。 + + Args: + project_id: プロジェクトID + from_date (Optional[str]): 取得する統計の区間の開始日(YYYY-MM-DD)。Noneの場合は、プロジェクト作成日を開始日とみなします。 + to_date (Optional[str]): 取得する統計の区間の終了日(YYYY-MM-DD)。Noneの場合は、今日の日付を終了日とみなします。 + + Returns: + タスク集計データ + + """ + dt_from_date, dt_to_date = self._get_from_and_to_date_for_statistics_webapi( + project_id, from_date=from_date, to_date=to_date + ) + func = functools.partial(self.api.get_task_daily_statistics, project_id) + return self._get_statistics_daily_xxx(func, dt_from_date=dt_from_date, dt_to_date=dt_to_date) + + ######################################### # Public Method : Supplementary ######################################### From 17c28ad87a288b7af5fc57a15e68f5651c18c75e Mon Sep 17 00:00:00 2001 From: yuji38kwmt Date: Fri, 22 Oct 2021 12:06:49 +0900 Subject: [PATCH 07/12] =?UTF-8?q?decorator=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- annofabapi/wrapper.py | 72 +++++++++++++++++++++++++++++++------- tests/test_api.py | 81 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+), 13 deletions(-) diff --git a/annofabapi/wrapper.py b/annofabapi/wrapper.py index a8b57b01..aaf0b2b3 100644 --- a/annofabapi/wrapper.py +++ b/annofabapi/wrapper.py @@ -11,13 +11,13 @@ import urllib.parse import uuid import warnings +from collections import defaultdict from dataclasses import dataclass from pathlib import Path from typing import Any, Callable, Dict, List, Optional, Tuple import requests from dateutil.relativedelta import relativedelta -from requests import Response from annofabapi import AnnofabApi from annofabapi.exceptions import AnnofabApiException, CheckSumError @@ -1119,7 +1119,7 @@ def get_worktime_statistics(self, project_id: str) -> List[Any]: def _get_statistics_daily_xxx( self, - function: Callable[[Dict[str, Any]], Tuple[List[Dict[str, Any]], Response]], + function: Callable[[Dict[str, Any]], List[Dict[str, Any]]], dt_from_date: datetime.date, dt_to_date: datetime.date, ) -> List[Dict[str, Any]]: @@ -1134,11 +1134,12 @@ def _get_statistics_daily_xxx( """ results: List[Dict[str, Any]] = [] + # 取得期間が最大3ヶ月になるようにする dt_max_to_date = dt_from_date + relativedelta(months=3, days=-1) dt_tmp_to_date = min(dt_max_to_date, dt_to_date) query_params = {"from": str(dt_from_date), "to": str(dt_tmp_to_date)} - tmp_result: List[Dict[str, Any]] = function(query_params)[0] + tmp_result: List[Dict[str, Any]] = function(query_params) results.extend(tmp_result) dt_tmp_from_date = dt_tmp_to_date + datetime.timedelta(days=1) @@ -1186,13 +1187,30 @@ def get_account_daily_statistics( Returns: ユーザ別タスク集計データ """ + + def decorator(f, project_id: str): + @functools.wraps(f) + def wrapper(*args, **kwargs): + content, _ = f(project_id, *args, **kwargs) + return content + + return wrapper + dt_from_date, dt_to_date = self._get_from_and_to_date_for_statistics_webapi( project_id, from_date=from_date, to_date=to_date ) - func = functools.partial(self.api.get_account_daily_statistics, project_id) - return self._get_statistics_daily_xxx(func, dt_from_date=dt_from_date, dt_to_date=dt_to_date) + func = decorator(self.api.get_account_daily_statistics, project_id) + result = self._get_statistics_daily_xxx(func, dt_from_date=dt_from_date, dt_to_date=dt_to_date) + + tmp_dict_results = defaultdict(list) + for elm in result: + tmp_dict_results[elm["account_id"]].extend(elm["histories"]) + + return [{"account_id": k, "histories": v} for k, v in tmp_dict_results.items()] - def get_inspection_daily_statistics(self, project_id: str, *, from_date: Optional[str] = None, to_date: Optional[str] = None) -> List[Dict[str, Any]]: + def get_inspection_daily_statistics( + self, project_id: str, *, from_date: Optional[str] = None, to_date: Optional[str] = None + ) -> List[Dict[str, Any]]: """ 指定した期間の 検査コメント集計データ を取得します。 @@ -1206,13 +1224,23 @@ def get_inspection_daily_statistics(self, project_id: str, *, from_date: Optiona """ + def decorator(f, project_id: str): + @functools.wraps(f) + def wrapper(*args, **kwargs): + content, _ = f(project_id, *args, **kwargs) + return content + + return wrapper + dt_from_date, dt_to_date = self._get_from_and_to_date_for_statistics_webapi( project_id, from_date=from_date, to_date=to_date ) - func = functools.partial(self.api.get_inspection_daily_statistics, project_id) + func = decorator(self.api.get_inspection_daily_statistics, project_id) return self._get_statistics_daily_xxx(func, dt_from_date=dt_from_date, dt_to_date=dt_to_date) - def get_phase_daily_statistics(self, project_id: str, *, from_date: Optional[str] = None, to_date: Optional[str] = None) -> List[Dict[str, Any]]: + def get_phase_daily_statistics( + self, project_id: str, *, from_date: Optional[str] = None, to_date: Optional[str] = None + ) -> List[Dict[str, Any]]: """指定した期間の フェーズ別タスク集計データ を取得します。 Args: @@ -1224,14 +1252,24 @@ def get_phase_daily_statistics(self, project_id: str, *, from_date: Optional[str フェーズ別タスク集計データ """ + + def decorator(f, project_id: str): + @functools.wraps(f) + def wrapper(*args, **kwargs): + content, _ = f(project_id, *args, **kwargs) + return content + + return wrapper + dt_from_date, dt_to_date = self._get_from_and_to_date_for_statistics_webapi( project_id, from_date=from_date, to_date=to_date ) - func = functools.partial(self.api.get_phase_daily_statistics, project_id) + func = decorator(self.api.get_phase_daily_statistics, project_id) return self._get_statistics_daily_xxx(func, dt_from_date=dt_from_date, dt_to_date=dt_to_date) - - def get_task_daily_statistics(self, project_id: str, *, from_date: Optional[str] = None, to_date: Optional[str] = None) -> List[Dict[str, Any]]: + def get_task_daily_statistics( + self, project_id: str, *, from_date: Optional[str] = None, to_date: Optional[str] = None + ) -> List[Dict[str, Any]]: """指定した期間の タスク集計データ を取得します。 Args: @@ -1243,13 +1281,21 @@ def get_task_daily_statistics(self, project_id: str, *, from_date: Optional[str] タスク集計データ """ + + def decorator(f, project_id: str): + @functools.wraps(f) + def wrapper(*args, **kwargs): + content, _ = f(project_id, *args, **kwargs) + return content + + return wrapper + dt_from_date, dt_to_date = self._get_from_and_to_date_for_statistics_webapi( project_id, from_date=from_date, to_date=to_date ) - func = functools.partial(self.api.get_task_daily_statistics, project_id) + func = decorator(self.api.get_task_daily_statistics, project_id) return self._get_statistics_daily_xxx(func, dt_from_date=dt_from_date, dt_to_date=dt_to_date) - ######################################### # Public Method : Supplementary ######################################### diff --git a/tests/test_api.py b/tests/test_api.py index f6b81c8d..986278ab 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -403,6 +403,87 @@ def test_wrapper_get_all_project_members(self): class TestStatistics: + def test_get_account_daily_statistics(self): + actual, _ = api.get_account_daily_statistics( + project_id, query_params={"from": "2021-09-01", "to": "2021-09-30"} + ) + assert type(actual) == list + + def test_get_inspection_daily_statistics(self): + actual, _ = api.get_inspection_daily_statistics( + project_id, query_params={"from": "2021-09-01", "to": "2021-09-30"} + ) + assert type(actual) == list + + def test_get_phase_daily_statistics(self): + actual, _ = api.get_phase_daily_statistics(project_id, query_params={"from": "2021-09-01", "to": "2021-09-30"}) + assert type(actual) == list + + def test_get_task_daily_statistics(self): + actual, _ = api.get_task_daily_statistics(project_id, query_params={"from": "2021-09-01", "to": "2021-09-30"}) + assert type(actual) == list + + def test_get_worktime_daily_statistics_by_account(self): + actual, _ = api.get_worktime_daily_statistics_by_account( + project_id, api.account_id, query_params={"from": "2021-09-01", "to": "2021-09-30"} + ) + assert type(actual) == dict + + def test_get_worktime_daily_statistics(self): + actual, _ = api.get_worktime_daily_statistics( + project_id, query_params={"from": "2021-09-01", "to": "2021-09-30"} + ) + print(actual) + assert type(actual) == dict + + def test_wrapper_get_account_daily_statistics(self): + actual = wrapper.get_account_daily_statistics(project_id, from_date="2021-04-01", to_date="2021-06-30") + assert type(actual) == list + + # 最大取得期間の3ヶ月を超えている場合 + actual = wrapper.get_account_daily_statistics(project_id, from_date="2021-04-01", to_date="2021-07-01") + assert type(actual) == list + + # 開始日と終了日を指定しない場合 + actual = wrapper.get_account_daily_statistics(project_id) + assert type(actual) == list + + def test_wrapper_get_inspection_daily_statistics(self): + actual = wrapper.get_inspection_daily_statistics(project_id, from_date="2021-04-01", to_date="2021-06-30") + assert type(actual) == list + + # 最大取得期間の3ヶ月を超えている場合 + actual = wrapper.get_inspection_daily_statistics(project_id, from_date="2021-04-01", to_date="2021-07-01") + assert type(actual) == list + + # 開始日と終了日を指定しない場合 + actual = wrapper.get_inspection_daily_statistics(project_id) + assert type(actual) == list + + def test_wrapper_get_phase_daily_statistics(self): + actual = wrapper.get_phase_daily_statistics(project_id, from_date="2021-04-01", to_date="2021-06-30") + assert type(actual) == list + + # 最大取得期間の3ヶ月を超えている場合 + actual = wrapper.get_phase_daily_statistics(project_id, from_date="2021-04-01", to_date="2021-07-01") + assert type(actual) == list + + # 開始日と終了日を指定しない場合 + actual = wrapper.get_phase_daily_statistics(project_id) + assert type(actual) == list + + def test_wrapper_get_task_daily_statistics(self): + actual = wrapper.get_task_daily_statistics(project_id, from_date="2021-04-01", to_date="2021-06-30") + assert type(actual) == list + + # 最大取得期間の3ヶ月を超えている場合 + actual = wrapper.get_task_daily_statistics(project_id, from_date="2021-04-01", to_date="2021-07-01") + assert type(actual) == list + + # 開始日と終了日を指定しない場合 + actual = wrapper.get_task_daily_statistics(project_id) + assert type(actual) == list + def test_wrapper_statistics(self): actual = wrapper.get_task_statistics(project_id) assert type(actual) == list From 24bc3dc1923793121816da663e50409ee5c4241a Mon Sep 17 00:00:00 2001 From: yuji38kwmt Date: Fri, 22 Oct 2021 14:13:14 +0900 Subject: [PATCH 08/12] update test --- annofabapi/wrapper.py | 59 +++++++++++++++++++++++++++++++++++++++++++ tests/test_api.py | 25 ++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/annofabapi/wrapper.py b/annofabapi/wrapper.py index aaf0b2b3..4b176330 100644 --- a/annofabapi/wrapper.py +++ b/annofabapi/wrapper.py @@ -1296,6 +1296,65 @@ def wrapper(*args, **kwargs): func = decorator(self.api.get_task_daily_statistics, project_id) return self._get_statistics_daily_xxx(func, dt_from_date=dt_from_date, dt_to_date=dt_to_date) + def get_worktime_daily_statistics( + self, project_id: str, *, from_date: Optional[str] = None, to_date: Optional[str] = None + ) -> Dict[str, Any]: + """プロジェクト全体のタスク作業時間集計データを取得します。 + + Args: + project_id: プロジェクトID + from_date (Optional[str]): 取得する統計の区間の開始日(YYYY-MM-DD)。Noneの場合は、プロジェクト作成日を開始日とみなします。 + to_date (Optional[str]): 取得する統計の区間の終了日(YYYY-MM-DD)。Noneの場合は、今日の日付を終了日とみなします。 + + Returns: + Dict[str, Any]: [description] + """ + + def decorator(f, project_id: str): + @functools.wraps(f) + def wrapper(*args, **kwargs): + content, _ = f(project_id, *args, **kwargs) + return content["data_series"] + + return wrapper + + dt_from_date, dt_to_date = self._get_from_and_to_date_for_statistics_webapi( + project_id, from_date=from_date, to_date=to_date + ) + func = decorator(self.api.get_worktime_daily_statistics, project_id) + result = self._get_statistics_daily_xxx(func, dt_from_date=dt_from_date, dt_to_date=dt_to_date) + return {"project_id": project_id, "data_series": result} + + def get_worktime_daily_statistics_by_account( + self, project_id: str, account_id: str, *, from_date: Optional[str] = None, to_date: Optional[str] = None + ) -> Dict[str, Any]: + """指定したプロジェクトメンバーのタスク作業時間集計データを取得します。 + + Args: + project_id: プロジェクトID + account_id: アカウントID + from_date (Optional[str]): 取得する統計の区間の開始日(YYYY-MM-DD)。Noneの場合は、プロジェクト作成日を開始日とみなします。 + to_date (Optional[str]): 取得する統計の区間の終了日(YYYY-MM-DD)。Noneの場合は、今日の日付を終了日とみなします。 + + Returns: + Dict[str, Any]: [description] + """ + + def decorator(f, project_id: str, account_id: str): + @functools.wraps(f) + def wrapper(*args, **kwargs): + content, _ = f(project_id, account_id, *args, **kwargs) + return content["data_series"] + + return wrapper + + dt_from_date, dt_to_date = self._get_from_and_to_date_for_statistics_webapi( + project_id, from_date=from_date, to_date=to_date + ) + func = decorator(self.api.get_worktime_daily_statistics_by_account, project_id, account_id) + result = self._get_statistics_daily_xxx(func, dt_from_date=dt_from_date, dt_to_date=dt_to_date) + return {"project_id": project_id, "account_id": account_id, "data_series": result} + ######################################### # Public Method : Supplementary ######################################### diff --git a/tests/test_api.py b/tests/test_api.py index 986278ab..eeacb14b 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -484,6 +484,31 @@ def test_wrapper_get_task_daily_statistics(self): actual = wrapper.get_task_daily_statistics(project_id) assert type(actual) == list + def test_wrapper_get_worktime_daily_statistics(self): + actual = wrapper.get_worktime_daily_statistics(project_id, from_date="2021-04-01", to_date="2021-06-30") + assert type(actual) == list + + # 最大取得期間の3ヶ月を超えている場合 + actual = wrapper.get_worktime_daily_statistics(project_id, from_date="2021-04-01", to_date="2021-07-01") + assert type(actual) == list + + # 開始日と終了日を指定しない場合 + actual = wrapper.get_worktime_daily_statistics(project_id) + assert type(actual) == list + + def test_wrapper_get_worktime_daily_statistics_by_account(self): + actual = wrapper.get_worktime_daily_statistics_by_account(project_id, from_date="2021-04-01", to_date="2021-06-30") + assert type(actual) == list + + # 最大取得期間の3ヶ月を超えている場合 + actual = wrapper.get_worktime_daily_statistics_by_account(project_id, from_date="2021-04-01", to_date="2021-07-01") + assert type(actual) == list + + # 開始日と終了日を指定しない場合 + actual = wrapper.get_worktime_daily_statistics_by_account(project_id) + assert type(actual) == list + + def test_wrapper_statistics(self): actual = wrapper.get_task_statistics(project_id) assert type(actual) == list From 3b9328e82ee5a3774cd665f1315bec45cd7616f1 Mon Sep 17 00:00:00 2001 From: yuji38kwmt Date: Fri, 22 Oct 2021 14:20:24 +0900 Subject: [PATCH 09/12] =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=81=AA=E3=83=86?= =?UTF-8?q?=E3=82=B9=E3=83=88=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89=E3=81=AE?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_api.py | 66 +++++------------------------------------------ 1 file changed, 6 insertions(+), 60 deletions(-) diff --git a/tests/test_api.py b/tests/test_api.py index eeacb14b..3adec431 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -403,39 +403,6 @@ def test_wrapper_get_all_project_members(self): class TestStatistics: - def test_get_account_daily_statistics(self): - actual, _ = api.get_account_daily_statistics( - project_id, query_params={"from": "2021-09-01", "to": "2021-09-30"} - ) - assert type(actual) == list - - def test_get_inspection_daily_statistics(self): - actual, _ = api.get_inspection_daily_statistics( - project_id, query_params={"from": "2021-09-01", "to": "2021-09-30"} - ) - assert type(actual) == list - - def test_get_phase_daily_statistics(self): - actual, _ = api.get_phase_daily_statistics(project_id, query_params={"from": "2021-09-01", "to": "2021-09-30"}) - assert type(actual) == list - - def test_get_task_daily_statistics(self): - actual, _ = api.get_task_daily_statistics(project_id, query_params={"from": "2021-09-01", "to": "2021-09-30"}) - assert type(actual) == list - - def test_get_worktime_daily_statistics_by_account(self): - actual, _ = api.get_worktime_daily_statistics_by_account( - project_id, api.account_id, query_params={"from": "2021-09-01", "to": "2021-09-30"} - ) - assert type(actual) == dict - - def test_get_worktime_daily_statistics(self): - actual, _ = api.get_worktime_daily_statistics( - project_id, query_params={"from": "2021-09-01", "to": "2021-09-30"} - ) - print(actual) - assert type(actual) == dict - def test_wrapper_get_account_daily_statistics(self): actual = wrapper.get_account_daily_statistics(project_id, from_date="2021-04-01", to_date="2021-06-30") assert type(actual) == list @@ -486,53 +453,32 @@ def test_wrapper_get_task_daily_statistics(self): def test_wrapper_get_worktime_daily_statistics(self): actual = wrapper.get_worktime_daily_statistics(project_id, from_date="2021-04-01", to_date="2021-06-30") - assert type(actual) == list + assert type(actual) == dict # 最大取得期間の3ヶ月を超えている場合 actual = wrapper.get_worktime_daily_statistics(project_id, from_date="2021-04-01", to_date="2021-07-01") - assert type(actual) == list + assert type(actual) == dict # 開始日と終了日を指定しない場合 actual = wrapper.get_worktime_daily_statistics(project_id) - assert type(actual) == list + assert type(actual) == dict def test_wrapper_get_worktime_daily_statistics_by_account(self): actual = wrapper.get_worktime_daily_statistics_by_account(project_id, from_date="2021-04-01", to_date="2021-06-30") - assert type(actual) == list + assert type(actual) == dict # 最大取得期間の3ヶ月を超えている場合 actual = wrapper.get_worktime_daily_statistics_by_account(project_id, from_date="2021-04-01", to_date="2021-07-01") - assert type(actual) == list + assert type(actual) == dict # 開始日と終了日を指定しない場合 actual = wrapper.get_worktime_daily_statistics_by_account(project_id) - assert type(actual) == list - - - def test_wrapper_statistics(self): - actual = wrapper.get_task_statistics(project_id) - assert type(actual) == list - - def test_wrapper_get_account_statistics(self): - actual = wrapper.get_account_statistics(project_id) - assert type(actual) == list - - def test_wrapper_get_inspection_statistics(self): - actual = wrapper.get_inspection_statistics(project_id) - assert type(actual) == list - - def test_wrapper_get_task_phase_statistics(self): - actual = wrapper.get_task_phase_statistics(project_id) - assert type(actual) == list + assert type(actual) == dict def test_wrapper_get_label_statistics(self): actual = wrapper.get_label_statistics(project_id) assert type(actual) == list - def test_wrapper_get_worktime_statistics(self): - actual = wrapper.get_worktime_statistics(project_id) - assert type(actual) == list - def test_graph_marker(self): print("get_markers") content, _ = api.get_markers(project_id) From ea4941744c84aed309c72c043e83c9b87009f261 Mon Sep 17 00:00:00 2001 From: yuji38kwmt Date: Fri, 22 Oct 2021 14:23:27 +0900 Subject: [PATCH 10/12] update docstring --- annofabapi/wrapper.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/annofabapi/wrapper.py b/annofabapi/wrapper.py index 4b176330..b181d6c4 100644 --- a/annofabapi/wrapper.py +++ b/annofabapi/wrapper.py @@ -1307,7 +1307,7 @@ def get_worktime_daily_statistics( to_date (Optional[str]): 取得する統計の区間の終了日(YYYY-MM-DD)。Noneの場合は、今日の日付を終了日とみなします。 Returns: - Dict[str, Any]: [description] + プロジェクト全体のタスク作業時間集計データ """ def decorator(f, project_id: str): @@ -1337,7 +1337,7 @@ def get_worktime_daily_statistics_by_account( to_date (Optional[str]): 取得する統計の区間の終了日(YYYY-MM-DD)。Noneの場合は、今日の日付を終了日とみなします。 Returns: - Dict[str, Any]: [description] + プロジェクトメンバーのタスク作業時間集計データ """ def decorator(f, project_id: str, account_id: str): From 643e87238cd8c77103375c11831ee28105cc66e8 Mon Sep 17 00:00:00 2001 From: yuji38kwmt Date: Fri, 5 Nov 2021 23:04:44 +0900 Subject: [PATCH 11/12] update test --- tests/test_api.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_api.py b/tests/test_api.py index dffdf5db..f420a9c3 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -464,15 +464,15 @@ def test_wrapper_get_worktime_daily_statistics(self): assert type(actual) == dict def test_wrapper_get_worktime_daily_statistics_by_account(self): - actual = wrapper.get_worktime_daily_statistics_by_account(project_id, from_date="2021-04-01", to_date="2021-06-30") + actual = wrapper.get_worktime_daily_statistics_by_account(project_id, account_id=api.account_id, from_date="2021-04-01", to_date="2021-06-30") assert type(actual) == dict # 最大取得期間の3ヶ月を超えている場合 - actual = wrapper.get_worktime_daily_statistics_by_account(project_id, from_date="2021-04-01", to_date="2021-07-01") + actual = wrapper.get_worktime_daily_statistics_by_account(project_id, account_id=api.account_id, from_date="2021-04-01", to_date="2021-07-01") assert type(actual) == dict # 開始日と終了日を指定しない場合 - actual = wrapper.get_worktime_daily_statistics_by_account(project_id) + actual = wrapper.get_worktime_daily_statistics_by_account(project_id, account_id=api.account_id, ) assert type(actual) == dict def test_wrapper_get_label_statistics(self): From 707d4b760be5a004ba6c9cd139afd85a5de91c52 Mon Sep 17 00:00:00 2001 From: yuji38kwmt Date: Fri, 5 Nov 2021 23:07:02 +0900 Subject: [PATCH 12/12] version up --- annofabapi/__version__.py | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/annofabapi/__version__.py b/annofabapi/__version__.py index d4ace94d..3a7c7a2f 100644 --- a/annofabapi/__version__.py +++ b/annofabapi/__version__.py @@ -1 +1 @@ -__version__ = "0.49.0" +__version__ = "0.50.0" diff --git a/pyproject.toml b/pyproject.toml index fc1630fc..2679a1a7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "annofabapi" -version = "0.49.0" +version = "0.50.0" description = "Python Clinet Library of AnnoFab WebAPI (https://annofab.com/docs/api/)" authors = ["yuji38kwmt"] license = "MIT"