Skip to content

feat(usage): add the event Usage page and CSV export (#1166) - #1481

Draft
shashank03-dev wants to merge 8 commits into
fossasia:devfrom
shashank03-dev:feat/1166-usage-page
Draft

shashank03-dev wants to merge 8 commits into
fossasia:devfrom
shashank03-dev:feat/1166-usage-page

Conversation

@shashank03-dev

@shashank03-dev shashank03-dev commented Dec 5, 2026 •

Copy link
Copy Markdown
Member

Fixes #1166

Built on #1480. This branch has #1480's commit too. Until #1480 merges, please review only dc0a3cc. Merge order: #1479, #1480, then this PR.

What it does: event owners get a Usage page that shows how much each room used: minutes of transcription, characters translated, minutes of AI voice, and how long listeners were connected. It is split by provider and model, with a UTC date range and a CSV export. It reads the counts #1480 saves, plus the ones not saved yet.

Who sees what: only the event owner and Admins. It opens from a new Usage tile on the event's workspace page. Coordinators and interpreters don't see the tile, and the page and CSV refuse them.

Why it's needed: after a 3 day event nobody can say how many transcription minutes ran on Deepgram, how many characters went to translation, or how many people listened. That makes provider bills hard to explain and the next event hard to size.

Tests: 7 page and CSV tests in tests/test_usage.py (totals, dates, the empty page, owner and Admin access, deleted events, workspace paths). All fail on dev. Full suite 3887 passed.

This recording covers the whole split (#1479, #1480 and #1481).

Before (dev): a listener is live on the English booth, but the event page has no Usage tile, and /workspace/events/1/usage/ and the CSV export both return 404.

1166-before.mp4

After: with a listener on English audio and German AI translation, the new Usage page shows transcription, characters translated, listening and listener connections. Listening in from Mission Control on English adds no listener connection. The CSV returns 200 for the event owner and 403 for a room coordinator.

1166-after.mp4

Summary by Sourcery

Give event owners and Admins a per-event view of service usage with date-filtered CSV exports.

New Features:

  • Add an event Usage page showing transcription, translation, AI voice, listening time, and listener connections by room, provider, model, and language, with UTC date filters and CSV export.
  • Restrict the Usage page and CSV export to event owners and Admins, and add a Usage tile to the event workspace.

Enhancements:

  • Include usage not yet persisted in page totals and exports, alongside saved usage.

CI:

  • Run the Mission Control monitoring-player test in the CI test workflow.

Documentation:

  • Add administrator documentation describing usage metrics, date filters, CSV exports, and counting rules.

Tests:

  • Add coverage for usage collection, persistence, listener sampling, page and CSV output, and access controls.

Chores:

  • Add database migration 054 and usage-record schema documentation for hourly event usage.

…g per event

Counts are kept in memory where the work happens and added to hourly
usage_records rows every 60 s, after a transcription worker stops and at
shutdown. Staff WHEP players are marked with ?monitor=1 so listening time
leaves them out. Part of fossasia#1166.
@coderabbitai

coderabbitai Bot commented Dec 5, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@sourcery-ai

sourcery-ai Bot commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Schema and migrations

Add the hourly usage-records table, its event cascade and unique bucket index, and the ORM model that maps to it.

  • alembic/versions/054_add_usage_records.py L1-47
  • portal/models.py L778-818

Data structures

Track the room, language, booth and connection time for each TTS subscription so the listening sampler can attribute AI-translation listeners.

  • portal/websockets/manager.py L650-653 (+3 small edits)

API

Expose owner-only usage and CSV endpoints that combine saved and pending counts, apply UTC date filters, and produce formula-safe daily exports.

  • portal/routers/usage.py L1-177

Uses of the API

Mark interpreter and staff monitoring WHEP players so their sessions are excluded from listener totals.

  • portal/routers/interpreter.py L27-281 (4 small edits)
  • portal/static/js/mission-control.js L247-248

Record transcription audio read by providers and request a prompt flush when a transcription worker exits.

  • portal/transcription/worker.py L116-127 (+3 small edits)

Count translation text sent to engines, including timed-out or cancelled calls, once per target language.

  • portal/translations/worker.py L272-304, L1001-1007, L1024-1033 (+6 small edits)

Attach event and provider metadata to voice configuration and count the PCM audio produced under the provider's resolved voice.

  • portal/tts/worker.py L107-121 (+3 small edits)

Implementation

Implement in-memory hourly counters, batched persistence and shutdown retries, audio metering, listener sampling, and daily report aggregation.

  • portal/usage.py L1-588

Give TTS providers a common voice-resolution method so usage records identify the voice actually spoken.

  • portal/tts/providers/base.py L41-44
  • portal/tts/providers/deepgram.py L33-38, L47
  • portal/tts/providers/elevenlabs.py L41-44
  • portal/tts/providers/supertonic.py L115, L129

Map workspace usage URLs to their admin-route equivalents.

  • portal/workspace_routing.py L26

UI

Add the Usage quick-action tile to the event management page.

  • portal/templates/admin/event_detail.html L67-75

Render usage totals and room-level breakdowns with UTC date filters, CSV download and explanatory empty states.

  • portal/templates/admin/usage.html L1-95

Configuration

Start and stop the usage meter and listening sampler with the application lifecycle, and register the usage router.

  • fastapi_app.py L141-150 (+4 small edits)

Add the Mission Control monitoring JavaScript check to the CI test workflow.

  • .github/workflows/tests.yml L314

Documentation

Document the usage-records table and add its migration to the database map.

  • .agents/context/DATABASE_MAP.md L231-254, L344

Document the usage page and CSV routes in the route map.

  • .agents/context/ROUTE_MAP.md L139-140

Add usage tracking to the project component inventory and migration count.

  • agents.md L92, L103

Explain the Usage page, its metrics, sampling limits, date filters and CSV export for administrators.

  • website/docs/admin/usage.mdx L1-39
  • website/sidebars.ts L31

Tests

Verify interpreter monitoring URLs are marked and staff listening is excluded.

  • tests/test_admin_panel.py L3419-3420
  • tests/test_fastapi_app.py L356, L2108-2117
  • tests/test_mission_control_monitor.js L1-152

Test provider voice resolution through the shared TTS interface.

  • tests/test_tts_providers.py L6, L63-72, L125

Cover usage counting, persistence and retries, listening attribution, page access, date filtering, workspace routing and CSV output.

  • tests/test_usage.py L1-1285

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

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.

Record AI and streaming usage per event (transcription minutes, translated characters, TTS seconds, listener minutes)

1 participant