Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check ranked state when retrieving user best scores #258

Merged
merged 2 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,40 @@ public void RankCountsCorrect()
WaitForDatabaseState<(int?, int?)>("SELECT `a_rank_count`, `s_rank_count` FROM `osu_user_stats_mania_4k` WHERE `user_id` = @userId", (0, 1), CancellationToken, new { userId = 2 });
}

[Fact]
public void RankCountsNotUpdatedForUnrankedScores()
{
var beatmap4K = AddBeatmap(b =>
{
b.beatmap_id = 12;
b.playmode = 3;
b.diff_size = 4;
}, s => s.beatmapset_id = 1);

WaitForDatabaseState<(int?, int?)>("SELECT `a_rank_count`, `s_rank_count` FROM `osu_user_stats_mania_4k` WHERE `user_id` = @userId", (null, null), CancellationToken, new { userId = 2 });

SetScoreForBeatmap(beatmap4K.beatmap_id, s =>
{
s.Score.ranked = false;
s.Score.preserve = true;
s.Score.total_score = 500_000;
s.Score.rank = ScoreRank.A;
s.Score.ruleset_id = 3;
});

WaitForDatabaseState<(int?, int?)>("SELECT `a_rank_count`, `s_rank_count` FROM `osu_user_stats_mania_4k` WHERE `user_id` = @userId", (0, 0), CancellationToken, new { userId = 2 });

SetScoreForBeatmap(beatmap4K.beatmap_id, s =>
{
s.Score.ranked = s.Score.preserve = true;
s.Score.total_score = 300_000; // same map and keymode as above, lower score, but score is ranked => should count
s.Score.rank = ScoreRank.S;
s.Score.ruleset_id = 3;
});

WaitForDatabaseState<(int?, int?)>("SELECT `a_rank_count`, `s_rank_count` FROM `osu_user_stats_mania_4k` WHERE `user_id` = @userId", (0, 1), CancellationToken, new { userId = 2 });
}

[Fact]
public void PerformancePointTotalAndRankUpdated()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ public void TestScoreOnRankedMapIncreasesRankedScore(BeatmapOnlineStatus status)
waitForRankedScore("osu_user_stats", 10081);
}

[Fact]
public void TestUnrankedScoreOnRankedMapDoesNotIncreaseRankedScore()
{
AddBeatmap(b => b.approved = BeatmapOnlineStatus.Ranked);
waitForRankedScore("osu_user_stats", 0);

SetScoreForBeatmap(TEST_BEATMAP_ID, s => s.Score.ranked = false);
waitForRankedScore("osu_user_stats", 0);

SetScoreForBeatmap(TEST_BEATMAP_ID, s => s.Score.total_score = 50000);
waitForRankedScore("osu_user_stats", 5041);
}

[Fact]
public void TestScoresFromDifferentBeatmapsAreCountedSeparately()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,32 @@ public void TestScoreWithRankAOrAboveOnRankedMapChangesRankCounts(BeatmapOnlineS
});
}

[Fact]
public void TestUnrankedScoreWithRankAOrAboveOnRankedMapDoesNotChangeRankCounts()
{
AddBeatmap(b => b.approved = BeatmapOnlineStatus.Ranked);
waitForRankCounts("osu_user_stats", new Dictionary<ScoreRank, int>());

SetScoreForBeatmap(TEST_BEATMAP_ID, item =>
{
item.Score.total_score = 100_000;
item.Score.rank = ScoreRank.A;
item.Score.ranked = false;
});
waitForRankCounts("osu_user_stats", new Dictionary<ScoreRank, int>());

SetScoreForBeatmap(TEST_BEATMAP_ID, item =>
{
item.Score.total_score = 50_000;
item.Score.rank = ScoreRank.S;
item.Score.ranked = true;
});
waitForRankCounts("osu_user_stats", new Dictionary<ScoreRank, int>
{
[ScoreRank.S] = 1
});
}

[Fact]
public void TestScoreFromSameBeatmapAndHigherTotalChangesCountedRank()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ public static bool IsBeatmapValidForRankedCounts(int beatmapId, MySqlConnection
// usages in processors will generally pass in an unprocessed score, but still expect it to be included in the results of this query as if it was processed.
// therefore we need to make an exception here to ensure it's included.
+ "AND (`preserve` = 1 OR `id` = @new_score_id) "
+ "AND `ranked` = 1 "
+ "ORDER BY total_score DESC, `id` DESC "
+ "LIMIT @offset, 1", new
{
Expand Down