Skip to content

Commit 90f76ee

Browse files
committed
tod
1 parent a38af36 commit 90f76ee

File tree

20 files changed

+3053
-194
lines changed

20 files changed

+3053
-194
lines changed

pytest.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
minversion = 3.7
33
log_cli=true
44
python_files = test_*.py
5-
;addopts = -n auto --dist=loadscope
5+
addopts = -n auto --dist=loadscope

src/superannotate/lib/app/annotation_helpers.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def add_annotation_comment_to_json(
8686
"y": comment_coords[1],
8787
"correspondence": [{"text": comment_text, "email": comment_author}],
8888
"resolved": resolved,
89+
"creationType": "Preannotation", # noqa
8990
"createdBy": user_action,
9091
"updatedBy": user_action,
9192
}
@@ -132,7 +133,6 @@ def add_annotation_bbox_to_json(
132133
"type": "bbox",
133134
"points": {"x1": bbox[0], "y1": bbox[1], "x2": bbox[2], "y2": bbox[3]},
134135
"className": annotation_class_name,
135-
"error": error,
136136
"groupId": 0,
137137
"pointLabels": {},
138138
"locked": False,
@@ -141,7 +141,8 @@ def add_annotation_bbox_to_json(
141141
if annotation_class_attributes is None
142142
else annotation_class_attributes,
143143
}
144-
144+
if error is not None:
145+
annotation["error"] = error
145146
annotation = _add_created_updated(annotation)
146147
annotation_json["instances"].append(annotation)
147148

@@ -175,13 +176,11 @@ def add_annotation_point_to_json(
175176
raise AppException("Point should be 2 element float list.")
176177

177178
annotation_json, path = _preprocess_annotation_json(annotation_json, image_name)
178-
179179
annotation = {
180180
"type": "point",
181181
"x": point[0],
182182
"y": point[1],
183183
"className": annotation_class_name,
184-
"error": error,
185184
"groupId": 0,
186185
"pointLabels": {},
187186
"locked": False,
@@ -190,6 +189,8 @@ def add_annotation_point_to_json(
190189
if annotation_class_attributes is None
191190
else annotation_class_attributes,
192191
}
192+
if error is not None:
193+
annotation["error"] = error
193194

194195
annotation = _add_created_updated(annotation)
195196
annotation_json["instances"].append(annotation)

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

Lines changed: 67 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,13 @@
4444
from lib.core.entities import AttachmentEntity
4545
from lib.core.entities import SettingEntity
4646
from lib.core.entities.classes import AnnotationClassEntity
47+
from lib.core.entities.classes import AttributeGroup
4748
from lib.core.entities.integrations import IntegrationEntity
4849
from lib.core.enums import ImageQuality
4950
from lib.core.exceptions import AppException
50-
from lib.core.types import AttributeGroup
5151
from lib.core.types import MLModel
5252
from lib.core.types import PriorityScore
5353
from lib.core.types import Project
54-
from lib.infrastructure.controller import Controller
5554
from lib.infrastructure.validators import wrap_error
5655
from pydantic import conlist
5756
from pydantic import parse_obj_as
@@ -1141,19 +1140,76 @@ def create_annotation_class(
11411140
11421141
:param project: project name
11431142
:type project: str
1143+
11441144
:param name: name for the class
11451145
:type name: str
1146-
:param color: RGB hex color value, e.g., "#FFFFAA"
1146+
1147+
:param color: RGB hex color value, e.g., "#F9E0FA"
11471148
:type color: str
1148-
:param attribute_groups: example:
1149-
[ { "name": "tall", "is_multiselect": 0, "attributes": [ { "name": "yes" }, { "name": "no" } ] },
1150-
{ "name": "age", "is_multiselect": 0, "attributes": [ { "name": "young" }, { "name": "old" } ] } ]
1149+
1150+
:param attribute_groups: list of attribute group dicts.
1151+
The values for the "group_type" key are "radio"|"checklist"|"text"|"numeric".
1152+
Mandatory keys for each attribute group are
1153+
- "name"
11511154
:type attribute_groups: list of dicts
1152-
:param class_type: class type
1155+
1156+
:param class_type: class type. Should be either "object" or "tag"
11531157
:type class_type: str
11541158
11551159
:return: new class metadata
11561160
:rtype: dict
1161+
1162+
Request Example:
1163+
::
1164+
attributes_list = [
1165+
{
1166+
"group_type": "radio",
1167+
"name": "Vehicle",
1168+
"attributes": [
1169+
{
1170+
"name": "Car"
1171+
},
1172+
{
1173+
"name": "Track"
1174+
},
1175+
{
1176+
"name": "Bus"
1177+
}
1178+
],
1179+
"default_value": "Car"
1180+
},
1181+
{
1182+
"group_type": "checklist",
1183+
"name": "Color",
1184+
"attributes": [
1185+
{
1186+
"name": "Yellow"
1187+
},
1188+
{
1189+
"name": "Black"
1190+
},
1191+
{
1192+
"name": "White"
1193+
}
1194+
],
1195+
"default_value": ["Yellow", "White"]
1196+
},
1197+
{
1198+
"group_type": "text",
1199+
"name": "Timestamp"
1200+
},
1201+
{
1202+
"group_type": "numeric",
1203+
"name": "Description"
1204+
}
1205+
]
1206+
client.create_annotation_class(
1207+
project="Image Project",
1208+
name="Example Class",
1209+
color="#F9E0FA",
1210+
attribute_groups=attributes_list
1211+
)
1212+
11571213
"""
11581214
if isinstance(project, Project):
11591215
project = project.dict()
@@ -1837,7 +1893,6 @@ def add_annotation_point_to_image(
18371893
annotations,
18381894
point,
18391895
annotation_class_name,
1840-
image_name,
18411896
annotation_class_attributes,
18421897
error,
18431898
)
@@ -2112,7 +2167,9 @@ def delete_annotations(
21122167
raise AppException(response.errors)
21132168

21142169
def validate_annotations(
2115-
self, project_type: ProjectTypes, annotations_json: Union[NotEmptyStr, Path, dict]
2170+
self,
2171+
project_type: ProjectTypes,
2172+
annotations_json: Union[NotEmptyStr, Path, dict],
21162173
):
21172174
"""Validates given annotation JSON.
21182175
@@ -2129,9 +2186,7 @@ def validate_annotations(
21292186
annotation_data = annotations_json
21302187
else:
21312188
annotation_data = json.load(open(annotations_json))
2132-
response = self.controller.validate_annotations(
2133-
project_type, annotation_data
2134-
)
2189+
response = self.controller.validate_annotations(project_type, annotation_data)
21352190
if response.errors:
21362191
raise AppException(response.errors)
21372192
report = response.data

src/superannotate/lib/core/enums.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
from types import DynamicClassAttribute
33

44

5+
class classproperty:
6+
def __init__(self, getter):
7+
self.getter = getter
8+
9+
def __get__(self, instance, owner):
10+
return self.getter(owner)
11+
12+
513
class BaseTitledEnum(int, Enum):
614
def __new__(cls, title, value):
715
obj = int.__new__(cls, value)
@@ -64,6 +72,10 @@ class ProjectType(BaseTitledEnum):
6472
VIDEO = "Video", 3
6573
DOCUMENT = "Document", 4
6674

75+
@classproperty
76+
def images(self):
77+
return self.VECTOR.value, self.PIXEL.value
78+
6779

6880
class UserRole(BaseTitledEnum):
6981
SUPER_ADMIN = "Superadmin", 1

src/superannotate/lib/core/serviceproviders.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,9 @@ def upload_annotations(
372372
) -> ServiceResponse:
373373
raise NotImplementedError
374374

375-
def get_schema(self, team_id: int, project_type: int, version: str) -> dict:
375+
def get_schema(
376+
self, team_id: int, project_type: int, version: str
377+
) -> ServiceResponse:
376378
raise NotImplementedError
377379

378380
def list_sub_sets(self, team_id: int, project_id: int) -> ServiceResponse:

src/superannotate/lib/core/types.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@
33
from pydantic import BaseModel
44
from pydantic import constr
55
from pydantic import Extra
6-
from superannotate_schemas.schemas.classes import AttributeGroup as AttributeGroupSchema
76

87
NotEmptyStr = constr(strict=True, min_length=1)
98

10-
AttributeGroup = AttributeGroupSchema
11-
129

1310
class Project(BaseModel):
1411
name: NotEmptyStr

0 commit comments

Comments
 (0)