import pickle


def load_res_file(meta, metric, version, target):
    """Locates pickle obj for a given metric, loads and stores into variable
    Returns res_file (loaded pickle object).
    Ex: keras_file = load_res_file("history", "v0", "mem_bin")
    loads from: "./data/2021-05-06-1620351000/results/mem_bin/history"
    """
    datestring = meta[version]["date"]
    res_file = f"data/{datestring}/results/{target}/{metric}"
    # print(f"{metric} file located: \n{res_file}")
    res_data = pickle.load(open(res_file, "rb"))
    return res_data