Switch to snippet-based reports
This commit is contained in:
parent
da330a6058
commit
ab2af1015a
6 changed files with 97 additions and 106 deletions
|
@ -54,10 +54,12 @@ def _save_json(path: Path, data: List[Dict]) -> None:
|
|||
path.write_text(json.dumps(data, indent=2))
|
||||
|
||||
|
||||
def _render_html(interval: str, reports: List[Dict], out_path: Path) -> None:
|
||||
def _render_snippet(report: Dict, out_dir: Path) -> None:
|
||||
"""Render a single report snippet to ``<name>.html`` inside ``out_dir``."""
|
||||
env = Environment(loader=FileSystemLoader(TEMPLATE_DIR))
|
||||
template = env.get_template("report.html")
|
||||
out_path.write_text(template.render(interval=interval, reports=reports))
|
||||
template = env.get_template("report_snippet.html")
|
||||
snippet_path = out_dir / f"{report['name']}.html"
|
||||
snippet_path.write_text(template.render(report=report))
|
||||
|
||||
|
||||
def _bucket_expr(interval: str) -> str:
|
||||
|
@ -113,15 +115,16 @@ def _generate_interval(interval: str, domain: Optional[str] = None) -> None:
|
|||
"label": definition.get("label", name.title()),
|
||||
"chart": definition.get("chart", "line"),
|
||||
"json": f"{name}.json",
|
||||
"html": f"{name}.html",
|
||||
}
|
||||
if "color" in definition:
|
||||
entry["color"] = definition["color"]
|
||||
if "colors" in definition:
|
||||
entry["colors"] = definition["colors"]
|
||||
_render_snippet(entry, out_dir)
|
||||
report_list.append(entry)
|
||||
|
||||
_save_json(out_dir / "reports.json", report_list)
|
||||
_render_html(interval, report_list, out_dir / "index.html")
|
||||
typer.echo(f"Generated {interval} reports")
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue