Skip to content

Commit

Permalink
Update hitobject counts when writing to osu_beatmaps
Browse files Browse the repository at this point in the history
  • Loading branch information
smoogipoo committed Nov 11, 2024
1 parent 4529f67 commit 451f0bc
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 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 Down Expand Up @@ -150,6 +151,20 @@ private void processDifficulty(ProcessableItem item, MySqlConnection conn)
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)
countSlider++;
if ((obj.LegacyType & LegacyHitObjectType.Spinner) > 0)
countSpinner++;
}

object param = new
{
BeatmapId = item.BeatmapID,
Expand All @@ -160,20 +175,24 @@ private void processDifficulty(ProcessableItem item, MySqlConnection conn)
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);
}
Expand Down

0 comments on commit 451f0bc

Please sign in to comment.