Skip to content

Commit 49bf690

Browse files
committed
Cahgned items serialization.
1 parent 3b03b74 commit 49bf690

File tree

15 files changed

+93
-61
lines changed

15 files changed

+93
-61
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -799,22 +799,22 @@ def get_project_workflow(project: Union[str, dict]):
799799
@Trackable
800800
@validate_arguments
801801
def search_annotation_classes(
802-
project: Union[NotEmptyStr, dict], name_prefix: Optional[str] = None
802+
project: Union[NotEmptyStr, dict], name_contains: Optional[str] = None
803803
):
804804
"""Searches annotation classes by name_prefix (case-insensitive)
805805
806806
:param project: project name
807807
:type project: str
808-
:param name_prefix: name prefix for search. If None all annotation classes
809-
will be returned
808+
:param name_contains: search string. Returns those classes,
809+
where the given string is found anywhere within its name. If None, all annotation classes will be returned.
810810
:type name_prefix: str
811811
812812
:return: annotation classes of the project
813813
:rtype: list of dicts
814814
"""
815815
project_name, folder_name = extract_project_folder(project)
816816
classes = Controller.get_default().search_annotation_classes(
817-
project_name, name_prefix
817+
project_name, name_contains
818818
)
819819
classes = [BaseSerializer(attribute).serialize() for attribute in classes.data]
820820
return classes

src/superannotate/lib/app/mixp/decorators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
import sys
33
from inspect import signature
44

5-
from mixpanel import Mixpanel
6-
75
from lib import get_default_controller
6+
from mixpanel import Mixpanel
87
from superannotate.logger import get_default_logger
98
from version import __version__
9+
1010
from .utils import parsers
1111

1212
logger = get_default_logger()

src/superannotate/lib/app/mixp/utils/parsers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ def upload_image_annotations(**kwargs):
372372
"event_name": "upload_image_annotations",
373373
"properties": {
374374
"project_name": get_project_name(project),
375-
"Pixel": bool(("mask" in kwargs)),
375+
"Pixel": bool("mask" in kwargs),
376376
},
377377
}
378378

@@ -478,7 +478,7 @@ def move_images(**kwargs):
478478
"properties": {
479479
"project_name": project_name,
480480
"Image Count": len(image_names),
481-
"Copy Annotations": bool(("include_annotations" in kwargs)),
481+
"Copy Annotations": bool("include_annotations" in kwargs),
482482
"Copy Annotation Status": bool("copy_annotation_status" in kwargs),
483483
"Copy Pin": bool("copy_pin" in kwargs),
484484
},

src/superannotate/lib/core/entities/base.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,15 @@ class TimedBaseModel(BaseModel):
1313

1414

1515
class BaseEntity(TimedBaseModel):
16-
id: int
1716
name: str
18-
path: Optional[str] = Field(
19-
None, description="Item’s path in SuperAnnotate project"
20-
)
21-
url: Optional[str] = Field(None, description="Publicly available HTTP address")
17+
path: Optional[str] = Field(None, description="Item’s path in SuperAnnotate project")
18+
url: Optional[str] = Field(description="Publicly available HTTP address")
19+
annotator_email: Optional[str] = Field(description="Annotator email")
20+
qa_email: Optional[str] = Field(description="QA email")
2221
annotation_status: AnnotationStatus = Field(description="Item annotation status")
23-
annotator_name: Optional[str] = Field(description="Annotator email")
24-
qa_name: Optional[str] = Field(description="QA email")
25-
entropy_value: Optional[str] = Field(description="Priority score of given item")
22+
entropy_value: Optional[float] = Field(description="Priority score of given item")
2623
createdAt: str = Field(description="Date of creation")
2724
updatedAt: str = Field(description="Update date")
2825

2926
class Config:
3027
extra = Extra.allow
31-
32-
def add_path(self, project_name: str, folder_name: str):
33-
path = f"{project_name}{f'/{folder_name}' if folder_name != 'root' else ''}/{self.name}"
34-
self.path = path
35-
return self

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@
77

88

99
class Entity(BaseEntity):
10+
1011
class Config:
1112
extra = Extra.allow
1213

14+
def add_path(self, project_name: str, folder_name: str):
15+
self.path = f"{project_name}{f'/{folder_name}' if folder_name != 'root' else ''}/{self.name}"
16+
return self
17+
1318

