From 0f223ff2fe533a54803ba8122339f53665709bc7 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Mon, 4 Sep 2023 19:16:06 +0900 Subject: [PATCH 1/6] Write legacy scoring attributes to new table --- .../Commands/CalculatorCommand.cs | 26 ++++++++++- .../ServerDifficultyCalculator.cs | 46 +++++++++++++++---- .../BeatmapProcessor.cs | 2 +- 3 files changed, 64 insertions(+), 10 deletions(-) diff --git a/osu.Server.DifficultyCalculator/Commands/CalculatorCommand.cs b/osu.Server.DifficultyCalculator/Commands/CalculatorCommand.cs index d36a5e9..d447be1 100644 --- a/osu.Server.DifficultyCalculator/Commands/CalculatorCommand.cs +++ b/osu.Server.DifficultyCalculator/Commands/CalculatorCommand.cs @@ -41,6 +41,9 @@ public abstract class CalculatorCommand : CommandBase [Option(CommandOptionType.NoValue, Template = "-dry|--dry-run", Description = "Whether to run the process without writing to the database.")] public bool DryRun { get; set; } + [Option(CommandOptionType.SingleValue, Template = "-pm|--processing-mode", Description = "The mode in which to process beatmaps.")] + public ProcessingModes ProcessingMode { get; set; } + private int[] threadBeatmapIds = null!; private IReporter reporter = null!; @@ -89,7 +92,21 @@ public void OnExecute(CommandLineApplication app, IConsole console) // ensure the correct online id is set beatmap.BeatmapInfo.OnlineID = beatmapId; - calc.ProcessBeatmap(beatmap); + switch (ProcessingMode) + { + case ProcessingModes.All: + calc.ProcessAll(beatmap); + break; + + case ProcessingModes.Difficulty: + calc.ProcessDifficulty(beatmap); + break; + + case ProcessingModes.ScoreAttributes: + calc.ProcessLegacyAttributes(beatmap); + break; + } + reporter.Verbose($"Difficulty updated for beatmap {beatmapId}."); } catch (Exception e) @@ -151,5 +168,12 @@ protected string CombineSqlConditions(params string?[] conditions) } protected abstract IEnumerable GetBeatmaps(); + + public enum ProcessingModes + { + All, + Difficulty, + ScoreAttributes + } } } diff --git a/osu.Server.DifficultyCalculator/ServerDifficultyCalculator.cs b/osu.Server.DifficultyCalculator/ServerDifficultyCalculator.cs index 5105297..9e83323 100644 --- a/osu.Server.DifficultyCalculator/ServerDifficultyCalculator.cs +++ b/osu.Server.DifficultyCalculator/ServerDifficultyCalculator.cs @@ -11,6 +11,7 @@ using osu.Game.Beatmaps; using osu.Game.Beatmaps.Legacy; using osu.Game.Rulesets; +using osu.Game.Rulesets.Scoring.Legacy; namespace osu.Server.DifficultyCalculator { @@ -38,7 +39,17 @@ public ServerDifficultyCalculator(int[]? rulesetIds = null, bool processConverts } } - public void ProcessBeatmap(WorkingBeatmap beatmap) + public void ProcessAll(WorkingBeatmap beatmap) + { + ProcessDifficulty(beatmap); + ProcessLegacyAttributes(beatmap); + } + + public void ProcessDifficulty(WorkingBeatmap beatmap) => run(beatmap, processDifficulty); + + public void ProcessLegacyAttributes(WorkingBeatmap beatmap) => run(beatmap, processLegacyAttributes); + + private void run(WorkingBeatmap beatmap, Action callback) { int beatmapId = beatmap.BeatmapInfo.OnlineID; @@ -58,10 +69,10 @@ public void ProcessBeatmap(WorkingBeatmap beatmap) if (processConverts && beatmap.BeatmapInfo.Ruleset.OnlineID == 0) { foreach (var ruleset in processableRulesets) - computeDifficulty(beatmapId, beatmap, ruleset, conn); + callback(beatmapId, beatmap, ruleset, conn); } else if (processableRulesets.Any(r => r.RulesetInfo.OnlineID == beatmap.BeatmapInfo.Ruleset.OnlineID)) - computeDifficulty(beatmapId, beatmap, beatmap.BeatmapInfo.Ruleset.CreateInstance(), conn); + callback(beatmapId, beatmap, beatmap.BeatmapInfo.Ruleset.CreateInstance(), conn); } } catch (Exception e) @@ -70,12 +81,9 @@ public void ProcessBeatmap(WorkingBeatmap beatmap) } } - private void computeDifficulty(int beatmapId, WorkingBeatmap beatmap, Ruleset ruleset, MySqlConnection conn) + private void processDifficulty(int beatmapId, WorkingBeatmap beatmap, Ruleset ruleset, MySqlConnection conn) { - var difficultyCalculator = ruleset.CreateDifficultyCalculator(beatmap); - difficultyCalculator.ComputeLegacyScoringValues = true; - - foreach (var attribute in difficultyCalculator.CalculateAllLegacyCombinations()) + foreach (var attribute in ruleset.CreateDifficultyCalculator(beatmap).CalculateAllLegacyCombinations()) { if (dryRun) continue; @@ -152,6 +160,28 @@ private void computeDifficulty(int beatmapId, WorkingBeatmap beatmap, Ruleset ru } } + private void processLegacyAttributes(int beatmapId, WorkingBeatmap beatmap, Ruleset ruleset, MySqlConnection conn) + { + ILegacyScoreSimulator simulator = ((ILegacyRuleset)ruleset).CreateLegacyScoreSimulator(); + LegacyScoreAttributes attributes = simulator.Simulate(beatmap, beatmap.GetPlayableBeatmap(ruleset.RulesetInfo)); + + if (dryRun) + return; + + conn.Execute( + "INSERT INTO `osu_beatmap_scoring_attribs` (`beatmap_id`, `mode`, `legacy_accuracy_score`, `legacy_combo_score`, `legacy_bonus_score_ratio`) " + + "VALUES (@BeatmapId, @Mode, @AccuracyScore, @ComboScore, @BonusScoreRatio) " + + "ON DUPLICATE KEY UPDATE `legacy_accuracy_score` = @AccuracyScore, `legacy_combo_score` = @ComboScore, `legacy_bonus_score_ratio` = @BonusScoreRatio", + new + { + BeatmapId = beatmapId, + Mode = ruleset.RulesetInfo.OnlineID, + AccuracyScore = attributes.AccuracyScore, + ComboScore = attributes.ComboScore, + BonusScoreRatio = attributes.BonusScoreRatio + }); + } + private static List getRulesets() { const string ruleset_library_prefix = "osu.Game.Rulesets"; diff --git a/osu.Server.Queues.BeatmapProcessor/BeatmapProcessor.cs b/osu.Server.Queues.BeatmapProcessor/BeatmapProcessor.cs index b2319f0..2412e1e 100644 --- a/osu.Server.Queues.BeatmapProcessor/BeatmapProcessor.cs +++ b/osu.Server.Queues.BeatmapProcessor/BeatmapProcessor.cs @@ -34,7 +34,7 @@ protected override void ProcessResult(BeatmapItem item) // ensure the correct online id is set working.BeatmapInfo.OnlineID = (int)beatmapId; - calculator.ProcessBeatmap(working); + calculator.ProcessDifficulty(working); } } } From a430a7a56e4fbe37e6f6dcff3e29e431a4e76f78 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Fri, 8 Sep 2023 03:47:09 +0900 Subject: [PATCH 2/6] Add classic mod for legacy scoring attribs --- .../ServerDifficultyCalculator.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/osu.Server.DifficultyCalculator/ServerDifficultyCalculator.cs b/osu.Server.DifficultyCalculator/ServerDifficultyCalculator.cs index 9e83323..5925281 100644 --- a/osu.Server.DifficultyCalculator/ServerDifficultyCalculator.cs +++ b/osu.Server.DifficultyCalculator/ServerDifficultyCalculator.cs @@ -11,6 +11,7 @@ using osu.Game.Beatmaps; using osu.Game.Beatmaps.Legacy; using osu.Game.Rulesets; +using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Scoring.Legacy; namespace osu.Server.DifficultyCalculator @@ -162,8 +163,11 @@ private void processDifficulty(int beatmapId, WorkingBeatmap beatmap, Ruleset ru private void processLegacyAttributes(int beatmapId, WorkingBeatmap beatmap, Ruleset ruleset, MySqlConnection conn) { + Mod? classicMod = ruleset.CreateMod(); + Mod[] mods = classicMod != null ? new[] { classicMod } : Array.Empty(); + ILegacyScoreSimulator simulator = ((ILegacyRuleset)ruleset).CreateLegacyScoreSimulator(); - LegacyScoreAttributes attributes = simulator.Simulate(beatmap, beatmap.GetPlayableBeatmap(ruleset.RulesetInfo)); + LegacyScoreAttributes attributes = simulator.Simulate(beatmap, beatmap.GetPlayableBeatmap(ruleset.RulesetInfo, mods)); if (dryRun) return; From 30611c7c56d874de4d45cbfc6b78dc3c133d5970 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Thu, 28 Sep 2023 15:37:05 +0900 Subject: [PATCH 3/6] Process everything in watch mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bartłomiej Dach --- osu.Server.Queues.BeatmapProcessor/BeatmapProcessor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Server.Queues.BeatmapProcessor/BeatmapProcessor.cs b/osu.Server.Queues.BeatmapProcessor/BeatmapProcessor.cs index 2412e1e..27c2a43 100644 --- a/osu.Server.Queues.BeatmapProcessor/BeatmapProcessor.cs +++ b/osu.Server.Queues.BeatmapProcessor/BeatmapProcessor.cs @@ -34,7 +34,7 @@ protected override void ProcessResult(BeatmapItem item) // ensure the correct online id is set working.BeatmapInfo.OnlineID = (int)beatmapId; - calculator.ProcessDifficulty(working); + calculator.ProcessAll(working); } } } From a8b558449c5f5014c7317effb961ff96bfb93d79 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 28 Sep 2023 19:18:19 +0900 Subject: [PATCH 4/6] Reduce inspection level for redundant anonymous type names --- osu.Server.DifficultyCalculator.sln.DotSettings | 1 + 1 file changed, 1 insertion(+) diff --git a/osu.Server.DifficultyCalculator.sln.DotSettings b/osu.Server.DifficultyCalculator.sln.DotSettings index 866c5b9..ec52d49 100644 --- a/osu.Server.DifficultyCalculator.sln.DotSettings +++ b/osu.Server.DifficultyCalculator.sln.DotSettings @@ -128,6 +128,7 @@ HINT WARNING WARNING + HINT HINT WARNING WARNING From 4b11886d8ae3bdd5f9b61c28251c9f2e136eed99 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 28 Sep 2023 19:27:11 +0900 Subject: [PATCH 5/6] Update game (and other) packages --- .../osu.Server.DifficultyCalculator.csproj | 20 +++++++++---------- .../osu.Server.Queues.BeatmapProcessor.csproj | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/osu.Server.DifficultyCalculator/osu.Server.DifficultyCalculator.csproj b/osu.Server.DifficultyCalculator/osu.Server.DifficultyCalculator.csproj index 3588352..338cbc3 100644 --- a/osu.Server.DifficultyCalculator/osu.Server.DifficultyCalculator.csproj +++ b/osu.Server.DifficultyCalculator/osu.Server.DifficultyCalculator.csproj @@ -10,18 +10,18 @@ true - + - - - - + + + + - - - - - + + + + + diff --git a/osu.Server.Queues.BeatmapProcessor/osu.Server.Queues.BeatmapProcessor.csproj b/osu.Server.Queues.BeatmapProcessor/osu.Server.Queues.BeatmapProcessor.csproj index 6667b8a..3ed014d 100644 --- a/osu.Server.Queues.BeatmapProcessor/osu.Server.Queues.BeatmapProcessor.csproj +++ b/osu.Server.Queues.BeatmapProcessor/osu.Server.Queues.BeatmapProcessor.csproj @@ -10,8 +10,8 @@ - - + + From 054961d998cf730fe9ff8b457da8e248abca5d77 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 28 Sep 2023 19:31:30 +0900 Subject: [PATCH 6/6] Remove `-pm` flags (kinda goes against standards) --- osu.Server.DifficultyCalculator/Commands/CalculatorCommand.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Server.DifficultyCalculator/Commands/CalculatorCommand.cs b/osu.Server.DifficultyCalculator/Commands/CalculatorCommand.cs index d447be1..4b22d9b 100644 --- a/osu.Server.DifficultyCalculator/Commands/CalculatorCommand.cs +++ b/osu.Server.DifficultyCalculator/Commands/CalculatorCommand.cs @@ -41,8 +41,8 @@ public abstract class CalculatorCommand : CommandBase [Option(CommandOptionType.NoValue, Template = "-dry|--dry-run", Description = "Whether to run the process without writing to the database.")] public bool DryRun { get; set; } - [Option(CommandOptionType.SingleValue, Template = "-pm|--processing-mode", Description = "The mode in which to process beatmaps.")] - public ProcessingModes ProcessingMode { get; set; } + [Option(CommandOptionType.SingleValue, Template = "--processing-mode", Description = "The mode in which to process beatmaps.")] + public ProcessingModes ProcessingMode { get; set; } = ProcessingModes.All; private int[] threadBeatmapIds = null!; private IReporter reporter = null!;