feat: rank balanced AI credit users and fix base-path API requests - #2
Merged
Conversation
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.
…ase path correctly
agrawalkaushik
requested review from
MichaelBaj
and
a lite review from Copilot
August 19, 2026 22:13
There was a problem hiding this comment.
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_scoreto 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 on lines
4
to
8
| export default defineConfig({ | ||
| base: "/copilot/", | ||
| plugins: [react()], | ||
| server: { | ||
| port: 5173, |
| } | ||
| ) | ||
| balanced_users.sort(key=lambda row: row["total_ai_credits"], reverse=True) | ||
| balanced_users.sort(key=lambda row: row["balanced_score"], reverse=True) |
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
approved these changes
Aug 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
balanced_scoreto every balanced AI-credit user and sorts the list by that score instead of raw credit volume.log10(total_ai_credits)dampens volume so disproportionately high usage does not dominate a better-balanced mix.Base-path API handling
import.meta.env.BASE_URL./copilot/to reach/copilot/api/...rather than root-relative/api/....import.meta.envduring production builds.Test maintenance
package-lock.jsonmetadata changes.Validation
git diff --checkpassed.31 passed in 2.04sfortest_billing_usage.pyandtest_features.py.npm run buildcompleted TypeScript checking and Vite bundling successfully.Scope