Skip to content

feat: rank balanced AI credit users and fix base-path API requests - #2

Merged
MichaelBaj merged 9 commits into
mainfrom
kagrawal/general-improvements
Aug 19, 2026
Merged

feat: rank balanced AI credit users and fix base-path API requests#2
MichaelBaj merged 9 commits into
mainfrom
kagrawal/general-improvements

Conversation

@agrawalkaushik

Copy link
Copy Markdown
Collaborator

Summary

This pull request improves AI-credit insights and makes frontend API access work when the app is deployed beneath a non-root Vite base path.

Balanced-user ranking

  • Adds balanced_score to every balanced AI-credit user and sorts the list by that score instead of raw credit volume.
  • Scores users using both model-mix balance and activity volume:
    • The 45-55% high-tier-model range receives the full balance factor.
    • Splits outside that range are penalized by their distance from it.
    • log10(total_ai_credits) dampens volume so disproportionately high usage does not dominate a better-balanced mix.
    • Squaring the balance factor increases the penalty for imbalance.
  • Exposes and renders the score in the Summary tab's balanced-users table.
  • Shows each user’s share of total AI credits in the Quality tab.
  • Adds backend coverage proving ordering across high-volume balanced, high-volume imbalanced, and low-volume perfectly balanced users.

Base-path API handling

  • Centralizes frontend API path prefixing with import.meta.env.BASE_URL.
  • Applies the base-path prefix to JSON reads, snapshots, imports and exports, usage-report creation, downloads and imports, and admin-token validation.
  • Configures the Vite development proxy for the matching base path, allowing deployments such as /copilot/ to reach /copilot/api/... rather than root-relative /api/....
  • Adds Vite client typings so TypeScript recognizes import.meta.env during production builds.

Test maintenance

  • Makes the feature endpoint test deterministic by querying the two explicitly seeded dates rather than relying on the current date’s rolling window.
  • Aligns billing headline metadata with the tested reporting period.
  • Includes generated package-lock.json metadata changes.

Validation

  • git diff --check passed.
  • Focused backend tests passed: 31 passed in 2.04s for test_billing_usage.py and test_features.py.
  • Frontend production build passed: npm run build completed TypeScript checking and Vite bundling successfully.

Scope

  • Includes commits for balanced-user ranking, base-path API routing, and build/test validation stability.
  • The frontend build emits the existing Vite chunk-size warning for a bundle exceeding 500 kB; it does not fail the build.

Implement combined scoring metric for balanced users list:
- Balance factor: penalizes deviation from 45-55% model split
- Logarithmic volume dampening: prevents massive unbalance from
  overshadowing perfect splits
- Score = log10(total) * (balance_factor ^ 2)

Update UI to display balance score and credit percentages across
QualityTab, SummaryTab, TeamsTab, and UsersTab. Add comprehensive
test validating score ranking with perfect vs. imbalanced users.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Goal: better AI-credit insights (balanced-user score + ranking, user credit share in tables) plus frontend API calls working under non-root Vite base path.

Changes:

  • Add balanced_score to balanced AI-credit users, sort backend results by score, render score in Summary tab.
  • Show per-user AI-credit share (%) in Users / Teams / Quality tables.
  • Prefix frontend API requests with import.meta.env.BASE_URL, update Vite dev proxy for base-path API routing, add Vite client typings; stabilize backend feature test window params.

Reviewed changes

Copilot reviewed 9 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
frontend/vite.config.ts Set Vite base path + dev proxy routing (now base-path aware).
frontend/src/vite-env.d.ts Add Vite client typings for import.meta.env.
frontend/src/components/UsersTab.tsx Show AI-credit share (%) next to per-user credits.
frontend/src/components/TeamsTab.tsx Show AI-credit share (%) for top users in team block; formatting/indent cleanup.
frontend/src/components/SummaryTab.tsx Display balanced_score column for balanced users table.
frontend/src/components/QualityTab.tsx Show AI-credit share (%) in top-users table.
frontend/src/api.ts Centralize base-path prefixing for API fetches and POST endpoints.
frontend/package-lock.json Lockfile metadata updates.
backend/tests/test_features.py Make features test deterministic via explicit start/end.
backend/tests/test_billing_usage.py Add ranking coverage for balanced-user scoring; add headline period meta in test.
backend/app/analytics.py Compute balanced_score and sort balanced users by score.
Files not reviewed (1)
  • frontend/package-lock.json: Generated file

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread frontend/vite.config.ts
Comment on lines 4 to 8
export default defineConfig({
base: "/copilot/",
plugins: [react()],
server: {
port: 5173,
Comment thread backend/app/analytics.py
}
)
balanced_users.sort(key=lambda row: row["total_ai_credits"], reverse=True)
balanced_users.sort(key=lambda row: row["balanced_score"], reverse=True)
Comment thread frontend/src/api.ts
Comment on lines 548 to +552
async function getJson<T>(path: string): Promise<T> {
const r = await fetch(path);
if (!r.ok) throw new Error(`${path}: ${r.status} ${r.statusText}`);
// Prepend base path so API requests resolve under the same base prefix (/copilot/api/...)
const prefix = import.meta.env.BASE_URL.replace(/\/$/, "");
const fullPath = path.startsWith("/api") ? `${prefix}${path}` : path;
const r = await fetch(fullPath);
@MichaelBaj
MichaelBaj merged commit 55e605b into main Aug 19, 2026
1 check passed
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.

3 participants