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

Update hitobject counts in osu_beatmaps table #233

Merged
merged 4 commits into from
Nov 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
79 changes: 49 additions & 30 deletions osu.Server.DifficultyCalculator/ServerDifficultyCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using osu.Game.Beatmaps.Legacy;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Objects.Legacy;
using osu.Game.Rulesets.Scoring.Legacy;
using osu.Server.DifficultyCalculator.Commands;

Expand All @@ -23,7 +24,7 @@

private readonly bool processConverts;
private readonly bool dryRun;
private readonly List<Ruleset> processableRulesets = new List<Ruleset>();

Check notice on line 27 in osu.Server.DifficultyCalculator/ServerDifficultyCalculator.cs

View workflow job for this annotation

GitHub Actions / Code Quality

Redundant type specification in osu.Server.DifficultyCalculator\ServerDifficultyCalculator.cs on line 27

public ServerDifficultyCalculator(int[]? rulesetIds = null, bool processConverts = true, bool dryRun = false)
{
Expand Down Expand Up @@ -67,7 +68,7 @@

public void ProcessLegacyAttributes(WorkingBeatmap beatmap) => run(beatmap, processLegacyAttributes);

private void run(WorkingBeatmap beatmap, Action<ProcessableBeatmap, MySqlConnection> callback)
private void run(WorkingBeatmap beatmap, Action<ProcessableItem, MySqlConnection> callback)
{
try
{
Expand All @@ -89,10 +90,10 @@
if (processConverts && beatmap.BeatmapInfo.Ruleset.OnlineID == 0)
{
foreach (var ruleset in processableRulesets)
callback(new ProcessableBeatmap(beatmap, ruleset, ranked), conn);
callback(new ProcessableItem(beatmap, ruleset, ranked), conn);
}
else if (processableRulesets.Any(r => r.RulesetInfo.OnlineID == beatmap.BeatmapInfo.Ruleset.OnlineID))
callback(new ProcessableBeatmap(beatmap, beatmap.BeatmapInfo.Ruleset.CreateInstance(), ranked), conn);
callback(new ProcessableItem(beatmap, beatmap.BeatmapInfo.Ruleset.CreateInstance(), ranked), conn);
}
}
catch (Exception e)
Expand All @@ -101,37 +102,37 @@
}
}

