# python3 -I 05_versions.py <repo>: compares versions of the test set; counts only.
import sys, json, subprocess, collections, hashlib
repo=sys.argv[1]
def show(c,p): return subprocess.run(['git','-C',repo,'show',f'{c}:{p}'],capture_output=True,check=True).stdout
cur=json.loads(show('624efc5','data/test/test_set.json'))
old=json.loads(show('459e02d','data/test/test_set.json'))
print('459e02d n',len(old),'identical to current',old==cur, 'sha',hashlib.sha256(show('459e02d','data/test/test_set.json')).hexdigest()[:16])
key=lambda d:(d['book'],d['plot']['i_p'],d['i_c'])
K={key(d):d for d in old}
diff=collections.Counter(); missing=0
for d in cur:
    o=K.get(key(d))
    if o is None: missing+=1; continue
    for k in set(d)|set(o):
        if d.get(k)!=o.get(k): diff[k]+=1
print('fields differing old vs current',diff,'missing',missing)
ids=json.loads(show('624efc5','test_data/test_circumstance_id.json')); ood=json.loads(show('624efc5','test_data/test_circumstance_ood.json'))
diff=collections.Counter()
for a,b in zip(ids+ood,cur):
    for k in set(a)|set(b):
        if a.get(k)!=b.get(k): diff[k]+=1
print('test_data vs test_set differing fields',diff)
# when did these test_data files appear
print(subprocess.run(['git','-C',repo,'log','--format=%h %ad %s','--date=short','--','test_data'],capture_output=True,text=True).stdout)
print('held_out', len(json.loads(show('624efc5','data/test/held_out_plots.json'))))
# paper claim: 13.2 utterances, etc.
print('weight present',sum(1 for d in cur if 'weight' in d))
