Skip to content

Commit 8bc6819

Browse files
Vaghinak BasentsyanVaghinak Basentsyan
authored andcommitted
Schema fixes
1 parent d3471e7 commit 8bc6819

File tree

5 files changed

+19
-40
lines changed

5 files changed

+19
-40
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33

44
from lib.core.entities.utils import BaseImageInstance
55
from lib.core.entities.utils import BaseModel
6-
from lib.core.entities.utils import MetadataBase
6+
from lib.core.entities.utils import Metadata
77
from lib.core.entities.utils import Tag
88
from pydantic import Field
99
from pydantic import validator
1010
from pydantic.color import Color
1111
from pydantic.color import ColorType
1212

1313

14-
class PixelMetaData(MetadataBase):
14+
class PixelMetaData(Metadata):
1515
is_segmented: Optional[bool] = Field(None, alias="isSegmented")
1616

1717

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from datetime import datetime
21
from enum import Enum
32
from typing import Dict
43
from typing import List
@@ -24,6 +23,9 @@ def enum_error_handling(self) -> str:
2423
NotEmptyStr = constr(strict=True, min_length=1)
2524

2625

26+
DATE_REGEX = r'\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d(?:\.\d{3})Z'
27+
28+
2729
class BaseModel(PyDanticBaseModel):
2830
class Config:
2931
use_enum_values = True
@@ -98,8 +100,8 @@ class BboxPoints(BaseModel):
98100

99101

100102
class TimedBaseModel(BaseModel):
101-
created_at: constr(regex=r'\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d(?:\.\d{3})Z') = Field(None, alias="createdAt")
102-
updated_at: constr(regex=r'\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d(?:\.\d{3})Z') = Field(None, alias="updatedAt")
103+
created_at: constr(regex=DATE_REGEX) = Field(None, alias="createdAt")
104+
updated_at: constr(regex=DATE_REGEX) = Field(None, alias="updatedAt")
103105

104106

105107
class UserAction(BaseModel):
@@ -128,12 +130,14 @@ class BaseInstance(TrackableModel, TimedBaseModel):
128130

129131

130132
class MetadataBase(BaseModel):
133+
name: NotEmptyStr
131134
last_action: Optional[LastUserAction] = Field(None, alias="lastAction")
132135
width: Optional[int]
133136
height: Optional[int]
134137
project_id: Optional[int] = Field(None, alias="projectId")
135138
annotator_email: Optional[EmailStr] = Field(None, alias="annotatorEmail")
136139
qa_email: Optional[EmailStr] = Field(None, alias="qaEmail")
140+
status: Optional[AnnotationStatusEnum]
137141

138142

139143
class PointLabels(BaseModel):
@@ -154,7 +158,7 @@ class Comment(TimedBaseModel, TrackableModel):
154158

155159
class BaseImageInstance(BaseInstance):
156160
class_id: Optional[int] = Field(None, alias="classId")
157-
class_name: Optional[str] = Field(None, alias="className")
161+
class_name: str = Field(alias="className")
158162
visible: Optional[bool]
159163
locked: Optional[bool]
160164
probability: Optional[int] = Field(100)
@@ -175,7 +179,5 @@ class BaseVectorInstance(BaseImageInstance):
175179

176180

177181
class Metadata(MetadataBase):
178-
name: NotEmptyStr
179-
status: Optional[AnnotationStatusEnum]
180182
pinned: Optional[bool]
181183
is_predicted: Optional[bool] = Field(None, alias="isPredicted")

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

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from typing import Optional
33
from typing import Union
44

5-
from lib.core.entities.utils import AttributeGroup
65
from lib.core.entities.utils import BaseModel
76
from lib.core.entities.utils import BaseVectorInstance
87
from lib.core.entities.utils import BboxPoints
@@ -12,20 +11,6 @@
1211
from lib.core.entities.utils import VectorAnnotationTypeEnum
1312
from pydantic import conlist
1413
from pydantic import Field
15-
from pydantic import StrictStr
16-
from pydantic import validate_model
17-
from pydantic import ValidationError
18-
from pydantic import validator
19-
20-
21-
class ClassesJson(BaseModel):
22-
name: StrictStr
23-
color: StrictStr
24-
attribute_groups: List[AttributeGroup]
25-
26-
27-
class Tags(BaseModel):
28-
items: Optional[List[str]]
2914

3015

3116
class AxisPoint(BaseModel):
@@ -126,9 +111,7 @@ def return_action(cls, values):
126111
try:
127112
instance_type = values["type"]
128113
except KeyError:
129-
raise ValueError(
130-
f"meta.type required"
131-
)
114+
raise ValueError("meta.type required")
132115
try:
133116
return ANNOTATION_TYPES[instance_type](**values)
134117
except KeyError:

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,15 @@
44
from typing import Optional
55
from typing import Union
66

