"""Build a static, auditable report from completed R62 results."""
import json,html
from pathlib import Path
ROOT=Path(__file__).resolve().parents[1];OUT=ROOT/'results/r62';d=json.loads((OUT/'results.json').read_text());records=d['records'];methods=('detector','grid','combined','five_plane_pool','pool_points')
def table(rows):
 out=''
 for mode in methods:
  vals=[sum(x['scores'][mode]['budgets'][str(n)]['matched'] for x in rows) for n in (5,10,20)]+[sum(x['scores'][mode]['all']['matched'] for x in rows)];count=sum(x['scores'][mode]['retained'] for x in rows);out+=f'<tr><td>{mode}</td>'+''.join(f'<td>{v}</td>' for v in vals)+f'<td>{count}</td></tr>'
 return out
cards=''
for r in records:
 scores=r['scores'];den=len(r['source_ids']);nums=' · '.join(f"{m}: {scores[m]['budgets']['10']['matched']}/{den}" for m in methods);cards+=f'<article><h2>{html.escape(r["condition"])} · pair {r["pair"]}</h2><img src="{r["image"]}" alt="Synthetic masks and candidate overlays"><p>Top-10 matches: {nums}. Retained candidates: '+', '.join(f'{m} {scores[m]["retained"]}' for m in methods)+'. <a href="'+r['archive']+'">Full masks and planes</a>.</p></article>'
page='''<!doctype html><html lang="en"><meta charset="utf-8"><meta name="viewport" content="width=device-width"><title>Separate-source combined proposals test</title><style>body{font:16px/1.5 system-ui;background:#f3f6ef;color:#203a38}main{max-width:1520px;margin:auto;padding:24px}.notice{background:#fff2d6;padding:16px}article{background:white;padding:14px;margin:16px 0}img{width:100%}table{border-collapse:collapse}th,td{padding:8px;border:1px solid #aaa;text-align:left} .table{overflow:auto}</style><main><nav><a href="/results/performance/">Performance monitor</a> · <a href="/research/R62.md">Research notes</a></nav><h1>Do combined proposals recover more separate-source crossings?</h1><p class="notice">These are synthetic overlays on real slide backgrounds. Foreground IDs were randomly preselected and excluded from prior public-source cohorts; background slide filenames differ from L49 and R61 but were previously inspected in R59. Three pairs repeat across conditions. Synthetic full-object targets are not expert annotations; these numbers do not establish real-slide, species-level or human-level accuracy.</p><p>The same fixed 64-point grid and filtering used in L49 is compared with middle-plane detector prompts, their alternating combination, a five-plane detector pool, and an alternating combination of pooled detections and point candidates. Predictions are matched one-to-one at IoU ≥0.5. Both pooled methods use five detector and segmentation passes; the combined pool also uses point prompts. Columns show synthetic full masks and each method’s first ten retained masks. Colors distinguish overlaid masks, not identities.</p><h2>Object-containing scenes (24 synthetic targets)</h2><div class="table"><table><tr><th>Method</th><th>Top 5</th><th>Top 10</th><th>Top 20</th><th>All</th><th>Retained candidates</th></tr>ROWS</table></div><p>Three background-only scenes have no synthetic targets but include natural, unannotated material; their candidate counts cannot be called false positives. The study retains all detector and point outputs, point locations, source planes, scores and raw simulated images. <a href="protocol.json">Frozen protocol and input hashes</a> · <a href="results.json">Full results</a>. Foreground source: Gündüz et al., <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a>; source and background details in <a href="selection.json">the frozen selection</a>.</p>CARDS</main></html>'''.replace('ROWS',table([r for r in records if r['condition']!='background_only'])).replace('CARDS',cards);(OUT/'index.html').write_text(page)
