diff --git a/scripts/generate_reports.py b/scripts/generate_reports.py index e7c42cb..b92a54c 100644 --- a/scripts/generate_reports.py +++ b/scripts/generate_reports.py @@ -62,6 +62,35 @@ def _render_snippet(report: Dict, out_dir: Path) -> None: snippet_path.write_text(template.render(report=report)) +def _write_stats() -> None: + """Query basic dataset stats and write them to ``output/global/stats.json``.""" + conn = sqlite3.connect(DB_PATH) + cur = conn.cursor() + + cur.execute("SELECT COUNT(*) FROM logs") + total_logs = cur.fetchone()[0] or 0 + + cur.execute("SELECT MIN(time), MAX(time) FROM logs") + row = cur.fetchone() or (None, None) + start_date = row[0] or "" + end_date = row[1] or "" + + cur.execute("SELECT COUNT(DISTINCT host) FROM logs") + unique_domains = cur.fetchone()[0] or 0 + + conn.close() + + stats = { + "total_logs": total_logs, + "start_date": start_date, + "end_date": end_date, + "unique_domains": unique_domains, + } + + out_path = OUTPUT_DIR / "global" / "stats.json" + _save_json(out_path, stats) + + def _bucket_expr(interval: str) -> str: """Return the SQLite strftime expression for the given interval.""" fmt = INTERVAL_FORMATS.get(interval) @@ -199,6 +228,7 @@ def _generate_global() -> None: report_list.append(entry) _save_json(out_dir / "reports.json", report_list) + _write_stats() typer.echo("Generated global reports") diff --git a/templates/index.html b/templates/index.html index 08b5732..6294602 100644 --- a/templates/index.html +++ b/templates/index.html @@ -32,6 +32,12 @@ +
Total logs: -
+Date range: - to -
+Unique domains: -
+