# rec2json1880.py -- turn the last "New record" line of a rwang1880 run into the JSON shape verify1880.py checks import sys, json, re n = int(sys.argv[2]); lines = [l for l in open(sys.argv[1], encoding='utf-8') if 'New record' in l] last = lines[-1]; L = int(re.search(r'New record: (\d+)', last).group(1)) res = {int(p): int(r) for r, p in re.findall(r'(\d+)/(\d+)', last)} t = float(re.search(r' t ([\d.]+)', last).group(1)); rs = int(re.search(r'restart (\d+)', last).group(1)) out = dict(n=n, best_run=(L - 5) // 6, best_length=L, residues={str(p): r for p, r in res.items()}, t=t, restart=rs, records=len(lines)) json.dump(out, open(sys.argv[3], 'w'), indent=0); print(sys.argv[3], L, 't', t, 'restart', rs, 'records', len(lines))