File size: 1,438 Bytes
f4924d6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""Local preview for the Tasks tab.

Renders the task-browser page from the *local* data clones
(``cadgenbench-data`` + ``cadgenbench-data-gt`` at the repo root) and
writes a standalone HTML file you can open in a browser. Image URLs are
relative paths into those local folders, so the output must live at the
workspace root for the relative paths to resolve.

Usage::

    python cadgenbench-leaderboard/tools/preview_tasks.py
    # writes <workspace>/tasks-preview.html
"""
from __future__ import annotations

import sys
from pathlib import Path

# Make `tasks` importable when run from anywhere.
LEADERBOARD_DIR = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(LEADERBOARD_DIR))

from tasks import load_tasks_from_dir, render_tasks_page  # noqa: E402

WORKSPACE = LEADERBOARD_DIR.parent
INPUTS_DIR = WORKSPACE / "cadgenbench-data"
GT_DIR = WORKSPACE / "cadgenbench-data-gt"
OUT = WORKSPACE / "tasks-preview.html"


def main() -> int:
    tasks = load_tasks_from_dir(INPUTS_DIR)

    def asset_url(fixture: str, relpath: str) -> str:
        return f"cadgenbench-data/{fixture}/{relpath}"

    doc = render_tasks_page(tasks, asset_url)
    OUT.write_text(doc)
    n_edit = sum(1 for t in tasks if t["task_type"] == "editing")
    print(
        f"Wrote {OUT} ({len(tasks)} tasks, {n_edit} editing, "
        f"{OUT.stat().st_size // 1024} KB)"
    )
    return 0


if __name__ == "__main__":
    raise SystemExit(main())