Commit 5e47d22
fix: rank category leaders by raw metrics instead of points (#209)
* fix: rank category leaders by raw metrics instead of points
Category leaders were being ranked by totalPoints which includes bonus
points (marathon bonus, media bonus, etc.), distorting the actual metric
rankings. For example, a 26.2mi marathon runner with a 100pt bonus
would rank above someone who ran 30mi.
Now tracks totalMetricValue (raw unit value from activity type's
configured unit) alongside totalPoints in categoryPoints and
weeklyCategoryPoints tables. Leaders are sorted by metric value so
rankings reflect actual performance.
Changes:
- Add totalMetricValue to categoryPoints/weeklyCategoryPoints schema
- Export extractActivityMetricValue helper from scoring.ts
- Thread metricDelta through all write paths (log, edit, delete, strava, admin, API)
- Sort leaders by totalMetricValue with fallback to totalPoints
- Update admin UI to show metric values with units
- Update backfill actions to compute metric values from existing activities
To backfill existing data:
npx convex run actions/backfillCategoryPoints:backfillCategoryPoints --prod
npx convex run actions/backfillWeeklyCategoryPoints:backfillWeeklyCategoryPoints --prod
https://claude.ai/code/session_01GTgPZnuNCKB6BV83Wx8XTN
* test: add tests for metric-based category leader rankings
- Unit tests for extractActivityMetricValue and getMetricValueForUnit
(exact keys, aliases, missing metrics, no-unit activity types)
- Integration tests verifying leaders are ranked by raw metrics:
- Marathon bonus doesn't inflate ranking (30mi > 26.2mi)
- Weekly awards also use metric ranking
- Fallback to totalPoints when no metric data exists
- Category unit is returned in the query response
https://claude.ai/code/session_01GTgPZnuNCKB6BV83Wx8XTN
* Add soft warning for unit mismatch in category activity types
When assigning an activity type to a category in the admin UI, show
a warning if the activity type's unit differs from other activity
types already in that category. This prevents silently mixing
incompatible units (e.g., miles + km) in category leader metric totals.
https://claude.ai/code/session_01GTgPZnuNCKB6BV83Wx8XTN
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent cfe9ee1 commit 5e47d22
24 files changed
Lines changed: 958 additions & 69 deletions
File tree
- apps/web
- app/challenges/[id]/admin/category-leaders
- components/admin
- tests
- api
- lib
- packages/backend
- actions
- lib
- mutations
- queries
- tasks
Lines changed: 4 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
262 | 262 | | |
263 | 263 | | |
264 | 264 | | |
265 | | - | |
| 265 | + | |
266 | 266 | | |
267 | | - | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
268 | 270 | | |
269 | 271 | | |
270 | 272 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
56 | 57 | | |
57 | 58 | | |
58 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
59 | 97 | | |
60 | 98 | | |
61 | 99 | | |
| |||
397 | 435 | | |
398 | 436 | | |
399 | 437 | | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
400 | 447 | | |
401 | 448 | | |
402 | 449 | | |
| |||
580 | 627 | | |
581 | 628 | | |
582 | 629 | | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
583 | 642 | | |
584 | 643 | | |
585 | 644 | | |
| |||
0 commit comments