Skip to content

Commit e8244cc

Browse files
committed
validate
1 parent c68a04a commit e8244cc

File tree

2 files changed

+39
-17
lines changed

2 files changed

+39
-17
lines changed

src/superannotate/lib/core/__init__.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,18 @@
8383
ATTACH_USER_LIMIT_ERROR_MESSAGE = "The number of items you want to attach exceeds the limit of your subscription plan."
8484

8585

86-
COPY_FOLDER_LIMIT_ERROR_MESSAGE = "The number of items you want to copy exceeds the limit of 50 000 items per folder."
86+
COPY_FOLDER_LIMIT_ERROR_MESSAGE = (
87+
"The number of items you want to copy exceeds the limit of 50 000 items per folder."
88+
)
8789
COPY_PROJECT_LIMIT_ERROR_MESSAGE = "The number of items you want to copy exceeds the limit of 500 000 items per project."
88-
COPY_SUPER_LIMIT_ERROR_MESSAGE = "The number of items you want to copy exceeds the limit of your subscription plan."
90+
COPY_SUPER_LIMIT_ERROR_MESSAGE = (
91+
"The number of items you want to copy exceeds the limit of your subscription plan."
92+
)
8993

9094

91-
MOVE_FOLDER_LIMIT_ERROR_MESSAGE = "The number of items you want to move exceeds the limit of 50 000 items per folder."
95+
MOVE_FOLDER_LIMIT_ERROR_MESSAGE = (
96+
"The number of items you want to move exceeds the limit of 50 000 items per folder."
97+
)
9298
MOVE_PROJECT_LIMIT_ERROR_MESSAGE = "The number of items you want to move exceeds the limit of 500 000 items per project."
9399

94100
__alL__ = (

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

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -833,14 +833,17 @@ def execute(self):
833833

834834
outline_color = 4 * (255,)
835835
for instance in self.annotations["instances"]:
836-
if (not instance.get("className")) or (not class_color_map.get(instance["className"])):
836+
if (not instance.get("className")) or (
837+
not class_color_map.get(instance["className"])
838+
):
837839
continue
838840
color = class_color_map.get(instance["className"])
839841
if not color:
840842
class_color_map[instance["className"]] = self.generate_color()
841843
for image in images:
842844
fill_color = (
843-
*class_color_map[instance["className"]], 255 if image.type == "fuse" else self.TRANSPARENCY
845+
*class_color_map[instance["className"]],
846+
255 if image.type == "fuse" else self.TRANSPARENCY,
844847
)
845848
if instance["type"] == "bbox":
846849
image.content.draw_bbox(
@@ -909,7 +912,9 @@ def execute(self):
909912
weight, height = image.get_size()
910913
empty_image_arr = np.full((height, weight, 4), [0, 0, 0, 255], np.uint8)
911914
for annotation in self.annotations["instances"]:
912-
if (not annotation.get("className")) or (not class_color_map.get(annotation["className"])):
915+
if (not annotation.get("className")) or (
916+
not class_color_map.get(annotation["className"])
917+
):
913918
continue
914919
fill_color = *class_color_map[annotation["className"]], 255
915920
for part in annotation["parts"]:
@@ -1989,17 +1994,28 @@ def validate_limitations(self):
19891994
if self._move:
19901995
if self._from_project.uuid == self._to_project.uuid:
19911996
if self._from_folder.uuid == self._to_folder.uuid:
1992-
raise AppValidationException("Cannot move image if source_project == destination_project.")
1997+
raise AppValidationException(
1998+
"Cannot move image if source_project == destination_project."
1999+
)
19932000
elif response.data.folder_limit.remaining_image_count < 1:
1994-
raise AppValidationException(constances.MOVE_FOLDER_LIMIT_ERROR_MESSAGE)
2001+
raise AppValidationException(
2002+
constances.MOVE_FOLDER_LIMIT_ERROR_MESSAGE
2003+
)
19952004
elif response.data.project_limit.remaining_image_count < 1:
1996-
raise AppValidationException(constances.MOVE_PROJECT_LIMIT_ERROR_MESSAGE)
2005+
raise AppValidationException(
2006+
constances.MOVE_PROJECT_LIMIT_ERROR_MESSAGE
2007+
)
19972008
else:
19982009
if response.data.folder_limit.remaining_image_count < 1:
19992010
raise AppValidationException(constances.COPY_FOLDER_LIMIT_ERROR_MESSAGE)
20002011
if response.data.project_limit.remaining_image_count < 1:
2001-
raise AppValidationException(constances.COPY_PROJECT_LIMIT_ERROR_MESSAGE)
2002-
if response.data.super_user_limit and response.data.super_user_limit.remaining_image_count < 1:
2012+
raise AppValidationException(
2013+
constances.COPY_PROJECT_LIMIT_ERROR_MESSAGE
2014+
)
2015+
if (
2016+
response.data.super_user_limit
2017+
and response.data.super_user_limit.remaining_image_count < 1
2018+
):
20032019
raise AppValidationException(constances.COPY_SUPER_LIMIT_ERROR_MESSAGE)
20042020

20052021
def execute(self) -> Response:
@@ -2722,16 +2738,16 @@ def upload_to_s3(
27222738
logger.warning(f"Invalid json {image_id_name_map[image_id].path}")
27232739
return image_id_name_map[image_id], False
27242740
bucket.put_object(
2725-
Key=image_info["annotation_json_path"], Body=json.dumps(annotation_json),
2741+
Key=image_info["annotation_json_path"],
2742+
Body=json.dumps(annotation_json),
27262743
)
27272744
if self._project.project_type == constances.ProjectType.PIXEL.value:
2728-
mask_path = image_id_name_map[image_id].path.replace("___pixel.json", constances.ANNOTATION_MASK_POSTFIX)
2745+
mask_path = image_id_name_map[image_id].path.replace(
2746+
"___pixel.json", constances.ANNOTATION_MASK_POSTFIX
2747+
)
27292748
if from_s3:
27302749
file = io.BytesIO()
2731-
s3_object = from_s3.Object(
2732-
self._client_s3_bucket,
2733-
mask_path
2734-
)
2750+
s3_object = from_s3.Object(self._client_s3_bucket, mask_path)
27352751
s3_object.download_fileobj(file)
27362752
file.seek(0)
27372753
else:

0 commit comments

Comments
 (0)