Skip to content

Official Codebase of 3DCodeVerse

Python

readers: one round row — the gallery's RoundRow extends select.RoundRow, and the CLI rounds table is select.round_rows

gaoypeng83f8375f3b6c
diff --git a/harness/codeverse3d/addons/gallery/index.py b/harness/codeverse3d/addons/gallery/index.py
index f3006ba1..d4dc3817 100644
--- a/harness/codeverse3d/addons/gallery/index.py
+++ b/harness/codeverse3d/addons/gallery/index.py
@@ -186,19 +186,10 @@ def entry_links(ws: Workspace, rec: RunRecord | None, picked: int | None) -> lis
def round_rows(ws: Workspace, rec: RunRecord) -> list[RoundRow]:
- rows: list[RoundRow] = []
- for r in rec.rounds:
- j = effective_judgment(r)
- gates = gate_error_summary(r)
- rows.append(RoundRow(
- index=r.index, kind=r.kind, commit=r.commit[:12],
- build_ok=None if r.build is None else r.build.ok,
- score=j.overall if j else None, passed=j.passed if j else None,
- gate_errors=sum(gates.values()), gates={k: v for k, v in gates.items() if v},
- cost_usd=round(r.usage.cost_usd, 6), minutes=round(r.minutes, 2),
- sheet=_round_sheet(ws, rec, r.index),
- ))
- return rows
+ rounds = {r.index: r for r in rec.rounds}
+ return [RoundRow(**{**row.model_dump(), "commit": row.commit[:12]}, sheet=_round_sheet(ws, rec, row.index),
+ gates={k: v for k, v in gate_error_summary(rounds[row.index]).items() if v})
+ for row in select.round_rows(ws.root, record=rec)]
#: complexity axes worth putting on a card / detail page (the index carries the rest)
diff --git a/harness/codeverse3d/addons/gallery/model.py b/harness/codeverse3d/addons/gallery/model.py
index bcfd2013..94d7f836 100644
--- a/harness/codeverse3d/addons/gallery/model.py
+++ b/harness/codeverse3d/addons/gallery/model.py
@@ -19,6 +19,8 @@ from typing import Literal
from pydantic import BaseModel, Field
+from codeverse3d.addons import select
+
#: the three buckets, in the order they are always displayed
VERDICTS = ("judged", "unjudged", "error")
@@ -104,20 +106,11 @@ class RunLink(BaseModel):
kind: LinkKind = "file"
-class RoundRow(BaseModel):
- """One round, flattened for the detail page's rounds table (``passed`` is the judge's
- own verdict for THAT round — a fact about the round, never about the run)."""
+class RoundRow(select.RoundRow):
+ """``select.RoundRow`` plus what the detail page's rounds table draws: the gate
+ breakdown and the round's contact sheet."""
- index: int
- kind: str = ""
- commit: str = ""
- build_ok: bool | None = None
- score: float | None = None
- passed: bool | None = None
- gate_errors: int = 0
gates: dict[str, int] = Field(default_factory=dict, description="gate name → error count")
- cost_usd: float = 0.0
- minutes: float = Field(default=0.0, description="RoundRecord.minutes")
sheet: str = Field(default="", description="run-relative contact sheet of this round")
diff --git a/harness/codeverse3d/cli/_common.py b/harness/codeverse3d/cli/_common.py
index 57894076..0bf08ca1 100644
--- a/harness/codeverse3d/cli/_common.py
+++ b/harness/codeverse3d/cli/_common.py
@@ -10,7 +10,7 @@ from collections.abc import Iterator
from contextlib import ExitStack, contextmanager
from dataclasses import dataclass
from pathlib import Path
-from typing import Annotated, Any
+from typing import TYPE_CHECKING, Annotated, Any
import typer
from rich.console import Console
@@ -23,6 +23,9 @@ from codeverse3d.contracts.spec import Spec
from codeverse3d.conventions import slugify
from codeverse3d.workspace import Workspace
+if TYPE_CHECKING:
+ from codeverse3d.addons.select import RoundRow
+
console = Console(emoji=False)
err_console = Console(stderr=True, style="bold red", emoji=False)
@@ -49,18 +52,17 @@ def fmt_usd(v: float) -> str:
return f"${v:.4f}"
-def rounds_table(record: RunRecord, picked: int | None) -> Table:
- """One row per round; "passed" is the judge's own verdict for THAT round."""
+def rounds_table(rows: list[RoundRow], picked: int | None) -> Table:
+ """One row per round (``select.round_rows``: a degraded verdict counts as unjudged);
+ "passed" is the judge's own verdict for THAT round."""
t = Table(title="rounds (* = picked)", show_lines=False)
- for col in ("#", "kind", "build", "gate err", "score", "passed", "cost", "secs", "commit"):
- t.add_column(col, justify="right" if col in ("#", "gate err", "score", "cost", "secs") else "left")
- for r in record.rounds:
- build = "-" if r.build is None else ("ok" if r.build.ok else "[red]FAIL[/red]")
- j = r.judgment
- passed = "-" if j is None else ("[green]yes[/green]" if j.passed else "no")
- mark = "*" if r.index == picked else ""
- t.add_row(f"{r.index}{mark}", r.kind, build, str(sum(len(g.errors) for g in r.gates)), fmt_score(r.score),
- passed, fmt_usd(r.usage.cost_usd), f"{r.duration_s:.0f}", r.commit[:8])
+ for col in ("#", "kind", "build", "gate err", "score", "passed", "cost", "min", "commit"):
+ t.add_column(col, justify="right" if col in ("#", "gate err", "score", "cost", "min") else "left")
+ for r in rows:
+ build = "-" if r.build_ok is None else ("ok" if r.build_ok else "[red]FAIL[/red]")
+ passed = "-" if r.passed is None else ("[green]yes[/green]" if r.passed else "no")
+ t.add_row(f"{r.index}{'*' if r.index == picked else ''}", r.kind, build, str(r.gate_errors), fmt_score(r.score),
+ passed, fmt_usd(r.cost_usd), f"{r.minutes:.1f}", r.commit[:8])
return t
@@ -96,7 +98,7 @@ def print_record_summary(record: RunRecord, ws_root: Path | None = None) -> None
lines.append(f"deliverable: {handed}")
console.print(Panel("\n".join(lines), title="run", expand=False))
if record.rounds:
- console.print(rounds_table(record, s.picked_round))
+ console.print(rounds_table(select.round_rows(root, record=record), s.picked_round))
def kv_table(title: str, rows: dict[str, Any]) -> Table:
diff --git a/harness/codeverse3d/cli/main.py b/harness/codeverse3d/cli/main.py
index 414d7441..3551bcf6 100644
--- a/harness/codeverse3d/cli/main.py
+++ b/harness/codeverse3d/cli/main.py
@@ -655,9 +655,7 @@ def pick(
raise C.CliError(str(e), code=2) from e
if idx is None:
raise typer.Exit(code=1)
- console.print(kv_table("rounds (* = picked)", {
- f"r{r.index:02d}{' *' if r.index == idx else ''}": f"{r.kind:<9} score {C.fmt_score(r.score)} "
- f"gate errors {r.gate_errors} {C.fmt_usd(r.cost_usd)}" for r in rows}))
+ console.print(C.rounds_table(rows, idx))
# --------------------------------------------------------------------------- render / judge