"""Publish retrospective prompt and ranking decomposition."""
import html,json
from pathlib import Path
R=Path(__file__).resolve().parents[1];O=R/'results/r112/grouped-prompt-diagnostic';r=json.loads((O/'results.json').read_text());s=r['summary'];table=''
for metric,label in [('grid_covers','Grid has a point inside weak support'),('raw_candidate_exists_for_support','At least one raw mask can match (not one-to-one)')]:table+='<tr><th>'+html.escape(label)+'</th>'+''.join('<td>'+str(s[n][metric])+'/'+str(s[n]['references'])+'</td>' for n in ('64','256'))+'</tr>'
for metric,label in [('raw_oracle','All raw masks, reference-assisted assignment'),('eligible_oracle','Eligible masks before NMS, reference-assisted'),('kept_oracle','Kept masks after NMS, all candidates'),('top30','Kept masks, first 30')]:table+='<tr><th>'+html.escape(label)+'</th>'+''.join('<td>'+str(s[n]['stages'][metric])+'/'+str(s[n]['references'])+'</td>' for n in ('64','256'))+'</tr>'
page='''<!doctype html><html lang="en"><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Prompt and ranking diagnostic</title><style>body{font:16px/1.55 system-ui;background:#f4f6f0;color:#193b37;margin:0}main{max-width:1000px;margin:auto;padding:24px}a{color:#096c58}.notice{background:#fff8df;border-left:5px solid #bc851b;padding:16px}table{border-collapse:collapse;background:white}td,th{border:1px solid #cddbd2;padding:8px;text-align:left}</style><main><nav><a href="/results/r112/grouped-baseline/">Segmentation baseline and scene images</a> · <a href="/results/r112/">Synthetic training</a></nav><h1>Where do weak-support matches get lost?</h1><p class="notice"><strong>Retrospective development diagnostic.</strong> All numbers use unverified projected masks as reference proxies; this is not real segmentation accuracy. The 48 scenes were already used, source names and biological independence are unverified, and original background may contain diatoms.</p><p>The fixed MobileSAM prompts and candidate masks were saved in the earlier run. We checked whether a grid point fell inside each projected support, and then compared matching at several processing stages. Matching uses IoU ≥0.5. A grid point inside a projected mask does not prove it lands on visible diatom anatomy.</p><table><tr><th>Stage</th><th>64 points</th><th>256 points</th></tr>'''+table+'''</table><p>The raw and eligible rows use the reference supports to find the best one-to-one assignment across all candidates. They are <strong>oracles</strong>, not an automatic way to identify or rank masks in use. The candidate-exists row permits the same mask to count for multiple supports and is not one-to-one. Assignments can change between rows; their differences do not identify a specific causal failure for each support. At top 30, scores are from the original fixed quality ranking.</p><p>For 256 points, the grid covers 216 supports, but only 105 have any raw mask with IoU ≥0.5; after NMS the reference-assisted assignment matches 97, and the first 30 candidates match 67. This motivates testing both mask generation and ranking. It does not validate any training method or prove the actual diatoms are missing.</p><p><a href="protocol.json">Protocol</a> · <a href="results.json">Per-scene counts and assignments</a> · <a href="verify.json">Recomputation check</a> · <a href="/results/r112/grouped-baseline/">Inspect all scene overlays</a></p></main></html>''';(O/'index.html').write_text(page);print('wrote report')
