mirror of
https://github.com/ppy/osu.git
synced 2024-12-05 09:42:54 +08:00
Make DifficultyRecommender
rely on the statistics provider
This commit is contained in:
parent
4a628287e2
commit
28f87407f6
@ -10,7 +10,7 @@ using JetBrains.Annotations;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online;
|
||||
using osu.Game.Rulesets;
|
||||
|
||||
namespace osu.Game.Beatmaps
|
||||
@ -21,18 +21,49 @@ namespace osu.Game.Beatmaps
|
||||
/// </summary>
|
||||
public partial class DifficultyRecommender : Component
|
||||
{
|
||||
[Resolved]
|
||||
private IAPIProvider api { get; set; }
|
||||
private readonly LocalUserStatisticsProvider statisticsProvider;
|
||||
|
||||
[Resolved]
|
||||
private Bindable<RulesetInfo> ruleset { get; set; }
|
||||
|
||||
private readonly Dictionary<string, double> recommendedDifficultyMapping = new Dictionary<string, double>();
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
/// <returns>
|
||||
/// Rulesets ordered descending by their respective recommended difficulties.
|
||||
/// The currently selected ruleset will always be first.
|
||||
/// </returns>
|
||||
private IEnumerable<string> orderedRulesets
|
||||
{
|
||||
api.LocalUser.BindValueChanged(_ => populateValues(), true);
|
||||
get
|
||||
{
|
||||
if (LoadState < LoadState.Ready || ruleset.Value == null)
|
||||
return Enumerable.Empty<string>();
|
||||
|
||||
return recommendedDifficultyMapping
|
||||
.OrderByDescending(pair => pair.Value)
|
||||
.Select(pair => pair.Key)
|
||||
.Where(r => !r.Equals(ruleset.Value.ShortName, StringComparison.Ordinal))
|
||||
.Prepend(ruleset.Value.ShortName);
|
||||
}
|
||||
}
|
||||
|
||||
private IBindable<UserStatisticsUpdate> statisticsUpdate = null!;
|
||||
|
||||
public DifficultyRecommender(LocalUserStatisticsProvider statisticsProvider)
|
||||
{
|
||||
this.statisticsProvider = statisticsProvider;
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
statisticsUpdate = statisticsProvider.StatisticsUpdate.GetBoundCopy();
|
||||
statisticsUpdate.BindValueChanged(u =>
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -63,36 +94,5 @@ namespace osu.Game.Beatmaps
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void populateValues()
|
||||
{
|
||||
if (api.LocalUser.Value.RulesetsStatistics == null)
|
||||
return;
|
||||
|
||||
foreach (var kvp in api.LocalUser.Value.RulesetsStatistics)
|
||||
{
|
||||
// algorithm taken from https://github.com/ppy/osu-web/blob/e6e2825516449e3d0f3f5e1852c6bdd3428c3437/app/Models/User.php#L1505
|
||||
recommendedDifficultyMapping[kvp.Key] = Math.Pow((double)(kvp.Value.PP ?? 0), 0.4) * 0.195;
|
||||
}
|
||||
}
|
||||
|
||||
/// <returns>
|
||||
/// Rulesets ordered descending by their respective recommended difficulties.
|
||||
/// The currently selected ruleset will always be first.
|
||||
/// </returns>
|
||||
private IEnumerable<string> orderedRulesets
|
||||
{
|
||||
get
|
||||
{
|
||||
if (LoadState < LoadState.Ready || ruleset.Value == null)
|
||||
return Enumerable.Empty<string>();
|
||||
|
||||
return recommendedDifficultyMapping
|
||||
.OrderByDescending(pair => pair.Value)
|
||||
.Select(pair => pair.Key)
|
||||
.Where(r => !r.Equals(ruleset.Value.ShortName, StringComparison.Ordinal))
|
||||
.Prepend(ruleset.Value.ShortName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -148,8 +148,7 @@ namespace osu.Game
|
||||
[Resolved]
|
||||
private FrameworkConfigManager frameworkConfig { get; set; }
|
||||
|
||||
[Cached]
|
||||
private readonly DifficultyRecommender difficultyRecommender = new DifficultyRecommender();
|
||||
private DifficultyRecommender difficultyRecommender;
|
||||
|
||||
[Cached]
|
||||
private readonly LegacyImportManager legacyImportManager = new LegacyImportManager();
|
||||
@ -1142,7 +1141,8 @@ namespace osu.Game
|
||||
loadComponentSingleFile(new BackgroundDataStoreProcessor(), Add);
|
||||
loadComponentSingleFile(new DetachedBeatmapStore(), Add, true);
|
||||
|
||||
Add(difficultyRecommender);
|
||||
loadComponentSingleFile(difficultyRecommender = new DifficultyRecommender(statisticsProvider), Add, true);
|
||||
|
||||
Add(externalLinkOpener = new ExternalLinkOpener());
|
||||
Add(new MusicKeyBindingHandler());
|
||||
Add(new OnlineStatusNotifier(() => ScreenStack.CurrentScreen));
|
||||
|
Loading…
Reference in New Issue
Block a user