7-
from lib.core.entities.utils import AnnotationStatusEnum
87
from lib.core.entities.utils import Attribute
98
from lib.core.entities.utils import BaseInstance
109
from lib.core.entities.utils import BaseModel
1110
from lib.core.entities.utils import BboxPoints
1211
from lib.core.entities.utils import MetadataBase
13-
from lib.core.entities.utils import NotEmptyStr
1412
from lib.core.entities.utils import PointLabels
1513
from lib.core.entities.utils import Tag
1614
from pydantic import conlist
1715
from pydantic import Field
18-
from pydantic import validator
1916

2017

2118
class VideoType(str, Enum):
@@ -24,9 +21,7 @@ class VideoType(str, Enum):
2421

2522

2623
class MetaData(MetadataBase):
27-
name: NotEmptyStr
2824
url: Optional[str]
29-
status: Optional[AnnotationStatusEnum]
3025
duration: Optional[int]
3126
error: Optional[bool]
3227

@@ -113,7 +108,7 @@ def return_action(cls, values):
113108
instance_type = values["meta"]["type"]
114109
except KeyError:
115110
raise ValueError(
116-
f"meta.type required"
111+
"meta.type required"
117112
)
118113
try:
119114
return INSTANCES[instance_type](**values)

tests/integration/annotations/test_annotation_upload_pixel.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def folder_path(self):
3131
@pytest.mark.flaky(reruns=2)
3232
@patch("lib.core.usecases.annotations.UploadAnnotationUseCase.s3_bucket")
3333
def test_recursive_annotation_upload_pixel(self, s3_bucket):
34-
sa.create_folder(self.PROJECT_NAME,self.FOLDER)
34+
sa.create_folder(self.PROJECT_NAME, self.FOLDER)
3535
destination = f"{self.PROJECT_NAME}/{self.FOLDER}"
3636
sa.upload_images_from_folder_to_project(
3737
destination, self.folder_path, recursive_subfolders=False
@@ -42,17 +42,17 @@ def test_recursive_annotation_upload_pixel(self, s3_bucket):
4242
recursive_subfolders=False)
4343
self.assertEqual(len(uploaded_annotations), 3)
4444
self.assertEqual(len(s3_bucket.method_calls), 6)
45-
self.assertIn(f"Uploading 3 annotations from {self.S3_FOLDER_PATH} to the project {destination}.", self._caplog.text)
45+
self.assertIn(f"Uploading 3 annotations from {self.S3_FOLDER_PATH} to the project {destination}.",
46+
self._caplog.text)
4647

4748
uploaded_annotations, _, _ = sa.upload_preannotations_from_folder_to_project(destination,
48-
self.S3_FOLDER_PATH,
49-
from_s3_bucket="superannotate-python-sdk-test",
50-
recursive_subfolders=False)
49+
self.S3_FOLDER_PATH,
50+
from_s3_bucket="superannotate-python-sdk-test",
51+
recursive_subfolders=False)
5152
self.assertEqual(len(s3_bucket.method_calls), 12)
5253
self.assertIn(f"Uploading 3 annotations from {self.S3_FOLDER_PATH} to the project {destination}.",
5354
self._caplog.text)
5455

55-
5656
@pytest.mark.flaky(reruns=2)
5757
def test_annotation_upload_pixel(self):
5858
sa.upload_images_from_folder_to_project(self.PROJECT_NAME, self.folder_path)
@@ -67,7 +67,6 @@ def test_annotation_upload_pixel(self):
6767
)
6868

6969

70-
7170
class TestAnnotationUploadPixelSingle(BaseTestCase):
7271
PROJECT_NAME = "TestAnnotationUploadPixelSingle"
7372
PROJECT_DESCRIPTION = "Desc"
@@ -83,7 +82,7 @@ def folder_path_pixel(self):
8382

8483
@pytest.mark.flaky(reruns=2)
8584
@patch("lib.core.usecases.annotations.UploadAnnotationUseCase.s3_bucket")
86-
def test_annotation_upload_pixel(self,s3_bucket):
85+
def test_annotation_upload_pixel(self, s3_bucket):
8786
annotation_path = join(self.folder_path_pixel, f"{self.IMAGE_NAME}___pixel.json")
8887
sa.upload_image_to_project(self.PROJECT_NAME, join(self.folder_path_pixel, self.IMAGE_NAME))
8988
sa.upload_image_annotations(self.PROJECT_NAME, self.IMAGE_NAME, annotation_path)

0 commit comments

Comments
 (0)