import re
import glob


def get_mtmanager_trial_files(mtmanager_trial_path, extension=".csv"):
    """Find all files of an mtmanager trial inside a directory.

    Args:
        mtmanager_trial_path(str): path to the trial directory
            containing mtmanager files.

    Returns:
        (dict[str, str]): dict with mtmanager sensor serial-number as
            keys and respective data paths as values.

    """
    mtmanager_file_paths = dict()
    sensor_name_pattern = re.compile(".*_(.*).csv")
    for f in sorted(glob.glob(mtmanager_trial_path + "/*" + extension)):
        match = re.match(sensor_name_pattern, f)
        if match is not None:
            sensor_id = match.group(1).upper()
            mtmanager_file_paths[sensor_id] = f
    return mtmanager_file_paths