"""Package completed anonymous surfaces/views; identity mapping stays sealed.""" from pathlib import Path import csv,hashlib,json,os,shutil,sys,time,resource from zipfile import ZipFile,ZipInfo,ZIP_DEFLATED from g1_blind_geometry import UNITS,validate_pair ROOT=Path('artifacts/s2-g1-blind120-2026-11-14') def sha(p):return hashlib.sha256(p.read_bytes()).hexdigest() def main(): start=time.monotonic();done=json.loads((ROOT/'custodian/batch-complete.json').read_text());assert done['all_pass'] and done['parts']==232 posed_done=json.loads((ROOT/'custodian/pose-batch-complete.json').read_text());assert posed_done['all_pass'] and posed_done['exports']==240 pose_seals=json.loads((ROOT/'public/pose-seals.json').read_text()) assert sha(ROOT/'custodian/pose-plan-v1.json')==pose_seals['pose_plan_sha256'] assert sha(ROOT/'custodian/pose-mapping-v1.json')==pose_seals['pose_mapping_sha256'] mapping=json.loads((ROOT/'custodian/sampling-and-mapping.json').read_text());public=json.loads((ROOT/'public/sample-summary-and-seals.json').read_text()) assert len(mapping['pairs'])==120 and len({r['anonymous_pair_id'] for r in mapping['pairs']})==120 assert len(mapping['unique_cases'])==232 and {r[k] for r in mapping['pairs'] for k in ['a','b']}==set(mapping['unique_cases']) assert len({tuple(sorted((r['a'],r['b']))) for r in mapping['pairs']})==120 for record in public['sealed_files']: assert sha(ROOT/'custodian'/record['file'])==record['sha256'], 'Sealed custody input changed' seal=next(r['sha256'] for r in public['sealed_files'] if r['file']=='sampling-and-mapping.json');assert sha(ROOT/'custodian/sampling-and-mapping.json')==seal bundle=ROOT/'blind-package';bundle.mkdir(exist_ok=False);ids=[];records=[] for row in mapping['pairs']: pid=row['anonymous_pair_id'];ids.append(pid);pair=bundle/'pairs'/pid;views=bundle/'views'/pid;pair.mkdir(parents=True);views.mkdir(parents=True) for side in ['left','right']: src=ROOT/'custodian/posed'/pid/side receipt=json.loads((src/'receipt.json').read_text()) t=receipt['transform'];assert abs(t['determinant']-1)<1e-12 and t['orthogonality_max_abs']<1e-12 assert max(t['edge_error_over_bbox_diagonal'],t['double_area_error_over_bbox_diagonal_squared'])<=1e-10 assert receipt['same_posed_coordinates_for_ply_and_png'] and receipt['archive_reads']==0 for record in receipt['files']: p=src/record['name'];assert p.stat().st_size==record['bytes'] and sha(p)==record['sha256'] shutil.copyfile(src/'surface.ply',pair/f'{side}.ply') for name in ['overview','detail-grid']:shutil.copyfile(src/f'{name}.png',views/f'{side}-{name}.png') (pair/'units.txt').write_text(UNITS) files=[{'name':p.name,'bytes':p.stat().st_size,'sha256':sha(p)} for p in sorted(pair.iterdir())] (pair/'manifest.json').write_text(json.dumps({'format':'blind-surface-pair-v1','anonymous_pair_id':pid,'files':files},indent=2)+'\n');validate_pair(pair) print(json.dumps({'packaged_pairs':len(ids)}),flush=True) if len(ids)%20==0 else None pages=bundle/'review-pairs';pages.mkdir() for pid in ids: (pages/(pid+'.md')).write_text(f'# Anonymous pair {pid}\n\nRelation: unassigned. Record local evidence or unresolved. Original coordinate units; compare axes, not pixel size.\n\n![Left overview](../views/{pid}/left-overview.png)\n\n![Right overview](../views/{pid}/right-overview.png)\n\n![Left fixed detail grid](../views/{pid}/left-detail-grid.png)\n\n![Right fixed detail grid](../views/{pid}/right-detail-grid.png)\n\n[Left full surface](../pairs/{pid}/left.ply) · [Right full surface](../pairs/{pid}/right.ply)\n') (bundle/'review-index.md').write_text('# Anonymous review index\n\nAll labels are blank. Full instructions: [README](README.md). Attestation: [unsigned template](reviewer-attestation.md).\n\n'+'\n'.join(f'- [Pair {i+1}: {pid}](review-pairs/{pid}.md)' for i,pid in enumerate(ids))+'\n') with (bundle/'blank-review.csv').open('w') as f: w=csv.writer(f,lineterminator='\n');w.writerow(['anonymous_pair_id','relation','local_evidence','resolvable','unresolved_reason','reviewer','review_version']) for pid in ids:w.writerow([pid,'','','','','','']) (bundle/'README.md').write_text('''# Geometry-only blind review\n\n120 anonymous pairs. Every relation is unassigned. Do not infer a positive relation from inclusion. Use rigid / template / variant / unrelated / unresolved, and record local geometric evidence. A shared-parent claim requiring source provenance can remain unresolved; no provenance is supplied in this blind view.\n\nOpen index.html locally for uniform views and detail grids; original surface files are in pairs/. Each exported instance has an independent random translation and proper rotation applied for blinding. Original units, physical lengths, boundary triangles and mirror relationships are preserved. No fitted registration, rescaling, reflection or simplification was applied. Source VTU has no explicit physical-unit tag, so axes are original numerical coordinate units, not a universal mm declaration. Views center the object for display only. Separate views fit their own extents; compare numeric axes rather than pixel size.\n\nFour overview views (XY/XZ/YZ/oblique) and four fixed oblique quadrant crops are supplied. Crops are systematic, not certified hole/bridge detections. Edge-on projections may be narrow; rasterization can show tessellation/antialias marks. A dark/white pixel is not topology evidence. Full PLY surface is authoritative. Use double-sided mesh display; stored triangle winding is not an outward-normal guarantee. If a relation or local hole/bridge is unresolved, say so and request a zoom by anonymous ID.\n\nNo source key, identities, ranks, residuals, process settings, fields or reference labels are included. Vertex/triangle counts and geometric shape remain visible and can still enable re-identification; posing is a mitigation, not guaranteed anonymity. Counts were not hidden by remeshing because that could alter holes and bridges. The reviewer must not consult census, Zenodo or identity materials. blank-review.csv is empty by design. Complete reviewer-attestation.md and freeze/commit it with the labels before the prescribed witnessed unblinding.\n''') (bundle/'reviewer-attestation.md').write_text('# Reviewer attestation\n\nI did not consult the census, the Zenodo files, or any identity material during review.\n\nReviewer: ____________________\n\nDate: ____________________\n\nSignature / explicit confirmation: ____________________\n\nFrozen labels commit / version: ____________________\n\nCommit this completed attestation together with frozen blind labels before unblinding. This template is unsigned.\n') html='''匿名几何复核

仅凭几何填写关系与局部依据。图轴为原坐标单位;分别自适应显示,像素尺寸不能直接比较。点击图片放大。看不清的关系、孔或薄桥可记未决。下载空白判定表 · 审阅声明(与判定一起冻结) · 完整性说明

左件 完整表面

右件 完整表面

''' (bundle/'index.html').write_text(html.replace('IDS',json.dumps(ids))) for p in sorted(bundle.rglob('*')): if p.is_file():records.append({'path':str(p.relative_to(bundle)),'bytes':p.stat().st_size,'sha256':sha(p)}) (bundle/'manifest.json').write_text(json.dumps({'scope':'anonymous geometry and blank review only','pairs':120,'files':records},indent=2)+'\n') archive=ROOT/'blind-package.zip' with ZipFile(archive,'x',compression=ZIP_DEFLATED,compresslevel=6) as z: for p in sorted(bundle.rglob('*')): if p.is_file(): info=ZipInfo(str(p.relative_to(bundle)),date_time=(1980,1,1,0,0,0));info.external_attr=0o100644<<16;info.compress_type=ZIP_DEFLATED;z.writestr(info,p.read_bytes()) # Byte equality verifies all archive entries, fixed timestamps, no identity path. with ZipFile(archive) as z: for entry in z.infolist(): assert entry.date_time==(1980,1,1,0,0,0) and not entry.filename.startswith('/') and '..' not in Path(entry.filename).parts assert z.read(entry.filename)==(bundle/entry.filename).read_bytes() report={'status':'120_BLIND_PAIRS_PACKAGED_NOT_REVIEWED','pairs':120,'unique_geometry_parts':232,'blind_files':len(records)+1,'blind_bytes':sum(r['bytes'] for r in records)+(bundle/'manifest.json').stat().st_size,'zip_bytes':archive.stat().st_size,'zip_sha256':sha(archive),'bundle_manifest_sha256':sha(bundle/'manifest.json'),'sampling_mapping_seal':seal,'all_pair_schemas_and_hashes_pass':True,'zip_entries_full_byte_check_pass':True,'zip_timestamps_normalized':True,'blank_labels':True,'reviewer_attestation_template_unsigned':True,'proper_pose_blinding':True,'pose_plan_sha256':pose_seals['pose_plan_sha256'],'pose_mapping_sha256':pose_seals['pose_mapping_sha256'],'cpu_seconds':sum(resource.getrusage(resource.RUSAGE_SELF)[:2]),'wall_seconds':time.monotonic()-start,'peak_rss_bytes':resource.getrusage(resource.RUSAGE_SELF).ru_maxrss*1024} (ROOT/'public/package-result.json').write_text(json.dumps(report,indent=2)+'\n');print(json.dumps(report)) if __name__=='__main__':main()