1
0
mirror of synced 2025-01-31 12:23:50 +01:00

Fix ranks

This commit is contained in:
shiibe 2024-06-04 23:01:42 -04:00
parent c2a6da0b83
commit 916482c1f7
3 changed files with 13 additions and 4 deletions

View File

@ -4,7 +4,7 @@ namespace SharedProject.Models;
public class SongLeaderboard public class SongLeaderboard
{ {
public uint Rank { get; set; } public int Rank { get; set; }
public uint Baid { get; set; } public uint Baid { get; set; }

View File

@ -51,10 +51,15 @@ public class SongLeaderboardService : ISongLeaderboardService
var playDatum = await context.SongPlayData var playDatum = await context.SongPlayData
.Where(x => x.SongId == songId && x.Difficulty == difficulty && x.Baid == score.Baid) .Where(x => x.SongId == songId && x.Difficulty == difficulty && x.Baid == score.Baid)
.FirstOrDefaultAsync(); .FirstOrDefaultAsync();
// calculate Rank based on page/limit
var rank = await context.SongBestData
.Where(x => x.SongId == songId && x.Difficulty == difficulty && x.BestScore > score.BestScore)
.CountAsync();
leaderboard.Add(new SongLeaderboard leaderboard.Add(new SongLeaderboard
{ {
Rank = (uint)leaderboard.Count + 1, Rank = rank + 1,
Baid = score.Baid, Baid = score.Baid,
UserName = user?.MyDonName, UserName = user?.MyDonName,
BestScore = score.BestScore, BestScore = score.BestScore,
@ -85,10 +90,14 @@ public class SongLeaderboardService : ISongLeaderboardService
var user = await context.UserData var user = await context.UserData
.Where(x => x.Baid == baid) .Where(x => x.Baid == baid)
.FirstOrDefaultAsync(); .FirstOrDefaultAsync();
var rank = await context.SongBestData
.Where(x => x.SongId == songId && x.Difficulty == difficulty && x.BestScore > currentUserScore.BestScore)
.CountAsync();
leaderboard.Add(new SongLeaderboard leaderboard.Add(new SongLeaderboard
{ {
Rank = (uint)userRank + 1, Rank = rank + 1,
Baid = currentUserScore.Baid, Baid = currentUserScore.Baid,
UserName = user?.MyDonName, UserName = user?.MyDonName,
BestScore = currentUserScore.BestScore, BestScore = currentUserScore.BestScore,

View File

@ -79,7 +79,7 @@
@if (TotalPages > 1) @if (TotalPages > 1)
{ {
<div class="d-flex flex-column align-center"> <div class="d-flex flex-column align-center">
<MudPagination Class="pa-4" Count="@TotalPages" Selected="currentPage" SelectedChanged="(page) => OnPageChange(page)" BoundaryCount="1" MiddleCount="3" /> <MudPagination Class="pa-4" Rectangular="true" DisableElevation="true" Count="@TotalPages" Selected="currentPage" SelectedChanged="(page) => OnPageChange(page)" BoundaryCount="1" MiddleCount="3" />
</div> </div>
} }
</PagerContent> </PagerContent>