1419
class TmpImageEntity(Entity):
1520
prediction_status: Optional[SegmentationStatus] = Field(

src/superannotate/lib/core/entities/project_entities.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ def __init__(
222222
project_id: int = None,
223223
parent_id: int = None,
224224
team_id: int = None,
225+
is_root: bool = False,
225226
name: str = None,
226227
folder_users: List[dict] = None,
227228
):
@@ -230,13 +231,15 @@ def __init__(
230231
self.project_id = project_id
231232
self.name = name
232233
self.parent_id = parent_id
234+
self.is_root = is_root
233235
self.folder_users = folder_users
234236

235237
def to_dict(self):
236238
return {
237239
**super().to_dict(),
238240
"id": self.uuid,
239241
"team_id": self.team_id,
242+
"is_root": self.is_root,
240243
"name": self.name,
241244
"parent_id": self.parent_id,
242245
"project_id": self.project_id,

src/superannotate/lib/core/repositories.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import boto3
99
from lib.core.conditions import Condition
1010
from lib.core.entities import BaseEntity
11+
from lib.core.entities import Entity
1112
from lib.core.entities import ProjectEntity
1213
from lib.core.entities import TmpBaseEntity
1314
from lib.core.serviceproviders import SuperannotateServiceProvider
@@ -17,18 +18,18 @@ class BaseReadOnlyRepository(ABC):
1718
@abstractmethod
1819
def get_one(
1920
self, uuid: Union[Condition, int]
20-
) -> Optional[Union[BaseEntity, TmpBaseEntity]]:
21+
) -> Optional[Union[BaseEntity, Entity]]:
2122
raise NotImplementedError
2223

2324
@abstractmethod
2425
def get_all(
2526
self, condition: Optional[Condition] = None
26-
) -> List[Union[BaseEntity, TmpBaseEntity]]:
27+
) -> List[Union[BaseEntity, Entity]]:
2728
raise NotImplementedError
2829

2930
@staticmethod
30-
def dict2entity(data: dict) -> BaseEntity:
31-
return BaseEntity(**data)
31+
def dict2entity(data: dict) -> Entity:
32+
return Entity(**TmpBaseEntity(**data).dict())
3233

3334

3435
class BaseManageableRepository(BaseReadOnlyRepository):

src/superannotate/lib/core/serviceproviders.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,6 @@ def get_project_workflows(self, project_id: int, team_id: int):
7575
def list_images(self, query_string):
7676
raise NotImplementedError
7777

78-
@abstractmethod
79-
def list_images(self, query_string):
80-
raise NotImplementedError
81-
8278
@abstractmethod
8379
def get_project(self, uuid: int, team_id: int):
8480
raise NotImplementedError

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

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import copy
12
from typing import List
23

34
import superannotate.lib.core as constances
@@ -36,6 +37,8 @@ def __init__(
3637

3738
@staticmethod
3839
def serialize_entity(entity: Entity, project: ProjectEntity):
40+
if project.upload_state != constances.UploadState.EXTERNAL.value:
41+
entity.url = None
3942
if project.project_type in (
4043
constances.ProjectType.VECTOR.value,
4144
constances.ProjectType.PIXEL.value,
@@ -92,12 +95,6 @@ def validate_query(self):
9295
if self._project.sync_status != constances.ProjectState.SYNCED.value:
9396
raise AppException("Data is not synced.")
9497

95-
@staticmethod
96-
def _drop_paths(items: List[Entity]):
97-
for item in items:
98-
item.path = None
99-
return items
100-
10198
def execute(self) -> Response:
10299
if self.is_valid():
103100
service_response = self._backend_client.saqul_query(
@@ -107,14 +104,7 @@ def execute(self) -> Response:
107104
folder_id=None if self._folder.name == "root" else self._folder.uuid,
108105
)
109106
if service_response.ok:
110-
if self._project.project_type == constances.ProjectType.VECTOR.value:
111-
data = self._drop_paths(
112-
parse_obj_as(List[TmpBaseEntity], service_response.data)
113-
)
114-
else:
115-
data = self._drop_paths(
116-
parse_obj_as(List[TmpBaseEntity], service_response.data)
117-
)
107+
data = parse_obj_as(List[TmpBaseEntity], service_response.data)
118108
for i, item in enumerate(data):
119109
data[i] = GetItem.serialize_entity(item, self._project)
120110
self._response.data = data
@@ -143,7 +133,7 @@ def __init__(
143133
self._recursive = recursive
144134

145135
def validate_recursive_case(self):
146-
if self._folder.name != "root" and self._recursive:
136+
if not self._folder.is_root and self._recursive:
147137
self._recursive = False
148138

149139
def execute(self) -> Response:
@@ -169,7 +159,7 @@ def execute(self) -> Response:
169159
folders.append(self._folder)
170160
for folder in folders:
171161
tmp = self._items.get_all(
172-
self._search_condition & Condition("folder_id", folder.uuid, EQ)
162+
copy.deepcopy(self._search_condition) & Condition("folder_id", folder.uuid, EQ)
173163
)
174164
items.extend(
175165
[

src/superannotate/lib/infrastructure/controller.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -821,11 +821,11 @@ def get_project_workflow(self, project_name: str):
821821
)
822822
return use_case.execute()
823823

824-
def search_annotation_classes(self, project_name: str, name_prefix: str = None):
824+
def search_annotation_classes(self, project_name: str, name_contains: str = None):
825825
project_entity = self._get_project(project_name)
826826
condition = None
827-
if name_prefix:
828-
condition = Condition("name", name_prefix, EQ) & Condition("pattern", True, EQ)
827+
if name_contains:
828+
condition = Condition("name", name_contains, EQ) & Condition("pattern", True, EQ)
829829
use_case = usecases.GetAnnotationClassesUseCase(
830830
classes=AnnotationClassRepository(
831831
service=self._backend_client, project=project_entity
@@ -1602,7 +1602,7 @@ def list_items(
16021602
if qa_email:
16031603
search_condition &= Condition("qa_id", qa_email, EQ)
16041604
if annotator_email:
1605-
search_condition &= Condition("annotator_id", qa_email, EQ)
1605+
search_condition &= Condition("annotator_id", annotator_email, EQ)
16061606
for key, value in kwargs.items():
16071607
search_condition &= Condition(key, value, EQ)
16081608
use_case = usecases.ListItems(

0 commit comments

Comments
 (0)