@@ -1037,7 +1037,6 @@ def validate_project_type(self):
10371037
10381038 def execute (self ):
10391039 if self .is_valid ():
1040- self .reporter .disable_info ()
10411040 response = GetAnnotations (
10421041 config = self ._config ,
10431042 reporter = Reporter (log_info = False ),
@@ -1046,10 +1045,9 @@ def execute(self):
10461045 item_names = [self ._video_name ],
10471046 service_provider = self ._service_provider ,
10481047 ).execute ()
1049- self .reporter .enable_info ()
10501048 if response .data :
10511049 generator = VideoFrameGenerator (response .data [0 ], fps = self ._fps )
1052- self . reporter . log_info (
1050+ logger . info (
10531051 f"Getting annotations for { generator .frames_count } frames from { self ._video_name } ."
10541052 )
10551053 if response .errors :
@@ -1412,21 +1410,10 @@ def validate_item_names(self):
14121410 self ._item_names = [
14131411 i for i in self ._item_names if not (i in seen or seen .add (i ))
14141412 ]
1415- elif self ._item_names is None :
1416- self ._item_names_provided = False
1417- condition = Condition ("project_id" , self ._project .id , EQ ) & Condition (
1418- "folder_id" , self ._folder .id , EQ
1419- )
1420-
1421- self ._item_names = [
1422- item .name for item in self ._service_provider .items .list (condition ).data
1423- ]
1424- else :
1425- self ._item_names = []
14261413
14271414 def _prettify_annotations (self , annotations : List [dict ]):
14281415 re_struct = {}
1429- if self ._item_names_provided :
1416+ if self ._item_names :
14301417 for annotation in annotations :
14311418 re_struct [annotation ["metadata" ]["name" ]] = annotation
14321419 try :
@@ -1499,12 +1486,12 @@ async def run_workers(
14991486 )
15001487 if small_annotations :
15011488 self ._small_annotations_queue = asyncio .Queue ()
1502- small_chunks = divide_to_chunks (
1503- small_annotations , size = self ._config .ANNOTATION_CHUNK_SIZE
1504- )
1505- for chunk in small_chunks :
1506- self ._small_annotations_queue .put_nowait (chunk )
1507- self ._small_annotations_queue .put_nowait (None )
1489+ small_chunks = divide_to_chunks (
1490+ small_annotations , size = self ._config .ANNOTATION_CHUNK_SIZE
1491+ )
1492+ for chunk in small_chunks :
1493+ self ._small_annotations_queue .put_nowait (chunk )
1494+ self ._small_annotations_queue .put_nowait (None )
15081495
15091496 annotations .extend (
15101497 list (
@@ -1528,19 +1515,25 @@ def execute(self):
15281515 self ._project , self ._folder , self ._item_names
15291516 )
15301517 )
1531- else :
1518+ len_items , len_provided_items = len (items ), len (self ._item_names )
1519+ if len_items != len_provided_items :
1520+ self .reporter .log_warning (
1521+ f"Could not find annotations for { len_provided_items - len_items } /{ len_provided_items } items."
1522+ )
1523+ elif self ._item_names is None :
15321524 condition = Condition ("project_id" , self ._project .id , EQ ) & Condition (
15331525 "folder_id" , self ._folder .id , EQ
15341526 )
15351527 items = get_or_raise (self ._service_provider .items .list (condition ))
1528+ else :
1529+ items = []
15361530 id_item_map = {i .id : i for i in items }
1537-
15381531 if not items :
15391532 logger .info ("No annotations to download." )
15401533 self ._response .data = []
15411534 return self ._response
15421535 items_count = len (items )
1543- logger . info (
1536+ self . reporter . log_info (
15441537 f"Getting { items_count } annotations from "
15451538 f"{ self ._project .name } { f'/{ self ._folder .name } ' if self ._folder .name != 'root' else '' } ."
15461539 )
@@ -1563,12 +1556,8 @@ def execute(self):
15631556 logger .error (e )
15641557 self ._response .errors = AppException ("Can't get annotations." )
15651558 return self ._response
1566- received_items_count = len (annotations )
15671559 self .reporter .finish_progress ()
1568- if items_count > received_items_count :
1569- self .reporter .log_warning (
1570- f"Could not find annotations for { items_count - received_items_count } /{ items_count } items."
1571- )
1560+
15721561 self ._response .data = self ._prettify_annotations (annotations )
15731562 return self ._response
15741563
0 commit comments