Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ license = "Apache-2.0"
license-files = ["LICENSE"]
requires-python = ">=3.10"
dependencies = [
"anybadge>=1.16.0",
# Keep sorted
"click>=8.1.7",
"enlighten>=1.12.4",
Expand Down
7 changes: 6 additions & 1 deletion src/dvsim/cli/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def dashboard() -> None:
)
def dashboard_gen(json_path: Path, output_dir: Path, base_url: str | None) -> None:
"""Generate a dashboard from a existing results JSON."""
from dvsim.sim.dashboard import gen_dashboard # noqa: PLC0415
from dvsim.sim.dashboard import gen_badges, gen_dashboard # noqa: PLC0415
from dvsim.sim.data import SimResultsSummary # noqa: PLC0415

results: SimResultsSummary = SimResultsSummary.load(path=json_path)
Expand All @@ -54,6 +54,11 @@ def dashboard_gen(json_path: Path, output_dir: Path, base_url: str | None) -> No
base_url=base_url,
)

gen_badges(
summary=results,
path=output_dir,
)


@cli.group()
def report() -> None:
Expand Down
143 changes: 143 additions & 0 deletions src/dvsim/sim/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

from pathlib import Path

from anybadge import Badge

from dvsim.logging import log
from dvsim.report.artifacts import render_static_content
from dvsim.sim.data import SimResultsSummary
Expand Down Expand Up @@ -59,3 +61,144 @@ def gen_dashboard(
},
)
)

(path / "dashboard.json").write_text(summary.model_dump_json())


def _badge_write(badge: Badge, path: Path) -> None:
"""Write a badge to file.

Args:
badge: the badge to write
path: file path to write the badge to

"""
path.parent.mkdir(parents=True, exist_ok=True)

if path.is_file():
path.unlink()

badge.write_badge(path)


def _badge_write_int(
label: str,
value: int | None,
path: Path,
) -> None:
"""Write a badge to file.

Args:
label: badge text label
value: badge value as int or
path: file path to write the badge to

"""
_badge_write(
badge=Badge(
label=label,
value=value,
default_color="blue",
),
path=path,
)


_COLOR_THRESHOLDS = {
0.01: "#EF5757",
10: "#EF6D57",
20: "#EF8357",
30: "#EF9957",
40: "#EFAF57",
50: "#EFC557",
60: "#EFDB57",
70: "#ECEF57",
80: "#D6EF57",
90: "#C0EF57",
100: "#57EF57",
}
_TEXT_THRESHOLD = 20


def _badge_write_percent(
label: str,
value: float,
path: Path,
) -> None:
"""Write a badge to file.

Args:
label: badge text label
value: badge value as int or
path: file path to write the badge to

"""
_badge_write(
badge=Badge(
label=label,
value=f"{value:.1f}" if value else "0",
value_suffix="%",
thresholds=_COLOR_THRESHOLDS,
text_color="#fff," + ("#000" if value > _TEXT_THRESHOLD else "#fff"),
),
path=path,
)


def gen_badges(
summary: SimResultsSummary,
path: Path,
) -> None:
"""Generate a dashboard badges.

Args:
summary: overview of the block results
path: output directory path
base_url: override the base URL for links

"""
base_path = path / "badge"

for block, results in summary.flow_results.items():
block_base = base_path / block

_badge_write_int(
label="Tests Running",
value=results.total,
path=block_base / "test.svg",
)

_badge_write_percent(
label="Tests Passing",
value=100 * results.passed / results.total,
path=block_base / "passing.svg",
)

# Coverage
if results.coverage is None:
continue

functional = results.coverage.functional or 0
_badge_write_percent(
label="Functional Coverage",
value=functional,
path=block_base / "functional.svg",
)

code = (
results.coverage.code.average
if results.coverage.code and results.coverage.code.average
else 0
)
_badge_write_percent(
label="Code Coverage",
value=code,
path=block_base / "code.svg",
)

assertion = results.coverage.assertion or 0
_badge_write_percent(
label="Assertion Coverage",
value=assertion,
path=block_base / "assertion.svg",
)
4 changes: 4 additions & 0 deletions src/dvsim/templates/dashboard/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
<span class="badge text-bg-secondary">
Branch: {{ top.branch }}
</span>
<a class="badge text-bg-secondary link-underline link-underline-opacity-0"
href="dashboard.json">
json
</a>
</div>
</div>

Expand Down
Loading
Loading