"""Render development crops only, with explicit quarantine and held-out-candidate status."""
import collections,html,json
from pathlib import Path
R=Path(__file__).resolve().parents[1];O=R/'results/r112/species-depth';a=json.loads((O/'development-assets.json').read_text());screen=json.loads((O/'similarity-screen.json').read_text());sel=json.loads((O/'selection.json').read_text());groups=collections.defaultdict(list)
for x in a['records']:groups[x['source_species']].append(x)
sections=[]
for species,items in groups.items():
 cards=[]
 for x in items:
  cards.append(f'<figure><a href="{html.escape(x["source_crop"])}"><img loading="lazy" src="{html.escape(x["source_crop"])}" alt="Development specimen crop"></a><figcaption>{html.escape(x["source_slide_group"])}<br>Original: {x["source_dimensions_px"]} px · resized: {x["scaled_dimensions_px"]} px<br>Source annotation: {html.escape(x["source_annotation_shape"])}<br><a href="{html.escape(x["source_crop"])}">Original</a> · <a href="{html.escape(x["scaled_crop"])}">Academy-scale image</a></figcaption></figure>')
 sections.append(f'<section><h2>{html.escape(species)}</h2><p>{len(items)} nonquarantined development crops. Source names and specimen identity are not independently verified.</p><div class="grid">{"".join(cards)}</div></section>')
q=set(screen['quarantined_new_ids']);counts=collections.Counter(r['split'] for r in sel['rows'] if r['annotation_id'] in q);part=collections.Counter(r['split'] for r in sel['rows']);(O/'index.html').write_text('''<!doctype html><html lang="en"><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Species depth source library</title><style>body{font:16px/1.55 system-ui;background:#f4f6f0;color:#183b37;margin:0}main{max-width:1200px;padding:24px;margin:auto}h1,h2{font-family:Georgia,serif}a{color:#096c58}section,.notice,figure{background:white;border:1px solid #cddbd2;border-radius:5px;padding:16px;margin:14px 0}.notice{border-left:5px solid #bd8616}.grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(210px,1fr));gap:12px}figure{margin:0}img{width:100%;height:210px;object-fit:contain;background:#f4f4f3}figcaption{font-size:.88rem;overflow-wrap:anywhere}</style><body><main><nav><a href="/results/r112/">Synthetic training</a> · <a href="/results/board.html">Board</a></nav><h1>More examples per source species</h1><p class="notice"><strong>Development candidates, not a finished training set.</strong> Source taxonomy is unverified; original crop annotations are rough, and pixels can contain other organisms. Distinct slide names do not establish independent biological samples. No verified instance masks or species-level performance claim is provided.</p><p>The metadata-only selection contains ten source-labeled species and 60 distinct slide-name groups: 200 development crops and 50 each in provisional validation and test groups. Perceptual and exact-hash triage flagged '''+str(len(q))+''' new image IDs for quarantine: '''+html.escape(str(dict(counts)))+'''. Flagged does not automatically mean duplicate; unflagged does not prove independence. The gallery shows only '''+str(len(a['records']))+''' nonquarantined development crops.</p><p>Validation and test candidates are omitted from the gallery and must not be used for training or model selection. The project's static server does not provide access control; the files are not technically private. These remain candidate partitions until sample provenance and unresolved image similarities are investigated.</p><p>Original UDE crops are retained at 0.09 µm/pixel, and derived copies use a recorded Academy scan's OME XY scale. Similar pixel spacing does not establish equivalent optics, focus or retained species-diagnostic detail. Source dataset UDE DIATOMS in the Wild 2024: CC0.</p><p><a href="selection.json">Frozen selection</a> · <a href="download-report.json">Download checksums</a> · <a href="similarity-screen.json">Similarity flags and quarantine</a> · <a href="development-assets.json">Development provenance</a> · <a href="verify.log">Verification</a></p>'''+''.join(sections)+'''</main></body></html>''')
print('Rendered',len(a['records']),'development images across',len(groups),'source taxa; held-out candidates not included.')
