Skip to content

Commit

Permalink
Merge pull request #189 from smoogipoo/add-score-conversion-output
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy authored Dec 5, 2023
2 parents b050937 + 1d5a75a commit 63c8dc0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
20 changes: 15 additions & 5 deletions PerformanceCalculator/Performance/ReplayPerformanceCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
using JetBrains.Annotations;
using McMaster.Extensions.CommandLineUtils;
using osu.Game.Beatmaps;
using osu.Game.Database;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Scoring.Legacy;
using osu.Game.Scoring;
using osu.Game.Scoring.Legacy;

Expand All @@ -30,17 +32,25 @@ public override void Execute()
using (var stream = File.OpenRead(Replay))
score = scoreDecoder.Parse(stream);

var ruleset = score.ScoreInfo.Ruleset.CreateInstance();

// At this point the beatmap will have been cached locally due to the lookup during decode, so this is practically free.
var workingBeatmap = ProcessorWorkingBeatmap.FromFileOrId(score.ScoreInfo.BeatmapInfo!.OnlineID.ToString());
var playableBeatmap = workingBeatmap.GetPlayableBeatmap(ruleset.RulesetInfo, score.ScoreInfo.Mods);

var ruleset = score.ScoreInfo.Ruleset.CreateInstance();
var difficultyCalculator = ruleset.CreateDifficultyCalculator(workingBeatmap);
Mod[] difficultyMods = score.ScoreInfo.Mods;

Mod[] mods = score.ScoreInfo.Mods;
if (score.ScoreInfo.IsLegacyScore)
mods = LegacyHelper.ConvertToLegacyDifficultyAdjustmentMods(workingBeatmap.BeatmapInfo, ruleset, mods);
{
difficultyMods = LegacyHelper.ConvertToLegacyDifficultyAdjustmentMods(workingBeatmap.BeatmapInfo, ruleset, difficultyMods);
score.ScoreInfo.LegacyTotalScore = (int)score.ScoreInfo.TotalScore;
score.ScoreInfo.TotalScore = StandardisedScoreMigrationTools.ConvertFromLegacyTotalScore(
score.ScoreInfo,
LegacyBeatmapConversionDifficultyInfo.FromBeatmap(playableBeatmap),
((ILegacyRuleset)ruleset).CreateLegacyScoreSimulator().Simulate(workingBeatmap, playableBeatmap));
}

var difficultyAttributes = difficultyCalculator.Calculate(mods);
var difficultyAttributes = ruleset.CreateDifficultyCalculator(workingBeatmap).Calculate(difficultyMods);
var performanceCalculator = score.ScoreInfo.Ruleset.CreateInstance().CreatePerformanceCalculator();
var performanceAttributes = performanceCalculator?.Calculate(score.ScoreInfo, difficultyAttributes);

Expand Down
15 changes: 14 additions & 1 deletion PerformanceCalculator/Performance/ScorePerformanceCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
using System.Linq;
using McMaster.Extensions.CommandLineUtils;
using osu.Game.Beatmaps;
using osu.Game.Database;
using osu.Game.Models;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Scoring.Legacy;

namespace PerformanceCalculator.Performance
{
Expand All @@ -28,17 +31,27 @@ public override void Execute()

var ruleset = LegacyHelper.GetRulesetFromLegacyID(apiScore.RulesetID);
var score = apiScore.ToScoreInfo(apiScore.Mods.Select(m => m.ToMod(ruleset)).ToArray(), apiBeatmap);
score.Ruleset = ruleset.RulesetInfo;
score.BeatmapInfo!.Metadata = new BeatmapMetadata
{
Title = apiBeatmap.Metadata.Title,
Artist = apiBeatmap.Metadata.Artist,
Author = new RealmUser { Username = apiBeatmap.Metadata.Author.Username },
};

var workingBeatmap = ProcessorWorkingBeatmap.FromFileOrId(score.BeatmapInfo!.OnlineID.ToString());

if (apiScore.BuildID == null)
{
score.Mods = score.Mods.Append(ruleset.CreateMod<ModClassic>()).ToArray();
score.IsLegacyScore = true;
score.LegacyTotalScore = (int)score.TotalScore;
score.TotalScore = StandardisedScoreMigrationTools.ConvertFromLegacyTotalScore(
score,
LegacyBeatmapConversionDifficultyInfo.FromAPIBeatmap(apiBeatmap),
((ILegacyRuleset)ruleset).CreateLegacyScoreSimulator().Simulate(workingBeatmap, workingBeatmap.GetPlayableBeatmap(ruleset.RulesetInfo, score.Mods)));
}

var workingBeatmap = ProcessorWorkingBeatmap.FromFileOrId(score.BeatmapInfo!.OnlineID.ToString());
var difficultyCalculator = ruleset.CreateDifficultyCalculator(workingBeatmap);
var difficultyAttributes = difficultyCalculator.Calculate(LegacyHelper.ConvertToLegacyDifficultyAdjustmentMods(workingBeatmap.BeatmapInfo, ruleset, score.Mods));
var performanceCalculator = ruleset.CreatePerformanceCalculator();
Expand Down
11 changes: 8 additions & 3 deletions PerformanceCalculator/ProcessorCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public void OutputPerformance(ScoreInfo score, PerformanceAttributes performance
BeatmapId = score.BeatmapInfo?.OnlineID ?? -1,
Beatmap = score.BeatmapInfo?.ToString() ?? "Unknown beatmap",
Mods = score.Mods.Select(m => new APIMod(m)).ToList(),
Score = score.TotalScore,
TotalScore = score.TotalScore,
LegacyTotalScore = score.LegacyTotalScore ?? 0,
Accuracy = score.Accuracy * 100,
Combo = score.MaxCombo,
Statistics = score.Statistics
Expand All @@ -76,7 +77,8 @@ public void OutputPerformance(ScoreInfo score, PerformanceAttributes performance

document.Children.Add(
FormatDocumentLine("beatmap", $"{result.Score.BeatmapId} - {result.Score.Beatmap}"),
FormatDocumentLine("score", result.Score.Score.ToString(CultureInfo.InvariantCulture)),
FormatDocumentLine("total score", result.Score.TotalScore.ToString(CultureInfo.InvariantCulture)),
FormatDocumentLine("legacy total score", result.Score.LegacyTotalScore.ToString(CultureInfo.InvariantCulture)),
FormatDocumentLine("accuracy", result.Score.Accuracy.ToString("N2", CultureInfo.InvariantCulture)),
FormatDocumentLine("combo", result.Score.Combo.ToString(CultureInfo.InvariantCulture)),
FormatDocumentLine("mods", result.Score.Mods.Count > 0 ? result.Score.Mods.Select(m => m.ToString()).Aggregate((c, n) => $"{c}, {n}") : "None")
Expand Down Expand Up @@ -168,7 +170,10 @@ private class ScoreStatistics
public List<APIMod> Mods { get; set; }

[JsonProperty("total_score")]
public long Score { get; set; }
public long TotalScore { get; set; }

[JsonProperty("legacy_total_score")]
public long LegacyTotalScore { get; set; }

[JsonProperty("accuracy")]
public double Accuracy { get; set; }
Expand Down

0 comments on commit 63c8dc0

Please sign in to comment.