-
Notifications
You must be signed in to change notification settings - Fork 15
Enforce real time difficulty for mod combinations which are not stored in the database #274
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
Open
tsunyoku
wants to merge
31
commits into
ppy:master
Choose a base branch
from
tsunyoku:partial-real-time-difficulty
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
2563d86
enforce realtime difficulty calculation when using non-default config…
tsunyoku 9d2cd87
add additional support for realtime calculations on non-legacy mods
tsunyoku 3b159d5
line endings
tsunyoku 435a1f5
remove unneeded interpolation
tsunyoku 749f505
line endings
tsunyoku 8aae8a2
fix CL edge case
tsunyoku 927af4e
rename `isLegacyMod` to `isRankedLegacyMod` and add missing mania mods
tsunyoku 59ca627
line endings (sigh)
tsunyoku 9835e52
add `OsuModSpunOut`
tsunyoku 8480823
handle hard rock being unranked for mania
tsunyoku b540e7b
use `ALWAYS_REALTIME_DIFFICULTY` in `DatabaseTest`
tsunyoku 5e1b1d9
line endings
tsunyoku f514a3c
add test
tsunyoku 26636d0
line endings
tsunyoku 0ec8c96
enforce realtime difficulty calculation when using non-default config…
tsunyoku 12217e7
remove unneeded interpolation
tsunyoku be5a334
fix CL edge case
tsunyoku c03acf1
rename `isLegacyMod` to `isRankedLegacyMod` and add missing mania mods
tsunyoku ff2aa59
add `OsuModSpunOut`
tsunyoku 7bbb452
handle hard rock being unranked for mania
tsunyoku b3ed260
use `ALWAYS_REALTIME_DIFFICULTY` in `DatabaseTest`
tsunyoku fc5e32a
add test
tsunyoku ffb1b48
Merge branch 'partial-real-time-difficulty' of https://github.com/tsu…
tsunyoku 2f562cd
rename env var to `PREFER_REALTIME_DIFFICULTY`
tsunyoku 808dc5f
fix README grammar
tsunyoku 19f72cb
move prefer naming back to always
tsunyoku 2abc9b2
rename to ALWAYS_USE_REALTIME_DIFFICULTY
tsunyoku 09efc44
more precise legacy mod checking
tsunyoku 327669a
Add preventative test coverage guarding against accidental inheritance
bdach 8b57913
Remove space in envvar name
bdach 68f0ce1
Merge branch 'master' into partial-real-time-difficulty
bdach File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| using System; | ||
| using System.Collections.Concurrent; | ||
| using System.Collections.Generic; | ||
| using System.Diagnostics; | ||
| using System.Diagnostics.CodeAnalysis; | ||
| using System.Linq; | ||
| using System.Threading.Tasks; | ||
|
|
@@ -17,6 +18,7 @@ | |
| using osu.Game.Rulesets.Mods; | ||
| using osu.Server.Queues.ScoreStatisticsProcessor.Helpers; | ||
| using osu.Server.Queues.ScoreStatisticsProcessor.Models; | ||
| using StatsdClient; | ||
| using Beatmap = osu.Server.Queues.ScoreStatisticsProcessor.Models.Beatmap; | ||
|
|
||
| namespace osu.Server.Queues.ScoreStatisticsProcessor.Stores | ||
|
|
@@ -26,7 +28,7 @@ namespace osu.Server.Queues.ScoreStatisticsProcessor.Stores | |
| /// </summary> | ||
| public class BeatmapStore | ||
| { | ||
| private static readonly bool use_realtime_difficulty_calculation = Environment.GetEnvironmentVariable("REALTIME_DIFFICULTY") != "0"; | ||
| private static readonly bool always_use_realtime_difficulty_calculation = Environment.GetEnvironmentVariable("ALWAYS_REALTIME_DIFFICULTY") != "0"; | ||
| private static readonly string beatmap_download_path = Environment.GetEnvironmentVariable("BEATMAP_DOWNLOAD_PATH") ?? "https://osu.ppy.sh/osu/{0}"; | ||
|
|
||
| private readonly ConcurrentDictionary<uint, Beatmap?> beatmapCache = new ConcurrentDictionary<uint, Beatmap?>(); | ||
|
|
@@ -65,8 +67,16 @@ public static async Task<BeatmapStore> CreateAsync(MySqlConnection connection, M | |
| /// <returns>The difficulty attributes or <c>null</c> if not existing.</returns> | ||
| public async Task<DifficultyAttributes?> GetDifficultyAttributesAsync(Beatmap beatmap, Ruleset ruleset, Mod[] mods, MySqlConnection connection, MySqlTransaction? transaction = null) | ||
| { | ||
| if (use_realtime_difficulty_calculation) | ||
| // database attributes are stored using the default mod configurations | ||
| // if we want to support mods with non-default configurations (i.e non-1.5x rates on DT/NC) | ||
| // or non-legacy mods which aren't populated into the database (with exception to CL) | ||
| // then we must calculate difficulty attributes in real-time. | ||
| bool mustUseRealtimeDifficulty = mods.Any(m => !m.UsesDefaultConfiguration || (!isLegacyMod(m) && m is not ModClassic)); | ||
|
|
||
| if (always_use_realtime_difficulty_calculation || mustUseRealtimeDifficulty) | ||
| { | ||
| var stopwatch = Stopwatch.StartNew(); | ||
|
|
||
| using var req = new WebRequest(string.Format(beatmap_download_path, beatmap.beatmap_id)); | ||
|
|
||
| req.AllowInsecureRequests = true; | ||
|
|
@@ -79,7 +89,17 @@ public static async Task<BeatmapStore> CreateAsync(MySqlConnection connection, M | |
| var workingBeatmap = new StreamedWorkingBeatmap(req.ResponseStream); | ||
| var calculator = ruleset.CreateDifficultyCalculator(workingBeatmap); | ||
|
|
||
| return calculator.Calculate(mods); | ||
| var attributes = calculator.Calculate(mods); | ||
|
|
||
| string[] tags = | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have to make sure to turn off indexing on these as soon as it goes live or we'll rack up a $1000 bill in no time |
||
| { | ||
| $"ruleset:{ruleset.RulesetInfo.OnlineID}", | ||
| $"mods:{string.Join("", mods.Select(x => x.Acronym))}" | ||
| }; | ||
|
|
||
| DogStatsd.Timer("calculate-realtime-difficulty-attributes", stopwatch.ElapsedMilliseconds, tags: tags); | ||
|
|
||
| return attributes; | ||
| } | ||
|
|
||
| BeatmapDifficultyAttribute[]? rawDifficultyAttributes; | ||
|
|
@@ -107,12 +127,33 @@ public static async Task<BeatmapStore> CreateAsync(MySqlConnection connection, M | |
| return difficultyAttributes; | ||
| } | ||
|
|
||
| /// <remarks> | ||
| /// This method attempts to create a simple solution to deciding if a <see cref="Mod"/> can be considered a "legacy" mod. | ||
| /// Used by <see cref="GetDifficultyAttributesAsync"/> to decide if the current mod combination's difficulty attributes | ||
| /// can be fetched from the database. | ||
| /// </remarks> | ||
| private static bool isLegacyMod(Mod mod) => | ||
| mod is ModNoFail | ||
| or ModEasy | ||
| or ModHidden | ||
| or ModHardRock | ||
| or ModPerfect | ||
| or ModSuddenDeath | ||
| or ModNightcore | ||
| or ModDoubleTime | ||
| or ModRelax | ||
| or ModHalfTime | ||
| or ModFlashlight | ||
| or ModCinema | ||
| or ModAutoplay | ||
| or ModScoreV2; | ||
tsunyoku marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /// <remarks> | ||
| /// This method attempts to choose the best possible set of <see cref="LegacyMods"/> to use for looking up stored difficulty attributes. | ||
| /// The match is not always exact; for some mods that award pp but do not exist in stable | ||
| /// (such as <see cref="ModHalfTime"/>) the closest available approximation is used. | ||
| /// Moreover, the set of <see cref="LegacyMods"/> returned is constrained to mods that actually affect difficulty in the legacy sense. | ||
| /// The entirety of this workaround is not used / unnecessary if <see cref="use_realtime_difficulty_calculation"/> is <see langword="true"/>. | ||
| /// The entirety of this workaround is not used / unnecessary if <see cref="always_use_realtime_difficulty_calculation"/> is <see langword="true"/>. | ||
| /// </remarks> | ||
| private static LegacyMods getLegacyModsForAttributeLookup(Beatmap beatmap, Ruleset ruleset, Mod[] mods) | ||
| { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.