22from typing import List
33from diffgram .file .file import File
44from diffgram .job .job import Job
5+ from uuid import uuid4
56
67
78class CompoundChildFile :
@@ -21,6 +22,8 @@ class CompoundChildFile:
2122 assume_new_instances_machine_made : bool
2223 convert_names_to_label_files : bool
2324 video_split_duration : int
25+ local_id : str
26+ ordinal : int
2427
2528 def __init__ (self ,
2629 child_file_type : str ,
@@ -38,7 +41,8 @@ def __init__(self,
3841 frame_packet_map : dict = None ,
3942 assume_new_instances_machine_made : bool = None ,
4043 convert_names_to_label_files : bool = None ,
41- video_split_duration : int = None ):
44+ video_split_duration : int = None ,
45+ ordinal : int = 0 ):
4246 self .child_file_type = child_file_type
4347 self .path = path
4448 self .url = url
@@ -55,6 +59,11 @@ def __init__(self,
5559 self .assume_new_instances_machine_made = assume_new_instances_machine_made
5660 self .convert_names_to_label_files = convert_names_to_label_files
5761 self .video_split_duration = video_split_duration
62+ self .local_id = str (uuid4 ())
63+ self .ordinal = ordinal
64+
65+ def set_ordinal (self , value : int ):
66+ self .ordinal = value
5867
5968
6069class CompoundFile :
@@ -68,6 +77,12 @@ def __init__(self, project: Project, name: str, directory_id: int):
6877 self .directory_id = directory_id
6978 self .child_files_to_upload = []
7079
80+ def __refresh_compound_file_from_data_dict (self , data : dict ):
81+ if not data :
82+ return
83+ for key in data :
84+ setattr (self , key , data [key ])
85+
7186 def remove_compound_file (self , child_file : CompoundChildFile ) -> List [CompoundChildFile ]:
7287 self .child_files_to_upload .remove (child_file )
7388 return self .child_files_to_upload
@@ -83,6 +98,7 @@ def __create_compound_parent_file(self):
8398 self .project .handle_errors (response )
8499 data = response .json ()
85100 self .parent_file_data = data .get ('file' )
101+ self .__refresh_compound_file_from_data_dict (data .get ('file' ))
86102 print ('self,' , self .parent_file_data )
87103 return data .get ('file' )
88104
@@ -125,7 +141,8 @@ def add_child_from_local(self,
125141 instance_list : list = None ,
126142 frame_packet_map : dict = None ,
127143 assume_new_instances_machine_made : bool = True ,
128- convert_names_to_label_files : bool = True ):
144+ convert_names_to_label_files : bool = True ,
145+ ordinal : int = 0 ):
129146 new_child_file = CompoundChildFile (
130147 child_file_type = "from_local" ,
131148 path = path ,
@@ -145,7 +162,8 @@ def add_child_file_from_url(self,
145162 job_id : int = None ,
146163 video_split_duration : int = None ,
147164 instance_list : list = None ,
148- frame_packet_map : dict = None ):
165+ frame_packet_map : dict = None ,
166+ ordinal : int = 0 ):
149167 new_child_file = CompoundChildFile (
150168 child_file_type = "from_url" ,
151169 url = url ,
@@ -167,7 +185,8 @@ def add_child_from_blob_path(self,
167185 media_type : str = 'image' ,
168186 instance_list : list = None ,
169187 file_name : str = None ,
170- frame_packet_map : dict = None
188+ frame_packet_map : dict = None ,
189+ ordinal : int = 0
171190 ):
172191 new_child_file = CompoundChildFile (
173192 child_file_type = "from_blob_path" ,
@@ -184,7 +203,10 @@ def add_child_from_blob_path(self,
184203 return new_child_file
185204
186205 def upload (self ):
206+ if len (self .child_files_to_upload ) == 0 :
207+ raise AssertionError ('Need to add at least one child file to the compound file before calling upload()' )
187208 parent_file_data : dict = self .__create_compound_parent_file ()
209+
188210 for child_file in self .child_files_to_upload :
189211 self .__create_child_file (child_file )
190212 return parent_file_data
0 commit comments