Skip to content

Commit 2cd347e

Browse files
authored
Annofab v0.93.0 対応 (#187)
* [wrapper.py statistics] Locationヘッダから取得するようにする * versionup * update swagger * update test code * update test code
1 parent 666746f commit 2cd347e

File tree

7 files changed

+178
-26
lines changed

7 files changed

+178
-26
lines changed

annofabapi/__version__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.37.0"
1+
__version__ = "0.38.0"

annofabapi/wrapper.py

+87-6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
from dataclasses import dataclass
1111
from typing import Any, Callable, Dict, List, Optional
1212

13+
import requests
14+
1315
from annofabapi import AnnofabApi
1416
from annofabapi.exceptions import AnnofabApiException
1517
from annofabapi.models import (
@@ -623,19 +625,17 @@ def put_input_data_from_file(
623625
#########################################
624626
# Public Method : Statistics
625627
#########################################
626-
def get_worktime_statistics(self, project_id: str) -> List[Any]:
628+
def _request_location_header_url(self, response: requests.Response) -> Any:
627629
"""
628-
タスク作業時間集計取得.
629-
Location Headerに記載されたURLのレスポンスをJSON形式で返す。
630+
Location headerに記載されているURLの中身を返す。
630631
631632
Args:
632-
project_id: プロジェクトID
633+
response:
633634
634635
Returns:
635-
タスク作業時間集計
636+
Location headerに記載されているURLの中身
636637
637638
"""
638-
_, response = self.api.get_worktime_statistics(project_id)
639639
url = response.headers["Location"]
640640

641641
response = self.api.session.get(url)
@@ -646,6 +646,87 @@ def get_worktime_statistics(self, project_id: str) -> List[Any]:
646646
content = self.api._response_to_content(response)
647647
return content
648648

649+
def get_task_statistics(self, project_id: str) -> List[Any]:
650+
"""
651+
getTaskStatistics APIのLocation headerの中身を返す。
652+
653+
Args:
654+
project_id: プロジェクトID
655+
656+
Returns:
657+
658+
659+
"""
660+
_, response = self.api.get_task_statistics(project_id)
661+
return self._request_location_header_url(response)
662+
663+
def get_account_statistics(self, project_id: str) -> List[Any]:
664+
"""
665+
getAccountStatistics APIのLocation headerの中身を返す。
666+
667+
Args:
668+
project_id:
669+
670+
Returns:
671+
672+
"""
673+
_, response = self.api.get_account_statistics(project_id)
674+
return self._request_location_header_url(response)
675+
676+
def get_inspection_statistics(self, project_id: str) -> List[Any]:
677+
"""
678+
getInspectionStatistics APIのLocation headerの中身を返す。
679+
680+
Args:
681+
project_id:
682+
683+
Returns:
684+
685+
"""
686+
_, response = self.api.get_inspection_statistics(project_id)
687+
return self._request_location_header_url(response)
688+
689+
def get_task_phase_statistics(self, project_id: str) -> List[Any]:
690+
"""
691+
getTaskPhaseStatistics APIのLocation headerの中身を返す。
692+
693+
Args:
694+
project_id:
695+
696+
Returns:
697+
698+
"""
699+
_, response = self.api.get_task_phase_statistics(project_id)
700+
return self._request_location_header_url(response)
701+
702+
def get_label_statistics(self, project_id: str) -> List[Any]:
703+
"""
704+
getLabelStatistics APIのLocation headerの中身を返す。
705+
706+
Args:
707+
project_id:
708+
709+
Returns:
710+
711+
"""
712+
_, response = self.api.get_label_statistics(project_id)
713+
return self._request_location_header_url(response)
714+
715+
def get_worktime_statistics(self, project_id: str) -> List[Any]:
716+
"""
717+
タスク作業時間集計取得.
718+
Location Headerに記載されたURLのレスポンスをJSON形式で返す。
719+
720+
Args:
721+
project_id: プロジェクトID
722+
723+
Returns:
724+
タスク作業時間集計
725+
726+
"""
727+
_, response = self.api.get_worktime_statistics(project_id)
728+
return self._request_location_header_url(response)
729+
649730
#########################################
650731
# Public Method : Supplementary
651732
#########################################

generate/swagger/swagger.v2.yaml

+36-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ info:
115115
116116
上記例 `account_id_count` は、タスクのフィールド `account_id` でタスクを分類したところ「`account_id` が `c5eee002` であるタスクが9件、`9f110e48` であるタスクが5件、`b25dfeb3` であるタスクが1件」だったという結果を表しています。
117117
118-
version: 0.91.0
118+
version: 0.93.0
119119
title: AnnoFab Web API
120120
x-logo:
121121
url: "https://annofab.com/images/logo_landscape.png"
@@ -387,6 +387,12 @@ paths:
387387
responses:
388388
"200":
389389
description: 正常
390+
headers:
391+
Location:
392+
description: 認証済み一時URL
393+
required: true
394+
schema:
395+
type: string
390396
content:
391397
application/json:
392398
schema:
@@ -429,6 +435,12 @@ paths:
429435
responses:
430436
"200":
431437
description: 正常
438+
headers:
439+
Location:
440+
description: 認証済み一時URL
441+
required: true
442+
schema:
443+
type: string
432444
content:
433445
application/json:
434446
schema:
@@ -471,6 +483,12 @@ paths:
471483
responses:
472484
"200":
473485
description: 正常
486+
headers:
487+
Location:
488+
description: 認証済み一時URL
489+
required: true
490+
schema:
491+
type: string
474492
content:
475493
application/json:
476494
schema:
@@ -513,6 +531,12 @@ paths:
513531
responses:
514532
"200":
515533
description: 正常
534+
headers:
535+
Location:
536+
description: 認証済み一時URL
537+
required: true
538+
schema:
539+
type: string
516540
content:
517541
application/json:
518542
schema:
@@ -555,6 +579,12 @@ paths:
555579
responses:
556580
"200":
557581
description: 正常
582+
headers:
583+
Location:
584+
description: 認証済み一時URL
585+
required: true
586+
schema:
587+
type: string
558588
content:
559589
application/json:
560590
schema:
@@ -598,6 +628,11 @@ paths:
598628
responses:
599629
"200":
600630
description: 正常
631+
headers:
632+
Location:
633+
description: 認証済み一時URL
634+
schema:
635+
type: string
601636
content:
602637
application/json:
603638
schema:

generate/swagger/swagger.yaml

+31-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ info:
116116
上記例 `account_id_count` は、タスクのフィールド `account_id` でタスクを分類したところ「`account_id` が `c5eee002` であるタスクが9件、`9f110e48` であるタスクが5件、`b25dfeb3` であるタスクが1件」だったという結果を表しています。
117117
また、AggregationResultの集約の件数は、合計で10000件以下に制限されており、それを超える件数がある場合は上位10000件が取得されます。もし、省略された部分を取得したい場合は、検索条件を縛って結果に上る集約の数を減らしてください。
118118
119-
version: 0.91.0
119+
version: 0.93.0
120120
title: AnnoFab Web API
121121
x-logo:
122122
url: "https://annofab.com/images/logo_landscape.png"
@@ -2394,6 +2394,12 @@ paths:
23942394
responses:
23952395
"200":
23962396
description: 正常
2397+
headers:
2398+
Location:
2399+
description: 認証済み一時URL
2400+
required: true
2401+
schema:
2402+
type: string
23972403
content:
23982404
application/json:
23992405
schema:
@@ -2429,6 +2435,12 @@ paths:
24292435
responses:
24302436
"200":
24312437
description: 正常
2438+
headers:
2439+
Location:
2440+
description: 認証済み一時URL
2441+
required: true
2442+
schema:
2443+
type: string
24322444
content:
24332445
application/json:
24342446
schema:
@@ -2461,6 +2473,12 @@ paths:
24612473
responses:
24622474
"200":
24632475
description: 正常
2476+
headers:
2477+
Location:
2478+
description: 認証済み一時URL
2479+
required: true
2480+
schema:
2481+
type: string
24642482
content:
24652483
application/json:
24662484
schema:
@@ -2494,6 +2512,12 @@ paths:
24942512
responses:
24952513
"200":
24962514
description: 正常
2515+
headers:
2516+
Location:
2517+
description: 認証済み一時URL
2518+
required: true
2519+
schema:
2520+
type: string
24972521
content:
24982522
application/json:
24992523
schema:
@@ -2528,6 +2552,12 @@ paths:
25282552
responses:
25292553
"200":
25302554
description: 正常
2555+
headers:
2556+
Location:
2557+
description: 認証済み一時URL
2558+
required: true
2559+
schema:
2560+
type: string
25312561
content:
25322562
application/json:
25332563
schema:

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "annofabapi"
3-
version = "0.37.0"
3+
version = "0.38.0"
44
description = "Python Clinet Library of AnnoFab WebAPI (https://annofab.com/docs/api/)"
55
authors = ["yuji38kwmt <[email protected]>"]
66
maintainers = ["yuji38kwmt <[email protected]>"]

tests/test_api.py

+17-11
Original file line numberDiff line numberDiff line change
@@ -299,23 +299,29 @@ def test_wrapper_copy_project_member(self):
299299

300300

301301
class TestStatistics:
302-
def test_statistics(self):
303-
assert type(api.get_task_statistics(project_id)[0]) == list
302+
def test_wrapper_statistics(self):
303+
actual = wrapper.get_task_statistics(project_id)
304+
assert type(actual) == list
304305

305-
def test_get_account_statistics(self):
306-
assert type(api.get_account_statistics(project_id)[0]) == list
306+
def test_wrapper_get_account_statistics(self):
307+
actual = wrapper.get_account_statistics(project_id)
308+
assert type(actual) == list
307309

308-
def test_get_inspection_statistics(self):
309-
assert type(api.get_inspection_statistics(project_id)[0]) == list
310+
def test_wrapper_get_inspection_statistics(self):
311+
actual = wrapper.get_inspection_statistics(project_id)
312+
assert type(actual) == list
310313

311-
def test_get_task_phase_statistics(self):
312-
assert type(api.get_task_phase_statistics(project_id)[0]) == list
314+
def test_wrapper_get_task_phase_statistics(self):
315+
actual = wrapper.get_task_phase_statistics(project_id)
316+
assert type(actual) == list
313317

314-
def test_get_label_statistics(self):
315-
assert type(api.get_label_statistics(project_id)[0]) == list
318+
def test_wrapper_get_label_statistics(self):
319+
actual = wrapper.get_label_statistics(project_id)
320+
assert type(actual) == list
316321

317322
def test_wrapper_get_worktime_statistics(self):
318-
assert type(wrapper.get_worktime_statistics(project_id)) == list
323+
actual = wrapper.get_worktime_statistics(project_id)
324+
assert type(actual) == list
319325

320326
def test_graph_marker(self):
321327
print("get_markers")

tests/test_dataclass.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -162,27 +162,27 @@ def test_project_member(self):
162162

163163
class TestStatistics:
164164
def test_statistics_get_task_statistics(self):
165-
stat_list, _ = service.api.get_task_statistics(project_id)
165+
stat_list = service.wrapper.get_task_statistics(project_id)
166166
stat = ProjectTaskStatisticsHistory.from_dict(stat_list[0])
167167
assert type(stat) == ProjectTaskStatisticsHistory
168168

169169
def test_statistics_get_account_statistics(self):
170-
stat_list, _ = service.api.get_account_statistics(project_id)
170+
stat_list = service.wrapper.get_account_statistics(project_id)
171171
stat = ProjectAccountStatistics.from_dict(stat_list[0])
172172
assert type(stat) == ProjectAccountStatistics
173173

174174
def test_statistics_get_inspection_statistics(self):
175-
stat_list, _ = service.api.get_inspection_statistics(project_id)
175+
stat_list = service.wrapper.get_inspection_statistics(project_id)
176176
stat = InspectionStatistics.from_dict(stat_list[0])
177177
assert type(stat) == InspectionStatistics
178178

179179
def test_statistics_get_task_phase_statistics(self):
180-
stat_list, _ = service.api.get_task_phase_statistics(project_id)
180+
stat_list = service.wrapper.get_task_phase_statistics(project_id)
181181
stat = TaskPhaseStatistics.from_dict(stat_list[0])
182182
assert type(stat) == TaskPhaseStatistics
183183

184184
def test_statistics_get_label_statistics(self):
185-
stat_list, _ = service.api.get_label_statistics(project_id)
185+
stat_list = service.wrapper.get_label_statistics(project_id)
186186
stat = LabelStatistics.from_dict(stat_list[0])
187187
assert type(stat) == LabelStatistics
188188

0 commit comments

Comments
 (0)