Internal Service β This is not an HTTP endpoint. Itβs called by the ranking-score route.
Purpose
Generates 4 fake competitor scores that are displayed alongside the userβs score. Creates the impression of a competitive landscape.
Function Signature
def generate_competitor_scores(user_score: int) -> List[int]
Parameters
| Parameter | Type | Description |
|---|
user_score | int | The userβs ranking score |
Returns
List[int] - 4 competitor scores, sorted descending (highest first)
| Rule | Description |
|---|
| Ranking | 50% chance user ranks 5th (all 4 higher), 50% chance user ranks 4th |
| Max score | No score exceeds 86 |
| Uniqueness | All scores must be unique |
| Close competitor | One competitor is always within 2-4 points of user |
Example Output
For a user score of 38:
{
"score": 38,
"competitor_scores": [72, 65, 58, 42]
}
The user sees: βYou rank #5 out of 5 competitorsβ
Why This Design?
- Close competitor - Shows the user theyβre βalmostβ beating someone
- Higher scores - Creates urgency (βcompetitors are aheadβ)
- Sorted descending - Easy to display as a leaderboard
- Randomized ranking - Some users rank 4th (hope), some rank 5th (urgency)
Code Location
src/website/ranking_score/routes.py
# Lines 49-129: generate_competitor_scores()