import json,glob,sys,numpy as np
R=sys.argv[1]
W='saebench_gemma-2-2b_width-2pow16_date-0108'
fs=sorted(glob.glob(f'{R}/sparse_probing/{W}/*.json'))
mx=0
for f in fs:
    d=json.load(open(f))
    agg=d['eval_result_metrics']['sae']['sae_top_1_test_accuracy']
    det=d['eval_result_details']
    dsm=np.mean([e['sae_top_1_test_accuracy'] for e in det])
    un=d['eval_result_unstructured']
    um=np.mean([x for v in un.values() for x in v['sae_top_1_test_accuracy'].values()])
    dm=np.mean([np.mean(list(v['sae_top_1_test_accuracy'].values())) for v in un.values()])
    n=[len(v['sae_top_1_test_accuracy']) for v in un.values()]
    mx=max(mx,abs(dsm-agg))
    print(f.split('0108_')[-1][:40],round(agg,5),round(um,5),round(dsm,5),round(dm,5),n)
print('max |details-mean-of-datasets - agg|',mx)
d=json.load(open(fs[0]));print([ (e['dataset_name'],e['sae_top_1_test_accuracy']) for e in d['eval_result_details']])
