Skip to content

feat(stats): read Miniserver statistics (lox stats list/get/download) - #27

Open
tbernaerd wants to merge 5 commits into
eisber:mainfrom
tbernaerd:feat/stats
Open

tbernaerd wants to merge 5 commits into
eisber:mainfrom
tbernaerd:feat/stats

Conversation

@tbernaerd

Copy link
Copy Markdown

Adds lox stats to read the statistics the Miniserver logs, over the /stats/ HTTP endpoints. Read-only.

What it does

  • lox stats list (alias ls): lists every statistic file from GET /stats/ (name, group, month, uuid, label). --filter, --month, --latest (newest month per statistic).
  • lox stats get <name|uuid>: fetches the monthly GET /stats/<file>.xml files and prints the values as table, CSV or JSON, one column per output (Outputs="total,totalNeg" → T,total,totalNeg). --group N for grouped statistics (meters), --from/--to YYYY-MM. Months are joined in order and the row that repeats at a month boundary is dropped.
  • lox stats download --dir <dir>: mirrors the raw XML files locally, incrementally. A past month is skipped once the local copy was saved after that month ended; the current month is always refetched; --force refetches all. Files are written via .part + rename. Honours the global --dry-run.

Ambiguous names fail with Ambiguous: '<name>' ... (→ ambiguous_control) and list the candidates; unknown names use not_found_error with suggestions. -o json, -o csv and --no-header are honoured.

Notes

  • Uses the XML statistics files, not /binstatisticdata/: they are self-describing (statistic name, group, output labels).
  • No new dependencies: index and XML parsing use quick-xml, file names are parsed by hand.
  • RunContext.csv, dry_run and no_header lose their #[allow(dead_code)], since stats reads them.
  • docs/commands/inspection.md described a lox stats / lox history that does not exist; that section now documents this command.
  • Tested with httpmock and invented fixtures (no live Miniserver needed), plus a manual run against a Gen 2 Miniserver on firmware 17.2 (about 80 statistics, 20 months of history).
  • cargo fmt --check, cargo clippy -- -D warnings, cargo build --release and cargo test pass.

- download: refetch a past month's local file unless it was saved at least
  one day after that month ended; "now" is injectable for tests
- merge_months: error naming the statistic, months and outputs when months
  disagree on their outputs, instead of using the first month's outputs
- parse_index: skip a malformed <li> entry and continue with the next
- get/download: reject --from later than --to
- stats list: add the `ls` alias
- tests: fuzzy "Did you mean" suggestion, out-of-order index months,
  --no-header for get CSV and the list table; invented fixture names
- docs: correct the Statistics notes in COMMANDS.md and replace the stale
  `lox stats` section in docs/commands/inspection.md

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant