diff --git a/NineChroniclesUtilBackend/Controllers/ArenaController.cs b/NineChroniclesUtilBackend/Controllers/ArenaController.cs index d5b95e99..935d7655 100644 --- a/NineChroniclesUtilBackend/Controllers/ArenaController.cs +++ b/NineChroniclesUtilBackend/Controllers/ArenaController.cs @@ -18,12 +18,16 @@ namespace NineChroniclesUtilBackend.Controllers; [Route("arena")] public class ArenaController(ArenaRankingRepository arenaRankingRepository) : ControllerBase { - [HttpGet("ranking")] - public async Task> GetRanking(int limit, int offset, string avatarAddress) + [HttpGet("ranking/{avatarAddress}/rank")] + public async Task GetRankByAvatarAddress(string avatarAddress) { - var addressOffset = await arenaRankingRepository.GetRankByAvatarAddress(avatarAddress); + return await arenaRankingRepository.GetRankByAvatarAddress(avatarAddress); + } - return await arenaRankingRepository.GetRanking(limit, offset + addressOffset); + [HttpGet("ranking")] + public async Task> GetRanking(int limit, int offset) + { + return await arenaRankingRepository.GetRanking(limit, offset); } [HttpPost("simulate")] diff --git a/NineChroniclesUtilBackend/Repositories/ArenaRankingRespository.cs b/NineChroniclesUtilBackend/Repositories/ArenaRankingRespository.cs index bd238ee7..1fcdd525 100644 --- a/NineChroniclesUtilBackend/Repositories/ArenaRankingRespository.cs +++ b/NineChroniclesUtilBackend/Repositories/ArenaRankingRespository.cs @@ -41,21 +41,18 @@ public async Task> GetRanking(long limit, long offset) { var pipelines = new[] { - @"{ $sort: { 'Score.Score': -1 } }", - @"{ $group: { _id: null, docs: { $push: '$$ROOT' } } }", - @"{ $unwind: { path: '$docs', includeArrayIndex: 'Rank' } }", + @"{ $setWindowFields: { partitionBy: '', sortBy: { 'Score.Score': -1 }, output: { Rank: { $rank: {} } } } }", $@"{{ $skip: {offset} }}", $@"{{ $limit: {limit} }}", - @"{ $replaceRoot: { newRoot: { $mergeObjects: [ '$docs', { Rank: '$Rank' } ] } } }", @"{ $lookup: { from: 'avatars', localField: 'AvatarAddress', foreignField: 'Avatar.address', as: 'Avatar' } }", @"{ $unwind: { path: '$Avatar', preserveNullAndEmptyArrays: true } }", + @"{ $unset: ['Avatar.Avatar.inventory', 'Avatar.Avatar.mailBox', 'Avatar.Avatar.stageMap', 'Avatar.Avatar.monsterMap', 'Avatar.Avatar.itemMap', 'Avatar.Avatar.eventMap'] }", }.Select(BsonDocument.Parse).ToArray(); - var aggregation = await ArenaCollection.Aggregate(pipelines).ToListAsync(); - + var aggregation = ArenaCollection.Aggregate(pipelines).ToList(); var arenaRankings = await Task.WhenAll(aggregation.OfType().Select(BuildArenaRankingFromDocument)); - return arenaRankings.ToList(); + return [.. arenaRankings]; } private async Task BuildArenaRankingFromDocument(BsonDocument document) @@ -65,7 +62,7 @@ private async Task BuildArenaRankingFromDocument(BsonDocument docu document["Information"]["Address"].AsString, document["Information"]["Win"].AsInt32, document["Information"]["Lose"].AsInt32, - document["Rank"].AsInt64 + 1, + document["Rank"].AsInt32 + 1, document["Information"]["Ticket"].AsInt32, document["Information"]["TicketResetCount"].AsInt32, document["Information"]["PurchasedTicketCount"].AsInt32, @@ -90,6 +87,7 @@ private async Task BuildArenaRankingFromDocument(BsonDocument docu var cp = await CpRepository.CalculateCp(avatar, characterId, equipmentids, costumeids, runeSlots); arenaRanking.CP = cp; + Console.WriteLine($"CP Calculate {arenaRanking.ArenaAddress}"); return arenaRanking; }