Skip to content

Commit

Permalink
Merge pull request #224 from smoogipoo/write-legacy-scoring-attributes
Browse files Browse the repository at this point in the history
Write to legacy scoring attributes table
  • Loading branch information
peppy committed Sep 28, 2023
2 parents 0dd8afd + 054961d commit f6f0e85
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 22 deletions.
26 changes: 25 additions & 1 deletion osu.Server.DifficultyCalculator/Commands/CalculatorCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "--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!;

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -151,5 +168,12 @@ protected string CombineSqlConditions(params string?[] conditions)
}

protected abstract IEnumerable<int> GetBeatmaps();

public enum ProcessingModes
{
All,
Difficulty,
ScoreAttributes
}
}
}
50 changes: 42 additions & 8 deletions osu.Server.DifficultyCalculator/ServerDifficultyCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
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
{
Expand Down Expand Up @@ -38,7 +40,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<int, WorkingBeatmap, Ruleset, MySqlConnection> callback)
{
int beatmapId = beatmap.BeatmapInfo.OnlineID;

Expand All @@ -58,10 +70,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)
Expand All @@ -70,12 +82,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;
Expand Down Expand Up @@ -153,6 +162,31 @@ private void computeDifficulty(int beatmapId, WorkingBeatmap beatmap, Ruleset ru
}
}

private void processLegacyAttributes(int beatmapId, WorkingBeatmap beatmap, Ruleset ruleset, MySqlConnection conn)
{
Mod? classicMod = ruleset.CreateMod<ModClassic>();
Mod[] mods = classicMod != null ? new[] { classicMod } : Array.Empty<Mod>();

ILegacyScoreSimulator simulator = ((ILegacyRuleset)ruleset).CreateLegacyScoreSimulator();
LegacyScoreAttributes attributes = simulator.Simulate(beatmap, beatmap.GetPlayableBeatmap(ruleset.RulesetInfo, mods));

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<Ruleset> getRulesets()
{
const string ruleset_library_prefix = "osu.Game.Rulesets";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
<ConcurrentGarbageCollection>true</ConcurrentGarbageCollection>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Dapper" Version="2.0.143" />
<PackageReference Include="Dapper" Version="2.0.151" />
<PackageReference Include="Dapper.Contrib" Version="2.0.78" />
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="4.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="4.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
<PackageReference Include="MySqlConnector" Version="2.2.7" />
<PackageReference Include="ppy.osu.Game" Version="2023.717.0" />
<PackageReference Include="ppy.osu.Game.Rulesets.Osu" Version="2023.717.0" />
<PackageReference Include="ppy.osu.Game.Rulesets.Taiko" Version="2023.717.0" />
<PackageReference Include="ppy.osu.Game.Rulesets.Catch" Version="2023.717.0" />
<PackageReference Include="ppy.osu.Game.Rulesets.Mania" Version="2023.717.0" />
<PackageReference Include="ppy.osu.Game" Version="2023.928.0" />
<PackageReference Include="ppy.osu.Game.Rulesets.Osu" Version="2023.928.0" />
<PackageReference Include="ppy.osu.Game.Rulesets.Taiko" Version="2023.928.0" />
<PackageReference Include="ppy.osu.Game.Rulesets.Catch" Version="2023.928.0" />
<PackageReference Include="ppy.osu.Game.Rulesets.Mania" Version="2023.928.0" />
</ItemGroup>
<ItemGroup>
<None Update="appsettings.*.json">
Expand Down
2 changes: 1 addition & 1 deletion osu.Server.Queues.BeatmapProcessor/BeatmapProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.ProcessAll(working);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Dapper" Version="2.0.143" />
<PackageReference Include="ppy.osu.Server.OsuQueueProcessor" Version="2022.1220.0" />
<PackageReference Include="Dapper" Version="2.0.151" />
<PackageReference Include="ppy.osu.Server.OsuQueueProcessor" Version="2023.822.0" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit f6f0e85

Please sign in to comment.