"""Draw the original, data-derived SVG with standard-library Python only."""
from pathlib import Path
from html import escape
import json
ROOT=Path(__file__).resolve().parent

def make_svg(results):
    p=results['focus_pairs']
    parts=['''<svg xmlns="http://www.w3.org/2000/svg" width="1000" height="610" viewBox="0 0 1000 610" role="img" aria-labelledby="plot-title plot-desc">
<title id="plot-title">Server throughput relative to the matched Offline run</title>
<desc id="plot-desc">Three NVIDIA DGX B300 submissions have Server to Offline ratios of 85.36, 94.37 and 97.87 percent. A separate NVIDIA GB200 GPT-OSS submission is 101.72 percent. Each percentage compares scenarios within one exact metadata group, never two systems.</desc>
<rect width="1000" height="610" fill="#f8f8f3"/>
<g font-family="Arial, sans-serif" fill="#252822">
<text x="40" y="43" font-size="22">The scenario ratio changes with the workload</text>
<text x="40" y="73" font-size="15" fill="#686d63">Server ÷ Offline × 100 · released MLPerf v6.1 results · higher is not a hardware ranking</text>
<text x="40" y="122" font-size="16" font-weight="bold">NVIDIA DGX B300 · 1 node · 8 × B300-SXM-270GB · FP4</text>
''']
    x0,x1=300,885
    scale=lambda q:x0+q/110*(x1-x0)
    for tick in [0,25,50,75,100]:
        x=scale(tick)
        parts.append(f'<path d="M{x:.2f} 147 V333 M{x:.2f} 429 V482" stroke="#dbdfd5" stroke-width="1"/>')
        parts.append(f'<text x="{x:.2f}" y="355" text-anchor="middle" font-size="13" fill="#686d63">{tick}%</text>')
    parts.append(f'<path d="M{scale(100):.2f} 147 V333 M{scale(100):.2f} 429 V482" stroke="#818c7e" stroke-dasharray="5 4"/>')
    labels=['DeepSeek-R1','GPT-OSS-120B','Llama 2 70B · 99.9 target','GPT-OSS-120B']
    for item,y,label,color in zip(p,[178,244,310,460],labels,['#075f43']*3+['#7b8875']):
        value=item['server_over_offline_percent']
        parts.append(f'<text x="40" y="{y+5}" font-size="16">{escape(label)}</text>')
        parts.append(f'<rect x="{x0}" y="{y-14}" width="{scale(value)-x0:.2f}" height="28" fill="{color}" rx="1"/>')
        parts.append(f'<text x="{scale(value)+10:.2f}" y="{y+5}" font-size="16" font-weight="bold">{value:.2f}%</text>')
    parts.append('''<path d="M40 382 H960" stroke="#dbdfd5"/>
<text x="40" y="410" font-size="16" font-weight="bold">Separate counterexample: NVIDIA GB200 NVL72 · 18 nodes · 72 × GB200 · FP4</text>
<text x="40" y="527" font-size="15" fill="#686d63">Each bar retains its own model, accuracy target, platform, precision and software metadata.</text>
<text x="40" y="551" font-size="15" fill="#686d63">Closed division · available systems · inferred = 0 · Tokens/s · has_power = false</text>
<text x="40" y="580" font-size="13" fill="#686d63">Source: MLCommons inference_results_v6.1, commit 4bb63cd28eb13. Analysis and figure: Aryan Putta.</text>
</g></svg>''')
    return ''.join(parts)

if __name__=='__main__':
    results=json.loads((ROOT/'results.json').read_text())
    (ROOT/'scenario-ratios.svg').write_text(make_svg(results))
    print('Wrote scenario-ratios.svg from four matched pairs.')
