Refactor reports to share definitions across intervals

This commit is contained in:
Jordan Wages 2025-07-18 01:50:19 -05:00
commit 657c30b260
4 changed files with 38 additions and 18 deletions

View file

@ -27,18 +27,21 @@ Reports are written under the `output/` directory. Each command updates the corr
### Configuring Reports
Report queries are defined in `reports.yml`. Each entry specifies the `name`,
`interval`, optional `label` and `chart` type, and a SQL `query` that must return
`bucket` and `value` columns. When `generate_reports.py` runs, every matching
definition creates `output/<interval>/<name>.json` and an interval dashboard.
optional `label` and `chart` type, and a SQL `query` that must return `bucket`
and `value` columns. The special token `{bucket}` is replaced with the
appropriate SQLite `strftime` expression for each interval (hourly, daily,
weekly or monthly) so that a single definition works across all durations.
When `generate_reports.py` runs, every definition is executed for the requested
interval and creates `output/<interval>/<name>.json` along with an HTML
dashboard.
Example snippet:
```yaml
- name: hits
interval: hourly
chart: bar
query: |
SELECT strftime('%Y-%m-%d %H:00:00', datetime(time)) AS bucket,
SELECT {bucket} AS bucket,
COUNT(*) AS value
FROM logs
GROUP BY bucket