import matplotlib.pyplot as plt
from scipy import stats
import numpy as np
import pickle
from logging_utils import logger
from argparse import ArgumentParser

SMALLEST_SIZE = 5
SMALL_SIZE = 7
MEDIUM_SIZE = 7
BIGGER_SIZE = 7
plt.rc('font', size=SMALLEST_SIZE, family="Times New Roman")
plt.rc('axes', titlesize=SMALL_SIZE)
plt.rc('axes', labelsize=SMALL_SIZE)
plt.rc('xtick', labelsize=SMALL_SIZE)
plt.rc('ytick', labelsize=SMALL_SIZE)
plt.rc('legend', fontsize=SMALLEST_SIZE)
plt.rc('figure', titlesize=BIGGER_SIZE, figsize=(7/4,21/16))

def load_and_95th_ci(path):
    # Python list of scores
    with open(f"results/{path}.pkl", 'rb') as f:
        data = pickle.load(f)

    mean_score = np.mean(data)

    lower_ci, upper_ci = stats.t.interval(confidence=0.95, df=len(data)-1, loc=mean_score, scale=stats.sem(data))

    logger.info((f"CI INFO: {mean_score=}, {lower_ci=}, {upper_ci=}, {upper_ci - mean_score}"))

    return mean_score, lower_ci, upper_ci

parser = ArgumentParser()
parser.add_argument("results_path")
args, _ = parser.parse_known_args()

load_and_95th_ci(args.results_path)
