Skip to content

Commit ca3cd91

Browse files
authored
Merge pull request #450 from superannotateai/1027_service_update
1027 service update
2 parents 7f7cab8 + 952aeb3 commit ca3cd91

File tree

8 files changed

+31
-28
lines changed

8 files changed

+31
-28
lines changed

src/superannotate/lib/app/analytics/aggregators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import copy
22
import json
3-
from dataclasses import dataclass
43
from pathlib import Path
54
from typing import List
65
from typing import Optional
76
from typing import Union
87

98
import lib.core as constances
109
import pandas as pd
10+
from dataclasses import dataclass
1111
from lib.app.exceptions import AppException
1212
from lib.core import ATTACHED_VIDEO_ANNOTATION_POSTFIX
1313
from lib.core import PIXEL_ANNOTATION_POSTFIX

src/superannotate/lib/app/interface/sdk_interface.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -684,19 +684,19 @@ def assign_items(
684684
685685
:param project: project name or folder path (e.g., "project1/folder1")
686686
:type project: str
687+
687688
:param items: list of items to assign
688-
:type item_names: list of str
689+
:type items: list of str
690+
689691
:param user: user email
690692
:type user: str
691693
"""
692694

693695
project_name, folder_name = extract_project_folder(project)
694696

695-
response, cnt_assigned = self.controller.assign_items(project_name, folder_name, items, user)
697+
response = self.controller.assign_items(project_name, folder_name, items, user)
696698

697-
if not response.errors:
698-
logger.info(f"Assigned {cnt_assigned}/{len(items)} items to user {user}")
699-
else:
699+
if response.errors:
700700
raise AppException(response.errors)
701701

702702
def unassign_items(
@@ -709,7 +709,7 @@ def unassign_items(
709709
:param project: project name or folder path (e.g., "project1/folder1")
710710
:type project: str
711711
:param items: list of items to unassign
712-
:type item_names: list of str
712+
:type items: list of str
713713
"""
714714
project_name, folder_name = extract_project_folder(project)
715715

@@ -2669,7 +2669,7 @@ def set_annotation_statuses(
26692669
self,
26702670
project: Union[NotEmptyStr, dict],
26712671
annotation_status: AnnotationStatuses,
2672-
item_names: Optional[List[NotEmptyStr]] = None,
2672+
items: Optional[List[NotEmptyStr]] = None,
26732673
):
26742674
"""Sets annotation statuses of items
26752675
@@ -2686,15 +2686,15 @@ def set_annotation_statuses(
26862686
:type annotation_status: str
26872687
26882688
:param items: item names to set the mentioned status for. If None, all the items in the project will be used.
2689-
:type items: str
2689+
:type items: list of strs
26902690
"""
26912691

26922692
project_name, folder_name = extract_project_folder(project)
26932693
response = self.controller.set_annotation_statuses(
26942694
project_name=project_name,
26952695
folder_name=folder_name,
26962696
annotation_status=annotation_status,
2697-
item_names=item_names,
2697+
item_names=items,
26982698
)
26992699
if response.errors:
27002700
raise AppException(response.errors)

src/superannotate/lib/core/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import threading
2+
from typing import Dict
3+
24
from dataclasses import dataclass
35
from dataclasses import field
4-
from typing import Dict
56

67

78
class Session:

src/superannotate/lib/core/service_types.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def __init__(self, response, content_type=None):
8080
"content": response.content,
8181
}
8282
if response.ok:
83-
if content_type:
83+
if content_type and not content_type is not self.__class__:
8484
data["data"] = content_type(**response.json())
8585
else:
8686
data["data"] = response.json()
@@ -92,4 +92,5 @@ def ok(self):
9292

9393
@property
9494
def error(self):
95-
return getattr(self.data, "error", "Unknown error.")
95+
default_message = self.reason if self.reason else "Unknown Error"
96+
return getattr(self.data, "error", default_message)

src/superannotate/lib/core/serviceproviders.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def assign_items(
182182
folder_name: str,
183183
user: str,
184184
item_names: list,
185-
):
185+
) -> ServiceResponse:
186186
raise NotImplementedError
187187

188188
def get_bulk_images(

src/superannotate/lib/core/usecases/items.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from lib.core.usecases.base import BaseUseCase
2323
from superannotate.logger import get_default_logger
2424

25-
2625
logger = get_default_logger()
2726

2827

@@ -210,28 +209,30 @@ def __init__(
210209
self._user = user
211210
self._service = service
212211

213-
214-
def validate_item_names(self, ):
212+
def validate_item_names(
213+
self,
214+
):
215215
self._item_names = list(set(self._item_names))
216216

217217
def execute(self):
218218
cnt_assigned = 0
219219
if self.is_valid():
220220
for i in range(0, len(self._item_names), self.CHUNK_SIZE):
221-
status, response = self._service.assign_items(
221+
response = self._service.assign_items(
222222
team_id=self._project.team_id,
223223
project_id=self._project.id,
224224
folder_name=self._folder.name,
225225
user=self._user,
226226
item_names=self._item_names[i : i + self.CHUNK_SIZE], # noqa: E203
227227
)
228-
if status == 406 and 'error' in response: # User not found
229-
self._response.errors+=response['error']
230-
return self._response, 0
231-
elif 'error' in response:
232-
response['successCount'] = 0
228+
if not response.ok and "error" in response: # User not found
229+
self._response.errors += response.error
230+
break
233231

234-
cnt_assigned+=response['successCount']
232+
cnt_assigned += response.data["successCount"]
233+
logger.info(
234+
f"Assigned {cnt_assigned}/{len(self._item_names)} items to user {self._user}"
235+
)
235236
return self._response, cnt_assigned
236237

237238

src/superannotate/lib/infrastructure/services.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -765,9 +765,9 @@ def assign_items(
765765
folder_name: str,
766766
user: str,
767767
item_names: list,
768-
):
768+
) -> ServiceResponse:
769769
assign_items_url = urljoin(self.api_url, self.URL_ASSIGN_ITEMS)
770-
res = self._request(
770+
return self._request(
771771
assign_items_url,
772772
"put",
773773
params={"team_id": team_id, "project_id": project_id},
@@ -776,8 +776,8 @@ def assign_items(
776776
"assign_user_id": user,
777777
"folder_name": folder_name,
778778
},
779+
content_type=ServiceResponse,
779780
)
780-
return res.status_code, res.json()
781781

782782
def un_assign_items(
783783
self,

tests/integration/items/test_set_annotation_statuses.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def test_image_annotation_status_via_names(self):
6565

6666
def test_image_annotation_status_via_invalid_names(self):
6767
sa.attach_items(
68-
self.PROJECT_NAME, self.ATTACHMENT_LIST, annotation_status="InProgress"
68+
self.PROJECT_NAME, "InProgress", self.ATTACHMENT_LIST
6969
)
7070
with self.assertRaisesRegexp(AppException, SetAnnotationStatues.ERROR_MESSAGE):
7171
sa.set_annotation_statuses(

0 commit comments

Comments
 (0)