import glob


def split_files(filepath="../features/"):
    """Reads in pickle data files and splits into training and test files based on phase diagram cutoffs.
    Keyword Args:
        filepath (str): Path to feature data.
    Returns:
        other_files (list[str]): List of simulation files not used in training.
        train_files (list[str]]): List of simulation files used for training.
    """
    # Read in all feature files
    all_files = glob.glob(filepath + "*.pkl")

    # Remove the path
    all_files = [all_files[i].split("/")[-1] for i in range(len(all_files))]

    train_files = []
    for file in all_files:
        phi = float(file.split("_")[1])
        t = float(file.split("_")[3])

        if (
            ((t > 12) and (phi >= 0.78))
            or ((t > 12) and (phi <= 0.32))
        ):
            train_files.append(file)
    # Define other files
    other_files = [x for x in all_files if x not in train_files]

    return other_files, train_files