#!/usr/bin/env python3 from __future__ import annotations import csv import html import json import os from pathlib import Path REPO_ROOT = Path("/workspace/SchemID") SOURCE_ROOT = REPO_ROOT / "derived" / "Source" ROWS_PATH = SOURCE_ROOT / "metadata" / "rows.jsonl" VIS_ROOT = SOURCE_ROOT / "visuals" CSV_PATH = VIS_ROOT / "four_column_table.csv" HTML_PATH = VIS_ROOT / "four_column_table.html" def rel_to_visuals(path: Path) -> str: return os.path.relpath(path, VIS_ROOT) def image_rel(path_str: str) -> str: path = Path(path_str) return rel_to_visuals(path) def main() -> None: VIS_ROOT.mkdir(parents=True, exist_ok=True) rows: list[dict[str, str]] = [] with ROWS_PATH.open() as handle: for line in handle: raw = json.loads(line) source_payload = json.loads(raw["Source"]) original_path = Path(raw["Circuit generated image"]) no_text_path = Path(raw["Circuit Generated image with no text"]) eps_path = SOURCE_ROOT / source_payload["eps_path"] row = { "Circuit Generation Code": raw["Circuit Generation Code"], "Circuit generated image": image_rel(str(original_path)), "Circuit Generated image with no text": image_rel(str(no_text_path)), "Source": json.dumps(source_payload, sort_keys=True), "Code File": rel_to_visuals(eps_path), } rows.append(row) with CSV_PATH.open("w", newline="") as handle: writer = csv.DictWriter( handle, fieldnames=[ "Circuit Generation Code", "Circuit generated image", "Circuit Generated image with no text", "Source", "Code File", ], ) writer.writeheader() writer.writerows(rows) parts = [ "", "", "", "", "", "SchemID 4-Column Circuit Table", "", "", "", "
", "

SchemID 4-Column Circuit Table

", f"

Rows: {len(rows)}. CSV companion: four_column_table.csv.

", "", "", "", ] for row in rows: code_text = html.escape(row["Circuit Generation Code"]) source_text = html.escape(row["Source"]) code_file = html.escape(row["Code File"]) original_rel = html.escape(row["Circuit generated image"]) no_text_rel = html.escape(row["Circuit Generated image with no text"]) parts.extend( [ "", ( "" ), ( "" ), ( "" ), f"", "", ] ) parts.extend( [ "", "
Circuit Generation CodeCircuit generated imageCircuit Generated image with no textSource
" f"
{code_text}
" f"" "
" f"
original circuit
" f"" "
" f"
no-text circuit
" f"" "
{source_text}
", "
", "", "", ] ) HTML_PATH.write_text("\n".join(parts)) if __name__ == "__main__": main()