Add global report generation
This commit is contained in:
parent
11d6e5e4ba
commit
a3f06fd9e2
3 changed files with 83 additions and 0 deletions
|
@ -101,6 +101,10 @@ def _generate_interval(interval: str, domain: Optional[str] = None) -> None:
|
|||
|
||||
report_list = []
|
||||
for definition in cfg:
|
||||
if "{bucket}" not in definition["query"] or definition.get("global"):
|
||||
# Global reports are generated separately
|
||||
continue
|
||||
|
||||
name = definition["name"]
|
||||
query = definition["query"].replace("{bucket}", bucket)
|
||||
query = query.replace("FROM logs", "FROM logs_view")
|
||||
|
@ -154,6 +158,50 @@ def _generate_root_index() -> None:
|
|||
typer.echo(f"Generated root index at {out_path}")
|
||||
|
||||
|
||||
def _generate_global() -> None:
|
||||
"""Generate reports that do not depend on an interval."""
|
||||
cfg = _load_config()
|
||||
if not cfg:
|
||||
typer.echo("No report definitions found")
|
||||
return
|
||||
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
cur = conn.cursor()
|
||||
|
||||
out_dir = OUTPUT_DIR / "global"
|
||||
out_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
report_list = []
|
||||
for definition in cfg:
|
||||
if "{bucket}" in definition["query"] and not definition.get("global"):
|
||||
continue
|
||||
|
||||
name = definition["name"]
|
||||
query = definition["query"]
|
||||
cur.execute(query)
|
||||
rows = cur.fetchall()
|
||||
headers = [c[0] for c in cur.description]
|
||||
data = [dict(zip(headers, row)) for row in rows]
|
||||
json_path = out_dir / f"{name}.json"
|
||||
_save_json(json_path, data)
|
||||
entry = {
|
||||
"name": name,
|
||||
"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)
|
||||
typer.echo("Generated global reports")
|
||||
|
||||
|
||||
@app.command()
|
||||
def hourly(
|
||||
domain: Optional[str] = typer.Option(
|
||||
|
@ -218,6 +266,12 @@ def monthly(
|
|||
_generate_interval("monthly", domain)
|
||||
|
||||
|
||||
@app.command("global")
|
||||
def global_reports() -> None:
|
||||
"""Generate global reports."""
|
||||
_generate_global()
|
||||
|
||||
|
||||
@app.command()
|
||||
def index() -> None:
|
||||
"""Generate the root index page linking all reports."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue