import glob
import json


def load_experiment_results(path, exp_folders, exp_names):
    """
    Load the results of the specified experiments in a dictionnary.
    ----------
    INPUT
        |---- path (str) where the expeiment folder are stored.
        |---- exp_folders (list of str) the folders' name to load.
        |---- exp_names (list of str) the dict keys to use for each experiments.
    OUTPUT
        |---- results_all (dict) the dict containing all the experiement results
        |           (each key is an experiment with repetitions). The value of
        |           the dict is a list of results dict (results of one replicate).
    """
    results_all = {}
    for folder, name in zip(exp_folders, exp_names):
        results = []
        for json_file in glob.glob(path + folder + '/results/*.json'):
            with open(json_file) as fp:
                results.append(json.load(fp))
        results_all[name] = results

    return results_all