Show rank tier and ELO alongside RZ points in the coins badge
Adds a server-computed tier/division (Bronze..Diamond, III-I) to the ratings profile endpoint and surfaces it next to the numeric ELO in the shared header badge, matching the coin balance display already there.
This commit is contained in:
@@ -47,4 +47,6 @@ public class RatingProfileResponse
|
||||
public int OverallElo { get; set; }
|
||||
public int RatedQuestionCount { get; set; }
|
||||
public Dictionary<string, int> CategoryElos { get; set; } = [];
|
||||
public string Tier { get; set; } = "";
|
||||
public int TierDivision { get; set; }
|
||||
}
|
||||
|
||||
@@ -27,14 +27,43 @@ public class RatingStore
|
||||
public async Task<RatingProfileResponse> GetProfileAsync(string userId)
|
||||
{
|
||||
var rating = await GetOrCreateUserRatingAsync(userId);
|
||||
var (tierName, tierDivision) = GetTier(rating.OverallElo);
|
||||
return new RatingProfileResponse
|
||||
{
|
||||
OverallElo = rating.OverallElo,
|
||||
RatedQuestionCount = rating.RatedQuestionCount,
|
||||
CategoryElos = rating.CategoryElos
|
||||
CategoryElos = rating.CategoryElos,
|
||||
Tier = tierName,
|
||||
TierDivision = tierDivision
|
||||
};
|
||||
}
|
||||
|
||||
private static readonly (string Name, int FloorElo)[] TierBands =
|
||||
[
|
||||
("Bronze", MinElo),
|
||||
("Silver", 1000),
|
||||
("Gold", 1300),
|
||||
("Platinum", 1900),
|
||||
("Diamond", 2200)
|
||||
];
|
||||
|
||||
private static (string Name, int Division) GetTier(int elo)
|
||||
{
|
||||
var bandIndex = 0;
|
||||
for (var i = 0; i < TierBands.Length; i++)
|
||||
{
|
||||
if (elo >= TierBands[i].FloorElo)
|
||||
bandIndex = i;
|
||||
}
|
||||
|
||||
var band = TierBands[bandIndex];
|
||||
var nextFloor = bandIndex + 1 < TierBands.Length ? TierBands[bandIndex + 1].FloorElo : band.FloorElo + 300;
|
||||
var bandWidth = nextFloor - band.FloorElo;
|
||||
var progress = bandWidth > 0 ? (elo - band.FloorElo) / (double)bandWidth : 0;
|
||||
var division = 3 - Math.Clamp((int)(progress * 3), 0, 2);
|
||||
return (band.Name, division);
|
||||
}
|
||||
|
||||
public async Task<UserRating> GetOrInitializeHistoryAsync(string userId, DateTime nowUtc)
|
||||
{
|
||||
var rating = await GetOrCreateUserRatingAsync(userId);
|
||||
|
||||
Reference in New Issue
Block a user