o
    iB                     @  sj   d dl mZ d dlZd dlmZ d dlmZmZ d dlm	Z	 g dZ
	ddddZdddZdddZdS )    )annotationsN)
BundleAlgo)algo_from_picklealgo_to_pickle)AlgoKeys)import_bundle_algo_historyexport_bundle_algo_historyget_name_from_algo_id.Toutput_folderstrtemplate_path
str | Noneonly_trainedboolreturnlistc                 C  s   g }t t| D ]\}tj| |}tj|sq	tj|d}tj|s'q	t||d\}}|t	j
d}	|	du rJz| }	W n	 tyI   Y nw |	du}
|rR|
sT|se|t	j|t	j|t	j
|	t	j|
i q	|S )a  
    import the history of the bundleAlgo objects as a list of algo dicts.
    each algo_dict has keys name (folder name), algo (bundleAlgo), is_trained (bool),

    Args:
        output_folder: the root path of the algorithms templates.
        template_path: the algorithm_template. It must contain algo.py in the follow path:
            ``{algorithm_templates_dir}/{network}/scripts/algo.py``.
        only_trained: only read the algo history if the algo is trained.
    zalgo_object.pklr   N)sortedoslistdirpathjoinisdirisfiler   getr   SCORE	get_scoreBaseExceptionappendIDALGO
IS_TRAINED)r   r   r   historynameZ
write_pathobj_filenamealgoalgo_meta_databest_metric
is_trained r*   \/home/dell461/cl/sdc2/last_ska_mid/HISourceFinder-master-l/src/monai/apps/auto3dseg/utils.pyr      s.   r   r#   list[dict[str, BundleAlgo]]Nonec                 C  s&   | D ]}|t j }t||jd qdS )z
    Save all the BundleAlgo in the history to algo_object.pkl in each individual folder

    Args:
        history: a List of Bundle. Typically, the history can be obtained from BundleGen get_history method
    r   N)r   r!   r   r   )r#   	algo_dictr&   r*   r*   r+   r   D   s   
r   idc                 C  s   |  dd S )z
    Get the name of Algo from the identifier of the Algo.

    Args:
        id: identifier which follows a convention of "name_fold_other".

    Returns:
        name of the Algo.
    _r   )split)r/   r*   r*   r+   r	   P   s   
r	   )r
   NT)r   r   r   r   r   r   r   r   )r#   r,   r   r-   )r/   r   r   r   )
__future__r   r   monai.apps.auto3dseg.bundle_genr   monai.auto3dsegr   r   monai.utils.enumsr   __all__r   r   r	   r*   r*   r*   r+   <module>   s   
-