q2_mlab/doctor.py
def filter_duplicate_parameter_results(
    list_of_artifact_filenames, results_dir, delete=False
):
    """Filter out duplicate results on the same parameter set

    From a sorted list of artifact filenames (sorted by parameter index),
    compare neighboring artifacts and if they are duplicate results on the same
    parameter index, either ignore (delete=False) or delete (delete=True) the
    older of the two duplicate results.

    Parameters
    ----------
    list_of_artifact_filenames : List
        A list of artifact filenames returned by get_results()
    results_dir : str
        The directory containing result artifacts.
    delete : bool, optional
        Delete the duplicate results if ``True``, or ignore them if
        ``False``.

    Returns
    -------
    artifact_filenames : List
        List of the artifact filenames, excluding duplicated results.

    """

    artifact_filenames = list_of_artifact_filenames.copy()

    # Change working dirs
    prev_working_dir = os.getcwd()
    os.chdir(results_dir)

    if len(artifact_filenames) == 0:
        raise ValueError("There are no result artifacts to remove.")
    artifact_filenames = sort_result_artifact_filenames(artifact_filenames)

    curr_path = artifact_filenames[0]
    curr_param_idx = int(curr_path.split("_")[0])

    # From the list of filenames (sorted by parameter index), check if neighboring
    # filenames are of the same parameter index.
    for next_path in artifact_filenames[1:]:
        next_param_idx = int(next_path.split("_")[0])
        if next_param_idx == curr_param_idx:
            # Remove the older of the duplicate results
            curr_path_time = datetime.fromtimestamp(
                os.stat(curr_path).st_mtime
            )
            next_path_time = datetime.fromtimestamp(
                os.stat(next_path).st_mtime
            )
            if curr_path_time < next_path_time:
                artifact_filenames.remove(curr_path)
                if delete:
                    os.remove(curr_path)
            else:
                artifact_filenames.remove(next_path)
                if delete:
                    os.remove(next_path)
                continue  # Do not update current_path
        # Update current path
        curr_path = next_path
        curr_param_idx = next_param_idx

    # Change working dir back
    os.chdir(prev_working_dir)

    return artifact_filenames
Filter out duplicate results on the same parameter set

    From a sorted list of artifact filenames (sorted by parameter index),
    compare neighboring artifacts and if they are duplicate results on the same
    parameter index, either ignore (delete=False) or delete (delete=True) the
    older of the two duplicate results.

    Parameters
    ----------
    list_of_artifact_filenames : List
        A list of artifact filenames returned by get_results()
    results_dir : str
        The directory containing result artifacts.
    delete : bool, optional
        Delete the duplicate results if ``True``, or ignore them if
        ``False``.

    Returns
    -------
    artifact_filenames : List
        List of the artifact filenames, excluding duplicated results.

    
Filter out duplicate results on the same parameter set
From a sorted list of artifact filenames (sorted by parameter index),
compare neighboring artifacts and if they are duplicate results on the same
parameter index, either ignore (delete=False) or delete (delete=True) the
older of the two duplicate results.

Parameters

list_of_artifact_filenames : List
A list of artifact filenames returned by get_results()
results_dir : str
The directory containing result artifacts.

Returns

artifact_filenames : List
List of the artifact filenames, excluding duplicated results.
Filter out duplicate results on the same parameter set From a sorted list of artifact filenames ( sorted by parameter index ) compare neighboring artifacts and if they are duplicate results on the same parameter index either ignore ( delete = False ) or delete ( delete = True ) the older of the two duplicate results . Parameters list_of_artifact_filenames : List A list of artifact filenames returned by get_results () results_dir : str The directory containing result artifacts . Returns artifact_filenames : List List of the artifact filenames excluding duplicated results .
def filter_duplicate_parameter_results(
    list_of_artifact_filenames, results_dir, delete=False
):
    artifact_filenames = list_of_artifact_filenames.copy()
    prev_working_dir = os.getcwd()
    os.chdir(results_dir)
    if len(artifact_filenames) == 0:
        raise ValueError("There are no result artifacts to remove.")
    artifact_filenames = sort_result_artifact_filenames(artifact_filenames)
    curr_path = artifact_filenames[0]
    curr_param_idx = int(curr_path.split("_")[0])
    for next_path in artifact_filenames[1:]:
        next_param_idx = int(next_path.split("_")[0])
        if next_param_idx == curr_param_idx:
            curr_path_time = datetime.fromtimestamp(
                os.stat(curr_path).st_mtime
            )
            next_path_time = datetime.fromtimestamp(
                os.stat(next_path).st_mtime
            )
            if curr_path_time < next_path_time:
                artifact_filenames.remove(curr_path)
                if delete:
                    os.remove(curr_path)
            else:
                artifact_filenames.remove(next_path)
                if delete:
                    os.remove(next_path)
                continue  
        curr_path = next_path
        curr_param_idx = next_param_idx
    os.chdir(prev_working_dir)
    return artifact_filenames
def filter_duplicate_parameter_results ( list_of_artifact_filenames , results_dir , delete = False ) : artifact_filenames = list_of_artifact_filenames . copy ( ) prev_working_dir = os . getcwd ( ) os . chdir ( results_dir ) if len ( artifact_filenames ) == 0 : raise ValueError ( "There are no result artifacts to remove." ) artifact_filenames = sort_result_artifact_filenames ( artifact_filenames ) curr_path = artifact_filenames [ 0 ] curr_param_idx = int ( curr_path . split ( "_" ) [ 0 ] ) for next_path in artifact_filenames [ 1 : ] : next_param_idx = int ( next_path . split ( "_" ) [ 0 ] ) if next_param_idx == curr_param_idx : curr_path_time = datetime . fromtimestamp ( os . stat ( curr_path ) . st_mtime ) next_path_time = datetime . fromtimestamp ( os . stat ( next_path ) . st_mtime ) if curr_path_time < next_path_time : artifact_filenames . remove ( curr_path ) if delete : os . remove ( curr_path ) else : artifact_filenames . remove ( next_path ) if delete : os . remove ( next_path ) continue curr_path = next_path curr_param_idx = next_param_idx os . chdir ( prev_working_dir ) return artifact_filenames
Filter out duplicate results on the same parameter set
From a sorted list of artifact filenames (sorted by parameter index),
compare neighboring artifacts and if they are duplicate results on the same
parameter index, either ignore (delete=False) or delete (delete=True) the
older of the two duplicate results.
Filter out duplicate results on the same parameter set From a sorted list of artifact filenames ( sorted by parameter index ) compare neighboring artifacts and if they are duplicate results on the same parameter index either ignore ( delete = False ) or delete ( delete = True ) the older of the two duplicate results .
"""Filter out duplicate results on the same parameter set

    From a sorted list of artifact filenames (sorted by parameter index),
    compare neighboring artifacts and if they are duplicate results on the same
    parameter index, either ignore (delete=False) or delete (delete=True) the
    older of the two duplicate results.

    Parameters
    ----------
    list_of_artifact_filenames : List
        A list of artifact filenames returned by get_results()
    results_dir : str
        The directory containing result artifacts.
    delete : bool, optional
        Delete the duplicate results if ``True``, or ignore them if
        ``False``.

    Returns
    -------
    artifact_filenames : List
        List of the artifact filenames, excluding duplicated results.

    """ # Change working dirs # From the list of filenames (sorted by parameter index), check if neighboring # filenames are of the same parameter index. # Remove the older of the duplicate results # Do not update current_path # Update current path # Change working dir back
list_of_artifact_filenames
results_dir
delete