"""Make disjoint answer sheets from the committed full truth; run in a working directory containing the published inputs."""
import json,hashlib,pathlib,sys
here=pathlib.Path(sys.argv[1]) if len(sys.argv)>1 else pathlib.Path('.')
dest=pathlib.Path(sys.argv[2]) if len(sys.argv)>2 else here
def read(n,h):
 raw=(here/n).read_bytes()
 assert hashlib.sha256(raw).hexdigest()==h
 return json.loads(raw)['cases']
b=read('display_blind_265.json','22213465388ba14a0a7d350baf3f381ce4058952d585bd34d7ffaaf2332d5ed3')
g=read('display_gold_265.json','93c08138eae9044bd7c41312d582f1c4e76a96c6b1d1b1e712e1c48d3caeaacc')
assert {x['id'] for x in b}=={x['id'] for x in g} and len(b)==len(g)==60
s={}
for fold,tag in [('calibration','cal'),('evaluation','eval')]:
 a=[dict(id=x['id'],truth=x['words'][x['gap']-2:x['gap']+2],base_id=x['base'],family=x['family'],in_menu=x['menu']) for x in g if x['fold']==fold]
 s[tag]={x['base_id'] for x in a}
 assert len(a)==30 and len(s[tag])==6 and all(len(x['truth'])==4 for x in a)
 (dest/f'display_{tag}_truth_268.json').write_text(json.dumps({'cases':a},sort_keys=True,separators=(',',':'))+'\n')
assert s['cal'].isdisjoint(s['eval'])
