From 0b8b653b9e6c67f87a9a14d56636f346afc0348c Mon Sep 17 00:00:00 2001 From: GZTime Date: Sat, 31 Aug 2024 15:53:52 +0800 Subject: [PATCH] fix: sort order --- src/GZCTF/Repositories/GameRepository.cs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/GZCTF/Repositories/GameRepository.cs b/src/GZCTF/Repositories/GameRepository.cs index eb4333cb8..ba9388e6e 100644 --- a/src/GZCTF/Repositories/GameRepository.cs +++ b/src/GZCTF/Repositories/GameRepository.cs @@ -148,7 +148,7 @@ public Task GetGames(int count, int skip, CancellationToken token) => // Refactored by GZTimeWalker @ 2024/08/31 public async Task GenScoreboard(Game game, CancellationToken token = default) { - Dictionary items; + Dictionary items; // participant id -> scoreboard item Dictionary challenges; List submissions; @@ -291,21 +291,21 @@ public async Task GenScoreboard(Game game, CancellationToken to } // 5. sort scoreboard items by score and last submission time - var sortedItems = items.Values + items = items.Values .OrderByDescending(i => i.Score) .ThenBy(i => i.LastSubmissionTime) - .ToArray(); + .ToDictionary(i => i.Id); // team id -> scoreboard item // 6. update rank and organization rank var ranks = new Dictionary(); var currentRank = 1; Dictionary> orgTeams = new() { ["all"] = [] }; - foreach (var item in sortedItems) + foreach (var item in items.Values) { item.Rank = currentRank++; if (item.Rank <= 10) - orgTeams["all"].Add(item.ParticipantId); + orgTeams["all"].Add(item.Id); if (item.Organization is null) continue; @@ -314,22 +314,22 @@ public async Task GenScoreboard(Game game, CancellationToken to { item.OrganizationRank = rank + 1; ranks[item.Organization]++; - orgTeams[item.Organization].Add(item.ParticipantId); + orgTeams[item.Organization].Add(item.Id); } else { item.OrganizationRank = 1; ranks[item.Organization] = 1; - orgTeams[item.Organization] = [item.ParticipantId]; + orgTeams[item.Organization] = [item.Id]; } } // 7. generate top timelines by solved challenges var timelines = orgTeams.ToDictionary( i => i.Key, - i => i.Value.Select(pid => + i => i.Value.Select(tid => { - var item = items[pid]; + var item = items[tid]; return new TopTimeLine { Id = item.Id, @@ -355,7 +355,10 @@ public async Task GenScoreboard(Game game, CancellationToken to return new() { - Challenges = challengesDict, Items = items, TimeLines = timelines, BloodBonusValue = game.BloodBonus.Val + Challenges = challengesDict, + Items = items, + TimeLines = timelines, + BloodBonusValue = game.BloodBonus.Val }; }