@@ -123,9 +123,10 @@ def _construct_data_file_id_name_map(self):
123123 if item ["@type" ] != "File" :
124124 continue
125125 id = item ["@id" ]
126- if "alternateName" not in item :
127- continue
128- alternate_name = item ["alternateName" ]
126+ #if "alternateName" not in item:
127+ # continue
128+ #alternate_name = item["alternateName"]
129+ alternate_name = item .get ("alternateName" , id )
129130 self .data_file_id_name_map [id ] = alternate_name
130131
131132
@@ -137,7 +138,8 @@ def _create_tasks(self, create_actions, main_workflow_id):
137138
138139 for create_action in create_actions :
139140 # Handle overall workflow create_action then skip
140- if create_action ["name" ] == f"Run of workflow/{ main_workflow_id } " :
141+ if ("Run of workflow" in create_action ["name" ] or
142+ "workflow run" in create_action ["name" ]):
141143 self ._process_main_workflow (create_action )
142144 continue
143145
@@ -154,8 +156,8 @@ def _create_tasks(self, create_actions, main_workflow_id):
154156 continue
155157
156158 # Get all input & output for the create_action
157- input = [obj ['@id' ] for obj in create_action ['object' ]]
158- output = [obj ['@id' ] for obj in create_action ['result' ]]
159+ input = [obj ['@id' ] if isinstance ( obj , dict ) else obj for obj in create_action ['object' ]]
160+ output = [obj ['@id' ] if isinstance ( obj , dict ) else obj for obj in create_action ['result' ]]
159161
160162 # Filter for actual files
161163 input_files = self ._filter_file_ids (input )
@@ -166,8 +168,8 @@ def _create_tasks(self, create_actions, main_workflow_id):
166168 # task_id=create_action['name'],
167169 task_id = create_action ['name' ] + "_" + create_action ['@id' ],
168170 task_type = TaskType .COMPUTE ,
169- runtime = self ._time_diff (create_action [ 'startTime' ] , create_action [ 'endTime' ] ),
170- executed_at = create_action [ 'startTime' ] ,
171+ runtime = self ._time_diff (create_action . get ( 'startTime' ) , create_action . get ( 'endTime' ) ),
172+ executed_at = create_action . get ( 'startTime' , '' ) ,
171173 input_files = self ._get_file_objects (input_files ),
172174 output_files = self ._get_file_objects (output_files ),
173175 logger = self .logger )
@@ -193,10 +195,11 @@ def _create_tasks(self, create_actions, main_workflow_id):
193195 files [outfile ]['out' ].append (create_action ['@id' ])
194196
195197 # For each task, track which 'instrument' it uses
196- instrument = create_action ['instrument' ]['@id' ]
197- if instrument not in instruments :
198- instruments [instrument ] = []
199- instruments [instrument ].append (create_action ['@id' ])
198+ if create_action .get ('instrument' ):
199+ instrument = create_action ['instrument' ]['@id' ]
200+ if instrument not in instruments :
201+ instruments [instrument ] = []
202+ instruments [instrument ].append (create_action ['@id' ])
200203
201204 self ._add_dependencies (files , instruments )
202205
@@ -231,6 +234,8 @@ def _add_dependencies(self, files, instruments):
231234 self .workflow .add_dependency (self .task_id_name_map [parent ], self .task_id_name_map [child ])
232235
233236 def _time_diff (self , start_time , end_time ):
237+ if not start_time or not end_time :
238+ return 0.0
234239 diff = datetime .fromisoformat (end_time ) - datetime .fromisoformat (start_time )
235240 return diff .total_seconds ()
236241
@@ -239,19 +244,38 @@ def _get_file_objects(self, files):
239244 output = []
240245 for file in files :
241246 if file not in self .file_objects :
242- self .file_objects [file ] = File (file_id = self .data_file_id_name_map [file ],
243- size = os .path .getsize (f"{ self .crate_dir } /{ file } " ),
244- logger = self .logger )
247+ #self.file_objects[file] = File(file_id=self.data_file_id_name_map[file],
248+ # size=os.path.getsize(f"{self.crate_dir}/{file}"),
249+ # logger=self.logger)
250+ if file not in self .data_file_id_name_map :
251+ # File is referenced but not in the map — use its @id as the name
252+ self .logger .warning (f"File not in data_file_id_name_map, using @id as name: { file } " ) if self .logger else None
253+ file_name = file
254+ else :
255+ file_name = self .data_file_id_name_map [file ]
256+ try :
257+ size = os .path .getsize (f"{ self .crate_dir } /{ file } " )
258+ except (OSError , ValueError ):
259+ size = 0 # file:// absolute paths won't resolve relative to crate_dir
260+ self .file_objects [file ] = File (file_id = file_name ,
261+ size = size ,
262+ logger = self .logger )
245263 output .append (self .file_objects [file ])
246264 return output
247265
248266 def _filter_file_ids (self , ids ):
249267
250- file_ids = list (filter (lambda x : self .lookup .get (x )['@type' ] == 'File' , ids ))
251- property_value_ids = list (filter (lambda x : self .lookup .get (x )['@type' ] == 'PropertyValue' , ids ))
268+ file_ids = list (filter (lambda x : (self .lookup .get (x ) or {}).get ('@type' ) == 'File' , ids ))
269+ # Ignore the files that start with http:// or https://
270+ file_ids = [x for x in file_ids if not x .startswith ("http://" )]
271+ file_ids = [x for x in file_ids if not x .startswith ("https://" )]
272+ property_value_ids = list (filter (lambda x : (self .lookup .get (x ) or {}).get ('@type' ) == 'PropertyValue' , ids ))
252273 for property_value_id in property_value_ids :
253274 property_values = self .lookup .get (property_value_id )['value' ]
254- if isinstance (property_values , dict ):
275+ # If the lookup fails, ignore
276+ if not property_values :
277+ continue
278+ if not isinstance (property_values , list ):
255279 property_values = [property_values ]
256280
257281 # Filter out values without "@id"s (i.e. int values, etc.)
@@ -279,4 +303,4 @@ def _filter_file_ids(self, ids):
279303
280304 def _process_main_workflow (self , main_workflow ):
281305 self .workflow .makespan = self ._time_diff (main_workflow ['startTime' ], main_workflow ['endTime' ])
282- self .workflow .executed_at = main_workflow ['startTime' ]
306+ self .workflow .executed_at = main_workflow ['startTime' ]
0 commit comments