Skip to content

Commit

Permalink
Fix various test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
frenzibyte committed Nov 18, 2024
1 parent 1847b67 commit 1b0a5f9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public void TestGlobalStatisticsUpdatedAfterRegistrationAddedAndScoreProcessed()

AddStep("signal score processed", () => ((ISpectatorClient)spectatorClient).UserScoreProcessed(userId, scoreId));
AddUntilStep("update received", () => update != null);
AddAssert("statistics values are correct", () => dummyAPI.LocalUser.Value.Statistics.TotalScore, () => Is.EqualTo(5_000_000));
AddAssert("statistics values are correct", () => statisticsProvider.GetStatisticsFor(ruleset)!.TotalScore, () => Is.EqualTo(5_000_000));
}

private int nextUserId = 2000;
Expand Down
32 changes: 20 additions & 12 deletions osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapRecommendations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
using osu.Game.Database;
using osu.Game.Extensions;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Catch;
using osu.Game.Rulesets.Mania;
Expand All @@ -28,25 +30,31 @@ namespace osu.Game.Tests.Visual.SongSelect
{
public partial class TestSceneBeatmapRecommendations : OsuGameTestScene
{
[Resolved]
private IRulesetStore rulesetStore { get; set; }

[SetUpSteps]
public override void SetUpSteps()
{
AddStep("populate ruleset statistics", () =>
{
Dictionary<string, UserStatistics> rulesetStatistics = new Dictionary<string, UserStatistics>();

rulesetStore.AvailableRulesets.Where(ruleset => ruleset.IsLegacyRuleset()).ForEach(rulesetInfo =>
((DummyAPIAccess)API).HandleRequest += r =>
{
rulesetStatistics[rulesetInfo.ShortName] = new UserStatistics
switch (r)
{
PP = getNecessaryPP(rulesetInfo.OnlineID)
};
});

API.LocalUser.Value.RulesetsStatistics = rulesetStatistics;
case GetUserRequest userRequest:
userRequest.TriggerSuccess(new APIUser
{
Id = 99,
Statistics = new UserStatistics
{
PP = getNecessaryPP(userRequest.Ruleset?.OnlineID ?? 0)
}
});

return true;

default:
return false;
}
};
});

decimal getNecessaryPP(int? rulesetID)
Expand Down
3 changes: 3 additions & 0 deletions osu.Game/Beatmaps/DifficultyRecommender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ protected override void LoadComplete()
statisticsUpdate = statisticsProvider.StatisticsUpdate.GetBoundCopy();
statisticsUpdate.BindValueChanged(u =>
{
if (u.NewValue == null)
return;

// algorithm taken from https://github.com/ppy/osu-web/blob/e6e2825516449e3d0f3f5e1852c6bdd3428c3437/app/Models/User.php#L1505
recommendedDifficultyMapping[u.NewValue.Ruleset.ShortName] = Math.Pow((double)(u.NewValue.NewStatistics.PP ?? 0), 0.4) * 0.195;
}, true);
Expand Down
8 changes: 2 additions & 6 deletions osu.Game/Online/API/Requests/Responses/APIUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public class KudosuCount
[JsonProperty(@"statistics")]
public UserStatistics Statistics
{
get => statistics;
get => statistics ??= new UserStatistics();
set
{
if (statistics != null)
Expand All @@ -244,11 +244,7 @@ public UserStatistics Statistics
[JsonProperty(@"rank_history")]
private APIRankHistory rankHistory
{
set
{
statistics ??= new UserStatistics();
statistics.RankHistory = value;
}
set => Statistics.RankHistory = value;
}

[JsonProperty(@"active_tournament_banners")]
Expand Down

0 comments on commit 1b0a5f9

Please sign in to comment.