1515from pathlib import Path
1616from typing import Iterable
1717from typing import List
18+ from typing import Optional
1819
1920import boto3
2021import cv2
@@ -363,6 +364,9 @@ def execute(self):
363364 ] = new_project_annotation_classes .insert (annotation_class_copy )
364365
365366 if self ._include_contributors :
367+ self ._project = self ._projects .get_one (
368+ uuid = self ._project .uuid , team_id = self ._project .team_id
369+ )
366370 for user in self ._project .users :
367371 self ._backend_service .share_project (
368372 project .uuid ,
@@ -504,7 +508,7 @@ class UploadImageS3UseCase(BaseUseCase):
504508 def __init__ (
505509 self ,
506510 project : ProjectEntity ,
507- project_settings : BaseReadOnlyRepository ,
511+ project_settings : List [ ProjectSettingEntity ] ,
508512 image_path : str ,
509513 image : io .BytesIO ,
510514 s3_repo : BaseManageableRepository ,
@@ -535,7 +539,7 @@ def execute(self):
535539 huge_image , huge_width , huge_height = image_processor .generate_huge ()
536540 quality = 60
537541 if not self ._image_quality_in_editor :
538- for setting in self ._project_settings . get_all () :
542+ for setting in self ._project_settings :
539543 if setting .attribute == "ImageQuality" :
540544 quality = setting .value
541545 else :
@@ -679,7 +683,11 @@ def execute(self):
679683 folder_id = self ._folder .uuid ,
680684 images = [image .name for image in self ._attachments ],
681685 )
682- duplications = [image ["name" ] for image in duplications ]
686+ try :
687+ duplications = [image ["name" ] for image in duplications ]
688+ except Exception :
689+ print (duplications )
690+ raise
683691 meta = {}
684692 to_upload = []
685693 for image in self ._attachments :
@@ -1062,7 +1070,7 @@ def execute(self):
10621070 headers = annotations ["annotation_json_path" ]["headers" ],
10631071 )
10641072 if not response .ok :
1065- raise AppException (f "Couldn't load annotations." )
1073+ raise AppException ("Couldn't load annotations." )
10661074
10671075 image_annotations = response .json ()
10681076 from_project_annotation_classes = (
@@ -1153,7 +1161,7 @@ def execute(self):
11531161 headers = annotations ["annotation_bluemap_path" ]["headers" ],
11541162 )
11551163 if not response .ok :
1156- raise AppException (f "Couldn't load annotations." )
1164+ raise AppException ("Couldn't load annotations." )
11571165 self .to_project_s3_repo .insert (
11581166 S3FileEntity (
11591167 auth_data ["annotation_bluemap_path" ]["filePath" ], response .content
@@ -2077,12 +2085,15 @@ def execute(self):
20772085 file_postfix = "___objects.json"
20782086 else :
20792087 file_postfix = "___pixel.json"
2088+ data ["annotation_mask_filename" ] = f"{ self ._image_name } ___save.png"
2089+ data ["annotation_json_filename" ] = f"{ self ._image_name } { file_postfix } "
2090+
20802091 response = requests .get (
20812092 url = credentials ["annotation_json_path" ]["url" ],
20822093 headers = credentials ["annotation_json_path" ]["headers" ],
20832094 )
20842095 if not response .ok :
2085- logger .warning (f "Couldn't load annotations." )
2096+ logger .warning ("Couldn't load annotations." )
20862097 self ._response .data = data
20872098 return self ._response
20882099 data ["annotation_json" ] = response .json ()
@@ -2094,7 +2105,6 @@ def execute(self):
20942105 headers = annotation_blue_map_creds ["headers" ],
20952106 )
20962107 data ["annotation_mask" ] = io .BytesIO (response .content )
2097- data ["annotation_mask_filename" ] = f"{ self ._image_name } ___save.png"
20982108
20992109 self ._response .data = data
21002110
@@ -2177,7 +2187,7 @@ def execute(self):
21772187 url = annotation_json_creds ["url" ], headers = annotation_json_creds ["headers" ],
21782188 )
21792189 if not response .ok :
2180- raise AppException (f "Couldn't load annotations." )
2190+ raise AppException ("Couldn't load annotations." )
21812191 data ["preannotation_json" ] = response .json ()
21822192 data ["preannotation_json_filename" ] = f"{ self ._image_name } { file_postfix } "
21832193 if self ._project .project_type == constances .ProjectType .PIXEL .value :
@@ -2254,7 +2264,7 @@ def execute(self):
22542264 headers = annotation_json_creds ["headers" ],
22552265 )
22562266 if not response .ok :
2257- logger .warning (f "Couldn't load annotations." )
2267+ logger .warning ("Couldn't load annotations." )
22582268 self ._response .data = (None , None )
22592269 return self ._response
22602270 data ["annotation_json" ] = response .json ()
@@ -2333,7 +2343,7 @@ def execute(self):
23332343 url = annotation_json_creds ["url" ], headers = annotation_json_creds ["headers" ],
23342344 )
23352345 if not response .ok :
2336- raise AppException (f "Couldn't load annotations." )
2346+ raise AppException ("Couldn't load annotations." )
23372347 data ["preannotation_json" ] = response .json ()
23382348 data ["preannotation_json_filename" ] = f"{ self ._image_name } { file_postfix } "
23392349 mask_path = None
@@ -3277,10 +3287,11 @@ def __init__(
32773287 self ,
32783288 project : ProjectEntity ,
32793289 folder : FolderEntity ,
3280- annotation_classes : BaseReadOnlyRepository ,
3290+ annotation_classes : List [ AnnotationClassEntity ] ,
32813291 folder_path : str ,
32823292 annotation_paths : List [str ],
32833293 backend_service_provider : SuerannotateServiceProvider ,
3294+ templates : List [dict ],
32843295 pre_annotation : bool = False ,
32853296 client_s3_bucket = None ,
32863297 ):
@@ -3293,6 +3304,7 @@ def __init__(
32933304 self ._annotation_paths = annotation_paths
32943305 self ._client_s3_bucket = client_s3_bucket
32953306 self ._pre_annotation = pre_annotation
3307+ self ._templates = templates
32963308
32973309 @property
32983310 def s3_client (self ):
@@ -3301,7 +3313,7 @@ def s3_client(self):
33013313 @property
33023314 def annotation_classes_name_map (self ) -> dict :
33033315 classes_data = defaultdict (dict )
3304- annotation_classes = self ._annotation_classes . get_all ()
3316+ annotation_classes = self ._annotation_classes
33053317 for annotation_class in annotation_classes :
33063318 class_info = {"id" : annotation_class .uuid }
33073319 if annotation_class .attribute_groups :
@@ -3327,11 +3339,8 @@ def annotation_postfix(self):
33273339 )
33283340
33293341 def get_templates_mapping (self ):
3330- templates = self ._backend_service .get_templates (
3331- team_id = self ._project .team_id
3332- ).get ("data" , [])
33333342 templates_map = {}
3334- for template in templates :
3343+ for template in self . _templates :
33353344 templates_map [template ["name" ]] = template ["id" ]
33363345 return templates_map
33373346
@@ -4276,7 +4285,7 @@ def __init__(
42764285 self ._project = project
42774286 self ._folder = folder
42784287 self ._folder_path = folder_path
4279- self ._settings = settings
4288+ self ._settings = settings . get_all ()
42804289 self ._s3_repo = s3_repo
42814290 self ._backend_client = backend_client
42824291 self ._image_quality_in_editor = image_quality_in_editor
@@ -4486,6 +4495,59 @@ def execute(self):
44864495 return self ._response
44874496
44884497
4498+ class DeleteAnnotations (BaseUseCase ):
4499+ POLL_AWAIT_TIME = 2
4500+
4501+ def __init__ (
4502+ self ,
4503+ project : ProjectEntity ,
4504+ folder : FolderEntity ,
4505+ backend_service : SuerannotateServiceProvider ,
4506+ image_names : Optional [List [str ]] = None ,
4507+ ):
4508+ super ().__init__ ()
4509+ self ._project = project
4510+ self ._folder = folder
4511+ self ._image_names = image_names
4512+ self ._backend_service = backend_service
4513+
4514+ def execute (self ) -> Response :
4515+
4516+ if self ._folder .name == "root" and not self ._image_names :
4517+ poll_id = self ._backend_service .delete_image_annotations (
4518+ project_id = self ._project .uuid , team_id = self ._project .team_id ,
4519+ )
4520+ else :
4521+ poll_id = self ._backend_service .delete_image_annotations (
4522+ project_id = self ._project .uuid ,
4523+ team_id = self ._project .team_id ,
4524+ folder_id = self ._folder .uuid ,
4525+ image_names = self ._image_names ,
4526+ )
4527+
4528+ if poll_id :
4529+ timeout_start = time .time ()
4530+ while time .time () < timeout_start + self .POLL_AWAIT_TIME :
4531+ progress = int (
4532+ self ._backend_service .get_annotations_delete_progress (
4533+ project_id = self ._project .uuid ,
4534+ team_id = self ._project .team_id ,
4535+ poll_id = poll_id ,
4536+ ).get ("process" , - 1 )
4537+ )
4538+ if 0 < progress < 100 :
4539+ logger .info (f"Delete annotations in progress { progress } /100" )
4540+ elif 0 > progress :
4541+ self ._response .errors = "Annotations delete fails."
4542+ break
4543+ else :
4544+ logger .info (f"Annotations deleted" )
4545+ break
4546+ else :
4547+ self ._response .errors = AppException ("Invalid image names." )
4548+ return self ._response
4549+
4550+
44894551
44904552class GetDuplicateImages (BaseUseCase ):
44914553 def __init__ (self ,
0 commit comments