import re


def extract_seed_date_from_path(p, yes_base, no_base):
    """ Extracts random seed and date from path of ABIDES output file

    :param p: path from which to extract seed and date
    :param yes_base: regex pattern for output files WITH execution agent. Must obey the following:
        - contains the string `yes` and not contain the string `no`
        - pattern must contain two capture groups, where the first captures seed, second captures POV, and third
        captures date.
        If the above are not satisfied you will have to rename experimental output files.
    :param no_base: regex pattern for output files WITHOUT execution agent. Must obey the following:
        - contains the string `no` and not contain the string `yes`
        - pattern must contain two capture groups, where the first captures seed, second captures date.
        If the above are not satisfied you will have to rename experimental output files.
    :return:
    """
    base = yes_base if 'yes' in p else no_base
    yes_no = 'yes' if 'yes' in p else 'no'

    m = re.search(base, p)

    if yes_no == 'yes':
        seed = m.group(1)
        pov = m.group(2)
        date = m.group(3)
        out_dict = {
            'type': yes_no,
            'seed': seed,
            'pov': pov,
            'date': date
        }
        return out_dict
    elif yes_no == 'no':
        seed = m.group(1)
        date = m.group(2)
        out_dict = {
            'type': yes_no,
            'seed': seed,
            'date': date
        }
        return out_dict
    else:
        raise ValueError(f'Path {p} not in required format')