private void processDifficulty(ProcessableBeatmap beatmap, MySqlConnection conn)
private void processDifficulty(ProcessableItem item, MySqlConnection conn)
{
foreach (var attribute in beatmap.Ruleset.CreateDifficultyCalculator(beatmap.Beatmap).CalculateAllLegacyCombinations())
foreach (var attribute in item.Ruleset.CreateDifficultyCalculator(item.WorkingBeatmap).CalculateAllLegacyCombinations())
{
if (dryRun)
continue;

LegacyMods legacyMods = beatmap.Ruleset.ConvertToLegacyMods(attribute.Mods);
LegacyMods legacyMods = item.Ruleset.ConvertToLegacyMods(attribute.Mods);

conn.Execute(
"INSERT INTO `osu_beatmap_difficulty` (`beatmap_id`, `mode`, `mods`, `diff_unified`) "
+ "VALUES (@BeatmapId, @Mode, @Mods, @Diff) "
+ "ON DUPLICATE KEY UPDATE `diff_unified` = @Diff",
new
{
BeatmapId = beatmap.BeatmapID,
Mode = beatmap.RulesetID,
BeatmapId = item.BeatmapID,
Mode = item.RulesetID,
Mods = (int)legacyMods,
Diff = attribute.StarRating
});

if (beatmap.Ranked && !AppSettings.SKIP_INSERT_ATTRIBUTES)
if (item.Ranked && !AppSettings.SKIP_INSERT_ATTRIBUTES)
{
var parameters = new List<object>();

foreach (var mapping in attribute.ToDatabaseAttributes())
{
parameters.Add(new
{
BeatmapId = beatmap.BeatmapID,
Mode = beatmap.RulesetID,
BeatmapId = item.BeatmapID,
Mode = item.RulesetID,
Mods = (int)legacyMods,
Attribute = mapping.attributeId,
Value = Convert.ToSingle(mapping.value)
Expand All @@ -145,49 +146,67 @@
parameters.ToArray());
}

if (legacyMods == LegacyMods.None && beatmap.Ruleset.RulesetInfo.Equals(beatmap.Beatmap.BeatmapInfo.Ruleset))
if (legacyMods == LegacyMods.None && item.Ruleset.RulesetInfo.Equals(item.WorkingBeatmap.BeatmapInfo.Ruleset))
{
double beatLength = beatmap.Beatmap.Beatmap.GetMostCommonBeatLength();
double beatLength = item.WorkingBeatmap.Beatmap.GetMostCommonBeatLength();
double bpm = beatLength > 0 ? 60000 / beatLength : 0;

int countCircle = 0;
int countSlider = 0;
int countSpinner = 0;

foreach (var obj in item.WorkingBeatmap.Beatmap.HitObjects.OfType<IHasLegacyHitObjectType>())
{
if ((obj.LegacyType & LegacyHitObjectType.Circle) > 0)
countCircle++;
if ((obj.LegacyType & LegacyHitObjectType.Slider) > 0)
Copy link
Contributor

@bdach bdach Nov 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing by as I update ppy/osu-server-beatmap-submission#1 to use LegacyHitObjectType too - not sure if it's gonna matter, but BSS included LegacyHitObjectType.Hold in this count too, and I'm about to mirror that. Could prove important for mania maps.

Copy link
Contributor

@bdach bdach Nov 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How... did I miss that D:

countSlider++;
if ((obj.LegacyType & LegacyHitObjectType.Spinner) > 0)
countSpinner++;
}

object param = new
{
BeatmapId = beatmap.BeatmapID,
BeatmapId = item.BeatmapID,
Diff = attribute.StarRating,
AR = beatmap.Beatmap.BeatmapInfo.Difficulty.ApproachRate,
OD = beatmap.Beatmap.BeatmapInfo.Difficulty.OverallDifficulty,
HP = beatmap.Beatmap.BeatmapInfo.Difficulty.DrainRate,
CS = beatmap.Beatmap.BeatmapInfo.Difficulty.CircleSize,
AR = item.WorkingBeatmap.BeatmapInfo.Difficulty.ApproachRate,
OD = item.WorkingBeatmap.BeatmapInfo.Difficulty.OverallDifficulty,
HP = item.WorkingBeatmap.BeatmapInfo.Difficulty.DrainRate,
CS = item.WorkingBeatmap.BeatmapInfo.Difficulty.CircleSize,
BPM = Math.Round(bpm, 2),
MaxCombo = attribute.MaxCombo,
CountCircle = countCircle,
CountSlider = countSlider,
CountSpinner = countSpinner,
CountTotal = countCircle + countSlider + countSpinner
};

if (AppSettings.INSERT_BEATMAPS)
{
conn.Execute(
"INSERT INTO `osu_beatmaps` (`beatmap_id`, `difficultyrating`, `diff_approach`, `diff_overall`, `diff_drain`, `diff_size`, `bpm`, `max_combo`) "
+ "VALUES (@BeatmapId, @Diff, @AR, @OD, @HP, @CS, @BPM, @MaxCombo) "
+ "ON DUPLICATE KEY UPDATE `difficultyrating` = @Diff, `diff_approach` = @AR, `diff_overall` = @OD, `diff_drain` = @HP, `diff_size` = @CS, `bpm` = @BPM, `max_combo` = @MaxCombo",
"INSERT INTO `osu_beatmaps` (`beatmap_id`, `difficultyrating`, `diff_approach`, `diff_overall`, `diff_drain`, `diff_size`, `bpm`, `max_combo`, `countNormal`, `countSlider`, `countSpinner`, `countTotal`) "
+ "VALUES (@BeatmapId, @Diff, @AR, @OD, @HP, @CS, @BPM, @MaxCombo, @CountCircle, @CountSlider, @CountSpinner, @CountTotal) "
+ "ON DUPLICATE KEY UPDATE `difficultyrating` = @Diff, `diff_approach` = @AR, `diff_overall` = @OD, `diff_drain` = @HP, `diff_size` = @CS, `bpm` = @BPM, `max_combo` = @MaxCombo, `countNormal` = @CountCircle, `countSlider` = @CountSlider, `countSpinner` = @CountSpinner, `countTotal` = @CountTotal",
param);
}
else
{
conn.Execute(
"UPDATE `osu_beatmaps` SET `difficultyrating` = @Diff, `diff_approach` = @AR, `diff_overall` = @OD, `diff_drain` = @HP, `diff_size` = @CS, `bpm` = @BPM , `max_combo` = @MaxCombo "
"UPDATE `osu_beatmaps` SET `difficultyrating` = @Diff, `diff_approach` = @AR, `diff_overall` = @OD, `diff_drain` = @HP, `diff_size` = @CS, `bpm` = @BPM , `max_combo` = @MaxCombo, `countNormal` = @CountCircle, `countSlider` = @CountSlider, `countSpinner` = @CountSpinner, `countTotal` = @CountTotal "
+ "WHERE `beatmap_id` = @BeatmapId",
param);
}
}
}
}

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

Check notice on line 206 in osu.Server.DifficultyCalculator/ServerDifficultyCalculator.cs

View workflow job for this annotation

GitHub Actions / Code Quality

Use collection expression in osu.Server.DifficultyCalculator\ServerDifficultyCalculator.cs on line 206

ILegacyScoreSimulator simulator = ((ILegacyRuleset)beatmap.Ruleset).CreateLegacyScoreSimulator();
LegacyScoreAttributes attributes = simulator.Simulate(beatmap.Beatmap, beatmap.Beatmap.GetPlayableBeatmap(beatmap.Ruleset.RulesetInfo, mods));
ILegacyScoreSimulator simulator = ((ILegacyRuleset)item.Ruleset).CreateLegacyScoreSimulator();
LegacyScoreAttributes attributes = simulator.Simulate(item.WorkingBeatmap, item.WorkingBeatmap.GetPlayableBeatmap(item.Ruleset.RulesetInfo, mods));

if (dryRun)
return;
Expand All @@ -198,8 +217,8 @@
+ "ON DUPLICATE KEY UPDATE `legacy_accuracy_score` = @AccuracyScore, `legacy_combo_score` = @ComboScore, `legacy_bonus_score_ratio` = @BonusScoreRatio, `legacy_bonus_score` = @BonusScore, `max_combo` = @MaxCombo",
new
{
BeatmapId = beatmap.BeatmapID,
Mode = beatmap.RulesetID,
BeatmapId = item.BeatmapID,
Mode = item.RulesetID,
AccuracyScore = attributes.AccuracyScore,
ComboScore = attributes.ComboScore,
BonusScoreRatio = attributes.BonusScoreRatio,
Expand Down Expand Up @@ -231,9 +250,9 @@
return rulesetsToProcess;
}

private readonly record struct ProcessableBeatmap(WorkingBeatmap Beatmap, Ruleset Ruleset, bool Ranked)
private readonly record struct ProcessableItem(WorkingBeatmap WorkingBeatmap, Ruleset Ruleset, bool Ranked)
{
public int BeatmapID => Beatmap.BeatmapInfo.OnlineID;
public int BeatmapID => WorkingBeatmap.BeatmapInfo.OnlineID;
public int RulesetID => Ruleset.RulesetInfo.OnlineID;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
<PackageReference Include="Dapper" Version="2.1.44" />
<PackageReference Include="Dapper.Contrib" Version="2.0.78" />
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="4.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.1" />
<PackageReference Include="MySqlConnector" Version="2.3.7" />
<PackageReference Include="ppy.osu.Game" Version="2024.1104.0" />
<PackageReference Include="ppy.osu.Game.Rulesets.Osu" Version="2024.1104.0" />
<PackageReference Include="ppy.osu.Game.Rulesets.Taiko" Version="2024.1104.0" />
<PackageReference Include="ppy.osu.Game.Rulesets.Catch" Version="2024.1104.0" />
<PackageReference Include="ppy.osu.Game.Rulesets.Mania" Version="2024.1104.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0" />
<PackageReference Include="MySqlConnector" Version="2.4.0" />
<PackageReference Include="ppy.osu.Game" Version="2024.1115.1" />
<PackageReference Include="ppy.osu.Game.Rulesets.Osu" Version="2024.1115.1" />
<PackageReference Include="ppy.osu.Game.Rulesets.Taiko" Version="2024.1115.1" />
<PackageReference Include="ppy.osu.Game.Rulesets.Catch" Version="2024.1115.1" />
<PackageReference Include="ppy.osu.Game.Rulesets.Mania" Version="2024.1115.1" />
</ItemGroup>
<ItemGroup>
<None Update="appsettings.*.json">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<ItemGroup>
<PackageReference Include="Dapper" Version="2.1.44" />
<PackageReference Include="ppy.osu.Server.OsuQueueProcessor" Version="2024.507.0" />
<PackageReference Include="ppy.osu.Server.OsuQueueProcessor" Version="2024.1111.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading