import os
import json
import click
from glob import glob
import numpy as np


def get_cor(paths):
    res = []
    for path in paths:
        res.append(json.load(open(path))["final_success"])
    return res


@click.command()
@click.option("--path", prompt="Path to the results")
@click.option("--save_path", default=None)
def main(path, save_path):
    all_envs = glob(os.path.join(path, "env-*.json"))
    cor = get_cor(all_envs)
    print("Cor:", np.sum(cor), " out of ", len(cor))


if __name__ == "__main__":
    main()
