Skip to content

Commit c639d1d

Browse files
committed
fix get_things_by_id
1 parent 132b0b7 commit c639d1d

File tree

16 files changed

+163
-145
lines changed

16 files changed

+163
-145
lines changed

docs/source/superannotate.sdk.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ ________
2525
.. automethod:: superannotate.SAClient.delete_project
2626
.. automethod:: superannotate.SAClient.rename_project
2727
.. _ref_get_project_metadata:
28+
.. automethod:: superannotate.SAClient.get_project_by_id
2829
.. automethod:: superannotate.SAClient.get_project_metadata
2930
.. automethod:: superannotate.SAClient.get_project_image_count
3031
.. automethod:: superannotate.SAClient.search_folders
3132
.. automethod:: superannotate.SAClient.assign_folder
3233
.. automethod:: superannotate.SAClient.unassign_folder
34+
.. automethod:: superannotate.SAClient.get_folder_by_id
3335
.. automethod:: superannotate.SAClient.get_folder_metadata
3436
.. automethod:: superannotate.SAClient.create_folder
3537
.. automethod:: superannotate.SAClient.delete_folders
@@ -68,6 +70,7 @@ Items
6870
______
6971

7072
.. automethod:: superannotate.SAClient.query
73+
.. automethod:: superannotate.SAClient.get_item_by_id
7174
.. automethod:: superannotate.SAClient.search_items
7275
.. automethod:: superannotate.SAClient.download_annotations
7376
.. automethod:: superannotate.SAClient.attach_items

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

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
import lib.core as constances
1010
import pandas as pd
1111
from lib.app.exceptions import AppException
12-
from lib.core import ATTACHED_VIDEO_ANNOTATION_POSTFIX
1312
from lib.core import PIXEL_ANNOTATION_POSTFIX
1413
from lib.core import VECTOR_ANNOTATION_POSTFIX
1514
from superannotate.logger import get_default_logger
1615

1716
logger = get_default_logger()
1817

18+
1919
@dataclass
2020
class ImageRowData:
2121
itemName: str = None
@@ -50,6 +50,7 @@ class ImageRowData:
5050
commentResolved: str = None
5151
tag: str = None
5252

53+
5354
@dataclass
5455
class VideoRawData:
5556
itemName: str = None
@@ -135,9 +136,9 @@ class DataAggregator:
135136
),
136137
"tag": lambda annotation: None,
137138
"mask": lambda annotation: {"parts": annotation["parts"]},
138-
"template": lambda annotation : None,
139+
"template": lambda annotation: None,
139140
"rbbox": lambda annotation: annotation["points"],
140-
"comment_inst": lambda annotation: annotation["points"]
141+
"comment_inst": lambda annotation: annotation["points"],
141142
}
142143

