Class ArenaRatingService
Service for ranked arena seasons and ratings. See IArenaRatingService.
public sealed class ArenaRatingService : BaseService<ArenaRatingEntity>, IArenaRatingService
- Inheritance
-
ArenaRatingService
- Implements
- Inherited Members
Constructors
ArenaRatingService(INpgsqlDbContextFactory)
Initializes a new instance of ArenaRatingService.
public ArenaRatingService(INpgsqlDbContextFactory dbContextFactory)
Parameters
dbContextFactoryINpgsqlDbContextFactory
Methods
FetchRatingsAsync(long, IReadOnlyList<long>, CancellationToken)
Reads the given characters' ratings in a season. Characters with none are absent.
public Task<DatabaseResult<IReadOnlyList<ArenaRatingData>>> FetchRatingsAsync(long seasonId, IReadOnlyList<long> characterIds, CancellationToken cancellationToken = default)
Parameters
seasonIdlongcharacterIdsIReadOnlyList<long>cancellationTokenCancellationToken
Returns
FetchTopAsync(long, int, CancellationToken)
The highest rated characters of a season, with their names resolved by the caller.
public Task<DatabaseResult<IReadOnlyList<ArenaRatingData>>> FetchTopAsync(long seasonId, int limit, CancellationToken cancellationToken = default)
Parameters
seasonIdlonglimitintcancellationTokenCancellationToken
Returns
GetOrCreateActiveSeasonAsync(CancellationToken)
The active season, creating a first one when none exists.
public Task<DatabaseResult<ArenaSeasonData>> GetOrCreateActiveSeasonAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationToken
Returns
Remarks
Called once per ranked match formed and once per board opened, so the answer is cheap: one indexed read, and an insert only on a fresh database.
StartNewSeasonAsync(string, DateTime?, CancellationToken)
Ends the active season and starts a new one. Ratings of the old season are kept.
public Task<DatabaseResult<ArenaSeasonData>> StartNewSeasonAsync(string name, DateTime? endsUtc, CancellationToken cancellationToken = default)
Parameters
namestringDisplay name of the new season.
endsUtcDateTime?When the new season ends, or null for open-ended.
cancellationTokenCancellationTokenCancellation token.
Returns
UpsertRatingsAsync(long, IReadOnlyList<(long characterId, int newRating, bool won)>, CancellationToken)
Writes ratings after a ranked match, in one statement.
public Task<DatabaseResult<int>> UpsertRatingsAsync(long seasonId, IReadOnlyList<(long characterId, int newRating, bool won)> results, CancellationToken cancellationToken = default)
Parameters
seasonIdlongSeason the match counted towards.
resultsIReadOnlyList<(long characterId, int newRating, bool won)>Per character: the new rating and whether they won.
cancellationTokenCancellationToken
Returns
Remarks
An upsert: a character's first ranked game inserts their row. Peak rating is kept at the higher of the old and new values by the statement itself.