Skip to content

Commit

Permalink
Remove legacy ranking code
Browse files Browse the repository at this point in the history
  • Loading branch information
sei-bstein committed Jan 21, 2025
1 parent 1c924d7 commit 2c141e2
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 42 deletions.
1 change: 0 additions & 1 deletion src/Gameboard.Api/Features/Game/GameController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ public async Task Rerank([FromRoute] string id, CancellationToken cancellationTo
await Authorize(_permissionsService.Can(PermissionKey.Scores_RegradeAndRerank));
await Validate(new Entity { Id = id });

await GameService.ReRank(id);
await _scoreDenormalization.DenormalizeGame(id, cancellationToken);
await _mediator.Publish(new GameCacheInvalidateNotification(id), cancellationToken);
}
Expand Down
29 changes: 0 additions & 29 deletions src/Gameboard.Api/Features/Game/GameService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public interface IGameService
Task<bool> IsUserPlaying(string gameId, string userId);
Task<IEnumerable<Game>> List(GameSearchFilter model = null, bool sudo = false);
Task<GameGroup[]> ListGrouped(GameSearchFilter model, bool sudo);
Task ReRank(string id);
Task<Game> Retrieve(string id, bool accessHidden = true);
Task<ChallengeSpec[]> RetrieveChallengeSpecs(string id);
Task<SessionForecast[]> SessionForecast(string id);
Expand Down Expand Up @@ -213,34 +212,6 @@ public async Task UpdateImage(string id, string type, string filename)
await _store.SaveUpdate(entity, default);
}

public async Task ReRank(string id)
{
var players = await _store
.WithTracking<Data.Player>()
.Where(p => p.GameId == id && p.Mode == PlayerMode.Competition)
.OrderByDescending(p => p.Score)
.ThenBy(p => p.Time)
.ThenByDescending(p => p.CorrectCount)
.ThenByDescending(p => p.PartialCount)
.ToArrayAsync()
;

int rank = 0;
string last = "";
foreach (var player in players)
{
if (player.TeamId != last)
{
rank += 1;
last = player.TeamId;
}

player.Rank = rank;
}

await _store.SaveUpdateRange(players);
}

public Task<bool> IsUserPlaying(string gameId, string userId)
=> _store.AnyAsync<Data.Player>(p => p.GameId == gameId && p.UserId == userId, CancellationToken.None);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
using System.Threading;
using System.Threading.Tasks;
using Gameboard.Api.Services;
using Gameboard.Api.Features.Scores;
using MediatR;

namespace Gameboard.Api.Features.Teams;

public record TeamSessionResetNotification(string GameId, string TeamId) : INotification;

internal class TeamSessionResetHandler : INotificationHandler<TeamSessionResetNotification>
internal class TeamSessionResetHandler(IScoreDenormalizationService scoreDenorm) : INotificationHandler<TeamSessionResetNotification>
{
private readonly GameService _gameService;

public TeamSessionResetHandler
(
GameService gameService
)
{
_gameService = gameService;
}
private readonly IScoreDenormalizationService _scoreDenorm = scoreDenorm;

public async Task Handle(TeamSessionResetNotification notification, CancellationToken cancellationToken)
{
await _gameService.ReRank(notification.GameId);
await _scoreDenorm.DenormalizeGame(notification.GameId, cancellationToken);
}
}

0 comments on commit 2c141e2

Please sign in to comment.