[claude] Sovereignty metrics emitter + SQLite store (#954) #1164

Merged
Rockachopa merged 1 commits from :claude/issue-954 into main 2026-03-23 19:52:21 +00:00
Collaborator

Fixes #954

What this does

Implements the sovereignty metrics infrastructure for the Bannerlord sovereignty loop.

New module: src/timmy/sovereignty/metrics.py

  • SovereigntyMetricsStore backed by SQLite (data/sovereignty_metrics.db)
  • events table: timestamp, event_type, session_id, metadata_json
  • sessions table: session_id, game, start_time, end_time
  • record(event_type, metadata) — logs any of the 9 sovereignty event types
  • get_sovereignty_pct(layer, time_window) → float (0–100)
  • get_cost_per_hour(time_window) → float (USD)
  • get_skills_crystallized(session_id) → int
  • get_snapshot() — real-time dict for dashboard widgets
  • emit_sovereignty_event() — async helper that records + publishes on event bus
  • Module-level convenience wrappers: metrics.record(...), metrics.get_sovereignty_pct(...), etc.

WebSocket emitter: src/dashboard/routes/sovereignty_ws.py

  • /ws/sovereignty — streams snapshots every 5 s to dashboard widget clients
  • Registered in dashboard/app.py

34 new unit tests (all passing, included in tox -e unit)

Covers all analytics functions, session management, edge cases, and emit_sovereignty_event.

Fixes #954 ## What this does Implements the sovereignty metrics infrastructure for the Bannerlord sovereignty loop. ### New module: `src/timmy/sovereignty/metrics.py` - `SovereigntyMetricsStore` backed by SQLite (`data/sovereignty_metrics.db`) - `events` table: `timestamp`, `event_type`, `session_id`, `metadata_json` - `sessions` table: `session_id`, `game`, `start_time`, `end_time` - `record(event_type, metadata)` — logs any of the 9 sovereignty event types - `get_sovereignty_pct(layer, time_window)` → float (0–100) - `get_cost_per_hour(time_window)` → float (USD) - `get_skills_crystallized(session_id)` → int - `get_snapshot()` — real-time dict for dashboard widgets - `emit_sovereignty_event()` — async helper that records + publishes on event bus - Module-level convenience wrappers: `metrics.record(...)`, `metrics.get_sovereignty_pct(...)`, etc. ### WebSocket emitter: `src/dashboard/routes/sovereignty_ws.py` - `/ws/sovereignty` — streams snapshots every 5 s to dashboard widget clients - Registered in `dashboard/app.py` ### 34 new unit tests (all passing, included in `tox -e unit`) Covers all analytics functions, session management, edge cases, and `emit_sovereignty_event`.
claude added 1 commit 2026-03-23 19:51:31 +00:00
feat: add sovereignty metrics emitter and SQLite store (#954)
Some checks failed
Tests / lint (pull_request) Has been cancelled
Tests / test (pull_request) Has been cancelled
8cd511266b
- Create src/timmy/sovereignty/metrics.py with:
  - SovereigntyMetricsStore backed by SQLite (events + sessions tables)
  - metrics.record(event_type, metadata) for all 9 sovereignty event types
  - get_sovereignty_pct(layer, time_window) for perception/decision/narration
  - get_cost_per_hour(time_window) extrapolated from api_cost events
  - get_skills_crystallized(session_id) count
  - get_snapshot() for dashboard widgets
  - emit_sovereignty_event() async helper using event bus
- Add /ws/sovereignty WebSocket endpoint (dashboard/routes/sovereignty_ws.py)
  that pushes metric snapshots every 5s to connected clients
- Register sovereignty_ws_router in dashboard/app.py
- Add 34 unit tests (all passing)

Fixes #954
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Rockachopa merged commit dec9736679 into main 2026-03-23 19:52:21 +00:00
Rockachopa deleted branch claude/issue-954 2026-03-23 19:52:21 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Rockachopa/Timmy-time-dashboard#1164