Skip to content

Commit

Permalink
Merge pull request #189 from smoogipoo/fix-total-score-conversion
Browse files Browse the repository at this point in the history
Update total score/accuracy conversion to new paths
  • Loading branch information
peppy authored Dec 21, 2023
2 parents ba8cf5e + eefa91a commit e8ff6b1
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ public static ScoreItem CreateTestScore(int? rulesetId = null, int? beatmapId =
beatmap_id = beatmapId ?? TEST_BEATMAP_ID,
ruleset_id = (ushort)(rulesetId ?? 0),
created_at = DateTimeOffset.Now,
updated_at = DateTimeOffset.Now,
};

var startTime = new DateTimeOffset(new DateTime(2020, 02, 05));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public void TestSoloScoreDirectSerialisation()

// ignore time values for now until we can figure how to test without precision issues.
deserialised.created_at = score.created_at;
deserialised.updated_at = score.updated_at;

deserialised.ShouldDeepEqual(score);
}
Expand All @@ -55,7 +54,6 @@ public void TestSoloScoreDatabaseSerialisation()

// ignore time values for now until we can figure how to test without precision issues.
retrieved.created_at = score.created_at;
retrieved.updated_at = score.updated_at;

retrieved.ShouldDeepEqual(score);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private async Task processUser(MySqlConnection db, int userId, CancellationToken

Console.WriteLine($"Marking score {score.id} non-preserved...");

await db.ExecuteAsync("UPDATE scores SET preserve = 0 WHERE id = @scoreId;", new
await db.ExecuteAsync("UPDATE scores SET preserve = 0, unix_updated_at = CURRENT_TIMESTAMP WHERE id = @scoreId;", new
{
scoreId = score.id
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.Scoring.Legacy;
Expand Down Expand Up @@ -636,6 +635,8 @@ private async Task<ScoreInfo> createReferenceScore(Ruleset ruleset, HighScore hi
IsLegacyScore = true
};

var scoreProcessor = ruleset.CreateScoreProcessor();

// Populate statistics and accuracy.
scoreInfo.SetCount50(highScore.count50);
scoreInfo.SetCount100(highScore.count100);
Expand All @@ -649,7 +650,7 @@ private async Task<ScoreInfo> createReferenceScore(Ruleset ruleset, HighScore hi
scoreInfo.Statistics = scoreInfo.Statistics.Where(kvp => kvp.Value != 0).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

// Populate the maximum statistics.
HitResult maxBasicResult = ruleset.GetHitResults().Select(h => h.result).Where(h => h.IsBasic()).MaxBy(Judgement.ToNumericResult);
HitResult maxBasicResult = ruleset.GetHitResults().Select(h => h.result).Where(h => h.IsBasic()).MaxBy(scoreProcessor.GetBaseScoreForResult);

foreach ((HitResult result, int count) in scoreInfo.Statistics)
{
Expand Down Expand Up @@ -736,12 +737,7 @@ private async Task<ScoreInfo> createReferenceScore(Ruleset ruleset, HighScore hi

LegacyBeatmapConversionDifficultyInfo difficulty = LegacyBeatmapConversionDifficultyInfo.FromAPIBeatmap(beatmap.ToAPIBeatmap());

scoreInfo.TotalScore = StandardisedScoreMigrationTools.ConvertFromLegacyTotalScore(scoreInfo, difficulty, scoreAttributes.ToAttributes());

int baseScore = scoreInfo.Statistics.Where(kvp => kvp.Key.AffectsAccuracy()).Sum(kvp => kvp.Value * Judgement.ToNumericResult(kvp.Key));
int maxBaseScore = scoreInfo.MaximumStatistics.Where(kvp => kvp.Key.AffectsAccuracy()).Sum(kvp => kvp.Value * Judgement.ToNumericResult(kvp.Key));

scoreInfo.Accuracy = maxBaseScore == 0 ? 1 : baseScore / (double)maxBaseScore;
StandardisedScoreMigrationTools.UpdateFromLegacy(scoreInfo, difficulty, scoreAttributes.ToAttributes());

return scoreInfo;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ public string data
[JsonIgnore]
public DateTimeOffset created_at { get; set; }

[JsonIgnore]
public DateTimeOffset updated_at { get; set; }

public override string ToString() => $"score_id: {id} user_id: {user_id}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
<PackageReference Include="Dapper" Version="2.1.24" />
<PackageReference Include="Dapper.Contrib" Version="2.0.78" />
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="4.1.0" />
<PackageReference Include="ppy.osu.Game" Version="2023.1221.0" />
<PackageReference Include="ppy.osu.Game.Rulesets.Catch" Version="2023.1221.0" />
<PackageReference Include="ppy.osu.Game.Rulesets.Mania" Version="2023.1221.0" />
<PackageReference Include="ppy.osu.Game.Rulesets.Osu" Version="2023.1221.0" />
<PackageReference Include="ppy.osu.Game.Rulesets.Taiko" Version="2023.1221.0" />
<PackageReference Include="ppy.osu.Game" Version="2023.1222.0" />
<PackageReference Include="ppy.osu.Game.Rulesets.Catch" Version="2023.1222.0" />
<PackageReference Include="ppy.osu.Game.Rulesets.Mania" Version="2023.1222.0" />
<PackageReference Include="ppy.osu.Game.Rulesets.Osu" Version="2023.1222.0" />
<PackageReference Include="ppy.osu.Game.Rulesets.Taiko" Version="2023.1222.0" />
<PackageReference Include="ppy.osu.Server.OsuQueueProcessor" Version="2023.1207.0" />
</ItemGroup>

Expand Down

0 comments on commit e8ff6b1

Please sign in to comment.