Skip to content

Commit 6a8d12c

Browse files
authored
Merge pull request #207 from superannotateai/friday_292
SDK | Added createdAt, updatedAt for classes in classes.json
2 parents 330c852 + a50dacd commit 6a8d12c

File tree

6 files changed

+61
-29
lines changed

6 files changed

+61
-29
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
from lib.core.enums import ImageQuality
4545
from lib.core.exceptions import AppException
4646
from lib.core.exceptions import AppValidationException
47-
from lib.core.types import ClassesJson
4847
from lib.core.types import AttributeGroup
48+
from lib.core.types import ClassesJson
4949
from lib.core.types import Project
5050
from lib.infrastructure.controller import Controller
5151
from plotly.subplots import make_subplots
@@ -1884,7 +1884,9 @@ def create_annotation_class(
18841884
"""
18851885
if isinstance(project, Project):
18861886
project = project.dict()
1887-
attribute_groups = list(map(lambda x: x.dict(), attribute_groups)) if attribute_groups else None
1887+
attribute_groups = (
1888+
list(map(lambda x: x.dict(), attribute_groups)) if attribute_groups else None
1889+
)
18881890
response = controller.create_annotation_class(
18891891
project_name=project, name=name, color=color, attribute_groups=attribute_groups
18901892
)
@@ -1941,6 +1943,8 @@ def download_annotation_classes_json(project: str, folder: Union[str, Path]):
19411943
response = controller.download_annotation_classes(
19421944
project_name=project, download_path=folder
19431945
)
1946+
if response.errors:
1947+
raise AppException(response.errors)
19441948
return response.data
19451949

19461950

src/superannotate/lib/core/entities.py

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@ def to_dict(self):
2424
raise NotImplementedError
2525

2626

27+
class BaseTimedEntity(BaseEntity):
28+
def __init__(
29+
self, uuid: Any = None, createdAt: str = None, updatedAt: str = None,
30+
):
31+
super().__init__(uuid)
32+
self.createdAt = createdAt
33+
self.updatedAt = updatedAt
34+
35+
def to_dict(self):
36+
return {
37+
"id": self.uuid,
38+
"createdAt": self.createdAt,
39+
"updatedAt": self.updatedAt,
40+
}
41+
42+
2743
class ConfigEntity(BaseEntity):
2844
def __init__(self, uuid: str, value: str):
2945
super().__init__(uuid)
@@ -41,10 +57,12 @@ def to_dict(self):
4157
return {"key": self.uuid, "value": self.value}
4258

4359

44-
class ProjectEntity(BaseEntity):
60+
class ProjectEntity(BaseTimedEntity):
4561
def __init__(
4662
self,
4763
uuid: int = None,
64+
createdAt: str = None,
65+
updatedAt: str = None,
4866
team_id: int = None,
4967
name: str = None,
5068
project_type: int = None,
@@ -65,7 +83,7 @@ def __init__(
6583
completed_images_count: int = None,
6684
root_folder_completed_images_count: int = None,
6785
):
68-
super().__init__(uuid)
86+
super().__init__(uuid, createdAt, updatedAt)
6987
self.team_id = team_id
7088
self.name = name
7189
self.project_type = project_type
@@ -100,7 +118,7 @@ def __copy__(self):
100118

101119
def to_dict(self):
102120
return {
103-
"id": self.uuid,
121+
**super().to_dict(),
104122
"team_id": self.team_id,
105123
"name": self.name,
106124
"type": self.project_type,
@@ -175,17 +193,19 @@ def to_dict(self):
175193
}
176194

177195

178-
class FolderEntity(BaseEntity):
196+
class FolderEntity(BaseTimedEntity):
179197
def __init__(
180198
self,
181199
uuid: int = None,
200+
createdAt: str = None,
201+
updatedAt: str = None,
182202
project_id: int = None,
183203
parent_id: int = None,
184204
team_id: int = None,
185205
name: str = None,
186206
folder_users: List[dict] = None,
187207
):
188-
super().__init__(uuid)
208+
super().__init__(uuid, createdAt, updatedAt)
189209
self.team_id = team_id
190210
self.project_id = project_id
191211
self.name = name
@@ -194,6 +214,7 @@ def __init__(
194214

195215
def to_dict(self):
196216
return {
217+
**super().to_dict(),
197218
"id": self.uuid,
198219
"team_id": self.team_id,
199220
"name": self.name,
@@ -301,22 +322,26 @@ def to_dict(self):
301322
return {"uuid": self.uuid, "bytes": self.data, "metadata": self.metadata}
302323

303324

304-
class AnnotationClassEntity(BaseEntity):
325+
class AnnotationClassEntity(BaseTimedEntity):
305326
def __init__(
306327
self,
307328
uuid: int = None,
329+
createdAt: str = None,
330+
updatedAt: str = None,
308331
color: str = None,
309332
count: int = None,
310333
name: str = None,
311334
project_id: int = None,
312335
attribute_groups: Iterable = None,
313336
):
314-
super().__init__(uuid)
337+
super().__init__(uuid, createdAt, updatedAt)
315338
self.color = color
316339
self.count = count
317340
self.name = name
318341
self.project_id = project_id
319342
self.attribute_groups = attribute_groups
343+
self.createdAt = createdAt
344+
self.updatedAt = updatedAt
320345

321346
def __copy__(self):
322347
return AnnotationClassEntity(
@@ -328,7 +353,7 @@ def __copy__(self):
328353

329354
def to_dict(self):
330355
return {
331-
"id": self.uuid,
356+
**super().to_dict(),
332357
"color": self.color,
333358
"count": self.count,
334359
"name": self.name,
@@ -402,12 +427,14 @@ def to_dict(self):
402427
}
403428

404429

405-
class MLModelEntity(BaseEntity):
430+
class MLModelEntity(BaseTimedEntity):
406431
def __init__(
407432
self,
408433
uuid: int = None,
409434
team_id: int = None,
410435
name: str = None,
436+
createdAt: str = None,
437+
updatedAt: str = None,
411438
path: str = None,
412439
config_path: str = None,
413440
model_type: int = None,
@@ -423,7 +450,7 @@ def __init__(
423450
is_global: bool = None,
424451
hyper_parameters: dict = {},
425452
):
426-
super().__init__(uuid=uuid)
453+
super().__init__(uuid, createdAt, updatedAt)
427454
self.name = name
428455
self.path = path
429456
self.team_id = team_id
@@ -443,7 +470,7 @@ def __init__(
443470

444471
def to_dict(self):
445472
return {
446-
"id": self.uuid,
473+
**super().to_dict(),
447474
"name": self.name,
448475
"team_id": self.team_id,
449476
"description": self.description,

src/superannotate/lib/core/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
from pydantic import BaseModel
66
from pydantic import constr
7-
from pydantic import StrictStr
87
from pydantic import Extra
8+
from pydantic import StrictStr
99

1010

1111
NotEmptyStr = constr(strict=True, min_length=1)

src/superannotate/lib/core/usecases.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -628,12 +628,12 @@ def validate_folder(self):
628628
if not self._folder.name:
629629
raise AppValidationException("Folder name cannot be empty.")
630630
if (
631-
len(
632-
set(self._folder.name).intersection(
633-
constances.SPECIAL_CHARACTERS_IN_PROJECT_FOLDER_NAMES
634-
)
631+
len(
632+
set(self._folder.name).intersection(
633+
constances.SPECIAL_CHARACTERS_IN_PROJECT_FOLDER_NAMES
635634
)
636-
> 0
635+
)
636+
> 0
637637
):
638638
self._folder.name = "".join(
639639
"_"
@@ -644,6 +644,7 @@ def validate_folder(self):
644644
logger.warning(
645645
"New folder name has special characters. Special characters will be replaced by underscores."
646646
)
647+
647648
def execute(self):
648649
if self.is_valid():
649650
self._folder.project_id = self._project.uuid
@@ -968,12 +969,12 @@ def validate_folder(self):
968969
if not self._folder.name:
969970
raise AppValidationException("Folder name cannot be empty.")
970971
if (
971-
len(
972-
set(self._folder.name).intersection(
973-
constances.SPECIAL_CHARACTERS_IN_PROJECT_FOLDER_NAMES
974-
)
972+
len(
973+
set(self._folder.name).intersection(
974+
constances.SPECIAL_CHARACTERS_IN_PROJECT_FOLDER_NAMES
975975
)
976-
> 0
976+
)
977+
> 0
977978
):
978979
self._folder.name = "".join(
979980
"_"
@@ -2657,10 +2658,9 @@ def execute(self):
26572658
)
26582659
classes = self._annotation_classes_repo.get_all()
26592660
classes = [entity.to_dict() for entity in classes]
2660-
json.dump(
2661-
classes, open(Path(self._download_path) / "classes.json", "w"), indent=4
2662-
)
2663-
self._response.data = self._download_path
2661+
json_path = Path(self._download_path) / "classes.json"
2662+
json.dump(classes, open(json_path, "w"), indent=4)
2663+
self._response.data = json_path
26642664
return self._response
26652665

26662666

src/superannotate/lib/infrastructure/repositories.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,8 @@ def dict2entity(data: dict):
336336
name=data["name"],
337337
count=data["count"],
338338
color=data["color"],
339+
createdAt=data["createdAt"],
340+
updatedAt=data["updatedAt"],
339341
attribute_groups=data["attribute_groups"],
340342
)
341343

src/superannotate/lib/infrastructure/services.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ class SuperannotateBackendService(BaseBackendService):
161161
URL_GET_FOLDER_BY_NAME = "folder/getFolderByName"
162162
URL_CREATE_FOLDER = "folder"
163163
URL_UPDATE_FOLDER = "folder/{}"
164-
URL_FOLDERS = "folder"
165164
URL_GET_IMAGE = "image/{}"
166165
URL_GET_IMAGES = "images"
167166
URL_BULK_GET_IMAGES = "images/getBulk"

0 commit comments

Comments
 (0)