cocogni4d / code /tools /find_content_fp.py
VEHwang's picture
Upload CoCogni4D-Bench (questions, media, scripts, render records, code) (part 7)
7ff74f6 verified
Raw History Blame Contribute Delete
1.9 kB
#!/usr/bin/env python3
"""Read-only: for every file that will change, compute content digests other than the raw-byte sha256
(canonical JSON variants, facts capability composite) and report where those digests are embedded."""
import hashlib, json, collections as C
from pathlib import Path
H = Path('${LOCAL}/simulation-workspace/runs/hf-release-20261120')
res = {x['rel']: x for x in json.load(open(H / 'work/scan.json'))}
g = json.load(open(H / 'work/graph.json')); ch = g['changed']
where = {}
for x in res.values():
for h in x['hashes']: where.setdefault(h, []).append(x['rel'])
sha = lambda b: hashlib.sha256(b).hexdigest()
V = {'sort_ea': lambda o: json.dumps(o, sort_keys=True, ensure_ascii=False).encode(),
'sort_compact': lambda o: json.dumps(o, sort_keys=True, separators=(',', ':'), ensure_ascii=False).encode(),
'sort_compact_ascii': lambda o: json.dumps(o, sort_keys=True, separators=(',', ':')).encode(),
'sort_ascii': lambda o: json.dumps(o, sort_keys=True).encode(),
'plain': lambda o: json.dumps(o, ensure_ascii=False).encode()}
hits = C.Counter(); ex = {}
for rel in ch:
if not rel.endswith('.json'): continue
p = Path(res[rel]['root']) / rel
try: o = json.loads(p.read_bytes())
except Exception: continue
for name, f in V.items():
d = sha(f(o))
for r in where.get(d, []):
k = (name, rel.split('/')[0] + '/' + rel.split('/')[-1], r.split('/')[0] + '/' + r.split('/')[-1])
hits[k] += 1; ex.setdefault(k, (rel, r))
if rel.endswith('/capability.json'):
sb = p.parent / 'static-bands.npz'
d = sha(p.read_bytes() + sb.read_bytes())
for r in where.get(d, []):
k = ('cap+static', rel.split('/')[-1], r.split('/')[0] + '/' + r.split('/')[-1]); hits[k] += 1; ex.setdefault(k, (rel, r))
for k, n in hits.most_common(): print(n, k, ex[k])
print('done', len(hits))