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

Fix online attribute flag in score performance command not retrieving full difficulty attributes #204

Merged
Merged
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
26 changes: 22 additions & 4 deletions PerformanceCalculator/Performance/ScorePerformanceCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,41 @@ private DifficultyAttributes queryApiAttributes(int beatmapId, int rulesetId, Le
{ "mods", ((int)mods).ToString(CultureInfo.InvariantCulture) }
};

var beatmap = GetJsonFromApi<APIBeatmap>($"beatmaps/{beatmapId}");

switch (rulesetId)
{
case 0:
return GetJsonFromApi<AttributesResponse<OsuDifficultyAttributes>>($"beatmaps/{beatmapId}/attributes", HttpMethod.Post, parameters).Attributes;
return getMergedAttributes<OsuDifficultyAttributes>(beatmap);

case 1:
return GetJsonFromApi<AttributesResponse<TaikoDifficultyAttributes>>($"beatmaps/{beatmapId}/attributes", HttpMethod.Post, parameters).Attributes;
return getMergedAttributes<TaikoDifficultyAttributes>(beatmap);

case 2:
return GetJsonFromApi<AttributesResponse<CatchDifficultyAttributes>>($"beatmaps/{beatmapId}/attributes", HttpMethod.Post, parameters).Attributes;
return getMergedAttributes<CatchDifficultyAttributes>(beatmap);

case 3:
return GetJsonFromApi<AttributesResponse<ManiaDifficultyAttributes>>($"beatmaps/{beatmapId}/attributes", HttpMethod.Post, parameters).Attributes;
return getMergedAttributes<ManiaDifficultyAttributes>(beatmap);

default:
throw new ArgumentOutOfRangeException(nameof(rulesetId));
}

DifficultyAttributes getMergedAttributes<TAttributes>(APIBeatmap apiBeatmap)
where TAttributes : DifficultyAttributes, new()
{
// the osu-web endpoint queries osu-beatmap-difficulty-cache, which in turn does not return the full set of attributes -
// it skips ones that are already present on `APIBeatmap`
// (https://github.com/ppy/osu-beatmap-difficulty-lookup-cache/blob/db2203368221109803f2031788da31deb94e0f11/BeatmapDifficultyLookupCache/DifficultyCache.cs#L125-L128).
// to circumvent this, do some manual grafting on our side to produce a fully populated set of attributes.
var databasedAttributes = GetJsonFromApi<AttributesResponse<TAttributes>>($"beatmaps/{beatmapId}/attributes", HttpMethod.Post, parameters).Attributes;
var fullAttributes = new TAttributes();
fullAttributes.FromDatabaseAttributes(databasedAttributes.ToDatabaseAttributes().ToDictionary(
pair => pair.attributeId,
pair => Convert.ToDouble(pair.value, CultureInfo.InvariantCulture)
), apiBeatmap);
return fullAttributes;
}
}

[JsonObject(MemberSerialization.OptIn)]
Expand Down
Loading