143144
def __init__(
@@ -204,18 +205,16 @@ def aggregate_annotations_as_df(self):
204205
self.check_classes_path()
205206
annotation_paths = self.get_annotation_paths()
206207

207-
208208
if self.project_type in (
209209
constances.ProjectType.VECTOR,
210-
constances.ProjectType.PIXEL
210+
constances.ProjectType.PIXEL,
211211
):
212212
return self.aggregate_image_annotations_as_df(annotation_paths)
213213
elif self.project_type is constances.ProjectType.VIDEO:
214214
return self.aggregate_video_annotations_as_df(annotation_paths)
215215
elif self.project_type is constances.ProjectType.DOCUMENT:
216216
return self.aggregate_document_annotations_as_df(annotation_paths)
217217

218-
219218
def __add_attributes_to_raws(self, raws, attributes, element_raw):
220219
for attribute_id, attribute in enumerate(attributes):
221220
attribute_raw = copy.copy(element_raw)
@@ -388,10 +387,10 @@ def aggregate_image_annotations_as_df(self, annotations_paths: List[str]):
388387
for annotation_path in annotations_paths:
389388
row_data = ImageRowData()
390389
annotation_json = None
391-
with open(annotation_path, 'r') as fp:
390+
with open(annotation_path) as fp:
392391
annotation_json = json.load(fp)
393392
parts = Path(annotation_path).name.split(self._annotation_suffix)
394-
row_data = self.__fill_image_metadata(row_data, annotation_json['metadata'])
393+
row_data = self.__fill_image_metadata(row_data, annotation_json["metadata"])
395394
annotation_instance_id = 0
396395

397396
# include comments
@@ -408,7 +407,7 @@ def aggregate_image_annotations_as_df(self, annotations_paths: List[str]):
408407
tag_row.rag = tag
409408
rows.append(tag_row)
410409

411-
#Instances
410+
# Instances
412411
for idx, annotation in enumerate(annotation_json["instances"]):
413412
instance_row = copy.copy(row_data)
414413
annotation_type = annotation.get("type", "mask")
@@ -462,7 +461,8 @@ def aggregate_image_annotations_as_df(self, annotations_paths: List[str]):
462461
attribute_name
463462
not in class_group_name_to_values[annotation_class_name][
464463
attribute_group
465-
] and group_id not in freestyle_attributes
464+
]
465+
and group_id not in freestyle_attributes
466466
):
467467
logger.warning(
468468
f"Annotation class group value {attribute_name} not in classes json. Skipping."
@@ -473,7 +473,6 @@ def aggregate_image_annotations_as_df(self, annotations_paths: List[str]):
473473
attribute_row.attributeGroupName = attribute_group
474474
attribute_row.attributeName = attribute_name
475475

476-
477476
rows.append(attribute_row)
478477
num_added += 1
479478

@@ -486,7 +485,7 @@ def aggregate_image_annotations_as_df(self, annotations_paths: List[str]):
486485

487486
@staticmethod
488487
def __fill_image_metadata(raw_data, metadata):
489-
raw_data.itemName = metadata.get('name')
488+
raw_data.itemName = metadata.get("name")
490489
raw_data.itemHeight = metadata.get("height")
491490
raw_data.itemWidth = metadata.get("width")
492491
raw_data.itemStatus = metadata.get("status")

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ def instance_consensus(inst_1, inst_2):
398398

399399
return score
400400

401+
401402
def calculate_tag_consensus(image_df):
402403
column_names = [
403404
"creatorEmail",
@@ -406,14 +407,14 @@ def calculate_tag_consensus(image_df):
406407
"className",
407408
"folderName",
408409
"attributeGroupName",
409-
"attributeName"
410+
"attributeName",
410411
]
411412

412413
image_data = {}
413414
for column_name in column_names:
414415
image_data[column_name] = []
415416

416-
image_df=image_df.reset_index()
417+
image_df = image_df.reset_index()
417418
image_data["score"] = []
418419
for i, irow in image_df.iterrows():
419420
for c in column_names:
@@ -422,10 +423,15 @@ def calculate_tag_consensus(image_df):
422423
for j, jrow in image_df.iterrows():
423424
if i == j:
424425
continue
425-
if (irow["className"] == jrow["className"]) and irow["attributeGroupName"] == jrow["attributeGroupName"] and irow["attributeName"] == jrow["attributeName"]:
426-
image_data["score"][i]+=1
426+
if (
427+
(irow["className"] == jrow["className"])
428+
and irow["attributeGroupName"] == jrow["attributeGroupName"]
429+
and irow["attributeName"] == jrow["attributeName"]
430+
):
431+
image_data["score"][i] += 1
427432
return image_data
428433

434+
429435
def consensus(df, item_name, annot_type):
430436
"""Helper function that computes consensus score for instances of a single image:
431437
@@ -484,7 +490,7 @@ def consensus(df, item_name, annot_type):
484490
inst = Polygon(shapely_format)
485491
elif annot_type == "point":
486492
inst = Point(inst_data["x"], inst_data["y"])
487-
if annot_type != "tag" and inst.is_valid:
493+
if annot_type != "tag" and inst.is_valid:
488494
projects_shaply_objs[row["folderName"]].append(
489495
(inst, row["className"], row["creatorEmail"], row["attributes"])
490496
)

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

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@
3535
from lib.app.interface.types import Setting
3636
from lib.app.serializers import BaseSerializer
3737
from lib.app.serializers import FolderSerializer
38+
from lib.app.serializers import ItemSerializer
3839
from lib.app.serializers import ProjectSerializer
3940
from lib.app.serializers import SettingsSerializer
4041
from lib.app.serializers import TeamSerializer
41-
from lib.app.serializers import ItemSerializer
4242
from lib.core import entities
4343
from lib.core import LIMITED_FUNCTIONS
4444
from lib.core.conditions import Condition
@@ -86,48 +86,59 @@ def __init__(
8686
):
8787
super().__init__(token, config_path)
8888

89-
def get_folder_by_id(self, project_id: int, folder_id: int):
90-
"""Returns the folder
91-
:param folder_id: the id of the folder
89+
def get_project_by_id(self, project_id: int):
90+
"""Returns the project metadata
91+
9292
:param project_id: the id of the project
93-
:return: folder information
93+
:type project_id: int
94+
95+
:return: project metadata
9496
:rtype: dict
9597
"""
98+
response = self.controller.get_project_by_id(project_id=project_id)
9699

97-
response = self.controller.get_folder_by_id(
98-
folder_id=folder_id,
99-
project_id=project_id
100-
)
100+
return ProjectSerializer(response.data).serialize()
101101

102-
return FolderSerializer(response).serialize(exclude={"completedCount", "is_root"})
102+
def get_folder_by_id(self, project_id: int, folder_id: int):
103+
"""Returns the folder metadata
103104
104-
def get_project_by_id(self, project_id: int):
105-
"""Returns the project
106105
:param project_id: the id of the project
107-
:return: folder information
106+
:type project_id: int
107+
108+
:param folder_id: the id of the folder
109+
:type folder_id: int
110+
111+
:return: folder metadata
108112
:rtype: dict
109113
"""
110-
response = self.controller.get_project_by_id(
111-
project_id=project_id
114+
115+
response = self.controller.get_folder_by_id(
116+
folder_id=folder_id, project_id=project_id
112117
)
113118

114-
return ProjectSerializer(response.data).serialize()
119+
return FolderSerializer(response).serialize(
120+
exclude={"completedCount", "is_root"}
121+
)
115122

116123
def get_item_by_id(self, project_id: int, item_id: int):
117-
"""Returns the project
118-
:param item_id: the id of the item
124+
"""Returns the item metadata
125+
119126
:param project_id: the id of the project
120-
:return: folder information
127+
:type project_id: int
128+
129+
:param item_id: the id of the item
130+
:type item_id: int
131+
132+
133+
:return: item metadata
121134
:rtype: dict
122135
"""
123136

124137
response = self.controller.get_item_by_id(
125-
item_id=item_id,
126-
project_id=project_id
138+
item_id=item_id, project_id=project_id
127139
)
128140

129-
return ItemSerializer(response).serialize(exclude = {"url", "meta"})
130-
141+
return ItemSerializer(response).serialize(exclude={"url", "meta"})
131142

132143
def get_team_metadata(self):
133144
"""Returns team metadata
@@ -499,7 +510,7 @@ def get_project_metadata(
499510
include_settings: Optional[StrictBool] = False,
500511
include_workflow: Optional[StrictBool] = False,
501512
include_contributors: Optional[StrictBool] = False,
502-
include_complete_image_count: Optional[StrictBool] = False
513+
include_complete_image_count: Optional[StrictBool] = False,
503514
):
504515
"""Returns project metadata
505516

src/superannotate/lib/app/serializers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ def serialize(self):
165165
self.data["value"] = constance.ImageQuality.get_name(self.data["value"])
166166
return self.data
167167

168+
168169
class ItemSerializer(BaseSerializer):
169170
def serialize(
170171
self,
@@ -177,6 +178,7 @@ def serialize(
177178

178179
return data
179180

181+
180182
class EntitySerializer:
181183
@classmethod
182184
def serialize(

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
from lib.core.entities.classes import AnnotationClassEntity
44
from lib.core.entities.folder import FolderEntity
55
from lib.core.entities.integrations import IntegrationEntity
6+
from lib.core.entities.items import ClassificationEntity
67
from lib.core.entities.items import DocumentEntity
78
from lib.core.entities.items import ImageEntity
8-
from lib.core.entities.items import VideoEntity
9-
from lib.core.entities.items import ClassificationEntity
10-
from lib.core.entities.items import TiledEntity
119
from lib.core.entities.items import PointCloudEntity
10+
from lib.core.entities.items import TiledEntity
11+
from lib.core.entities.items import VideoEntity
1212
from lib.core.entities.project import AttachmentEntity
1313
from lib.core.entities.project import MLModelEntity
1414
from lib.core.entities.project import ProjectEntity
@@ -30,6 +30,9 @@
3030
"ImageEntity",
3131
"BaseItemEntity",
3232
"VideoEntity",
33+
"PointCloudEntity",
34+
"TiledEntity",
35+
"ClassificationEntity",
3336
"DocumentEntity",
3437
# Utils
3538
"AttachmentEntity",

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,22 @@ class VideoEntity(BaseItemEntity):
2828
class Config:
2929
extra = Extra.ignore
3030

31+
3132
class DocumentEntity(BaseItemEntity):
3233
class Config:
3334
extra = Extra.ignore
3435

36+
3537
class TiledEntity(BaseItemEntity):
3638
class Config:
3739
extra = Extra.ignore
3840

41+
3942
class ClassificationEntity(BaseItemEntity):
4043
class Config:
4144
extra = Extra.ignore
4245

46+
4347
class PointCloudEntity(BaseItemEntity):
4448
class Config:
4549
extra = Extra.ignore

src/superannotate/lib/core/service_types.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,24 +167,31 @@ def set_error(self, value: Union[dict, str]):
167167
class ImageResponse(ServiceResponse):
168168
data: entities.ImageEntity = None
169169

170+
170171
class VideoResponse(ServiceResponse):
171172
data: entities.VideoEntity = None
172173

174+
173175
class DocumentResponse(ServiceResponse):
174176
data: entities.DocumentEntity = None
175177

178+
176179
class TiledResponse(ServiceResponse):
177180
data: entities.TiledEntity = None
178181

182+
179183
class ClassificationResponse(ServiceResponse):
180184
data: entities.ClassificationEntity = None
181185

186+
182187
class PointCloudResponse(ServiceResponse):
183188
data: entities.PointCloudEntity = None
184189

190+
185191
class TeamResponse(ServiceResponse):
186192
data: entities.TeamEntity = None
187193

194+
188195
class ModelListResponse(ServiceResponse):
189196
data: List[entities.AnnotationClassEntity] = None
190197

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ def __init__(self, project_id, folder_id, team_id, service_provider):
2525
def execute(self):
2626
try:
2727
response = self._service_provider.folders.get_by_id(
28-
folder_id = self._folder_id,
29-
project_id = self._project_id,
30-
team_id = self._team_id
28+
folder_id=self._folder_id,
29+
project_id=self._project_id,
30+
team_id=self._team_id,
3131
)
3232
except AppException as e:
33-
self._response.errors=e
33+
self._response.errors = e
3434
else:
3535
self._response.data = response.data
3636

0 commit comments

Comments
 (0)