Class LeaderboardRanker
Pure ranking policy for leaderboard entries: deterministic sorting and competition-style rank assignment (equal values share a rank; the next distinct value skips the gap). Ties are detected by exact double equality, matching relational RANK() OVER (ORDER BY ...) semantics, so ranking policy stays identical across backends. Callers submitting computed floating-point values must quantize them first if they expect ties.
Inherited Members
Namespace: Serenity.Leaderboard.Domain.Services
Assembly: Serenity.Leaderboard.Domain.dll
Syntax
public static class LeaderboardRanker
Methods
AssignRanks(IReadOnlyList<LeaderboardEntry>)
Assigns competition ranks to an already-sorted list of entries: entries with equal Value share the same rank, and the next distinct value resumes at the 1-based position it would occupy without the tie (1, 2, 2, 4, ...).
Declaration
public static IReadOnlyList<RankedEntry> AssignRanks(IReadOnlyList<LeaderboardEntry> sortedEntries)
Parameters
| Type | Name | Description |
|---|---|---|
| IReadOnlyList<LeaderboardEntry> | sortedEntries | Entries already sorted in ranking order (see Sort(IReadOnlyList<LeaderboardEntry>, LeaderboardSortDirection)). |
Returns
| Type | Description |
|---|---|
| IReadOnlyList<RankedEntry> | The ranked entries, in the same order as |
FindRank(IReadOnlyList<LeaderboardEntry>, PlayerId)
Finds the 1-based competition rank of a player within an already-sorted list.
Declaration
public static int FindRank(IReadOnlyList<LeaderboardEntry> sortedEntries, PlayerId player)
Parameters
| Type | Name | Description |
|---|---|---|
| IReadOnlyList<LeaderboardEntry> | sortedEntries | Entries already sorted in ranking order (see Sort(IReadOnlyList<LeaderboardEntry>, LeaderboardSortDirection)). |
| PlayerId | player | The player to look up. |
Returns
| Type | Description |
|---|---|
| int | The player's 1-based rank, or zero when the player is not present. |
IsBetter(double, double, LeaderboardSortDirection)
Determines whether a candidate value beats the current value under the given direction —
the single write-path "should this submission replace the stored best?" policy shared by
every ILeaderboardStore backend. Strict comparison: an equal value is NOT better,
so the earlier submission is kept (matching relational $gt/$lt-style
upsert-if-better semantics).
Declaration
public static bool IsBetter(double candidateValue, double currentValue, LeaderboardSortDirection direction)
Parameters
| Type | Name | Description |
|---|---|---|
| double | candidateValue | The newly submitted value. |
| double | currentValue | The currently stored best value. |
| LeaderboardSortDirection | direction | The ordering that defines "better" for the board. |
Returns
| Type | Description |
|---|---|
| bool |
Sort(IReadOnlyList<LeaderboardEntry>, LeaderboardSortDirection)
Sorts entries by Value according to the given direction. Ties are broken deterministically by the earlier AchievedAtUtcTicks (regardless of direction), then by PlayerId ordinal comparison.
Declaration
public static IReadOnlyList<LeaderboardEntry> Sort(IReadOnlyList<LeaderboardEntry> entries, LeaderboardSortDirection direction)
Parameters
| Type | Name | Description |
|---|---|---|
| IReadOnlyList<LeaderboardEntry> | entries | The entries to sort. |
| LeaderboardSortDirection | direction | The ordering to apply to Value. |
Returns
| Type | Description |
|---|---|
| IReadOnlyList<LeaderboardEntry> | A new, sorted list. The input list is not modified. |