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

Bump difficalcy from 3f3b541 to 4343fda #30

Merged
merged 3 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
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
16 changes: 11 additions & 5 deletions Difficalcy.PerformancePlus.Tests/OsuCalculatorServiceTest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Difficalcy.Models;
using Difficalcy.PerformancePlus.Models;
using Difficalcy.PerformancePlus.Services;
using Difficalcy.Services;
Expand All @@ -20,18 +21,23 @@ public OsuCalculatorServiceTest()
protected override CalculatorService<OsuScore, OsuDifficulty, OsuPerformance, OsuCalculation> CalculatorService { get; }

[Theory]
[InlineData(6.578701261037768d, 288.6125590551904d, "diffcalc-test", 0)]
[InlineData(8.8180306947868328d, 722.9095478161727d, "diffcalc-test", 64)]
public void Test(double expectedDifficultyTotal, double expectedPerformanceTotal, string beatmapId, int mods)
=> TestGetCalculationReturnsCorrectValues(expectedDifficultyTotal, expectedPerformanceTotal, new OsuScore { BeatmapId = beatmapId, Mods = mods });
[InlineData(6.578701261037768d, 288.6125590551904d, "diffcalc-test", new string[] { })]
[InlineData(8.8180306947868328d, 722.9095478161727d, "diffcalc-test", new string[] { "DT" })]
public void Test(double expectedDifficultyTotal, double expectedPerformanceTotal, string beatmapId, string[] mods)
=> TestGetCalculationReturnsCorrectValues(expectedDifficultyTotal, expectedPerformanceTotal, new OsuScore { BeatmapId = beatmapId, Mods = mods.Select(m => new Mod { Acronym = m }).ToArray() });

[Fact]
public void TestAllParameters()
{
var score = new OsuScore
{
BeatmapId = "diffcalc-test",
Mods = 1112, // HD, HR, DT, FL
Mods = [
new Mod() { Acronym = "HD" },
new Mod() { Acronym = "HR" },
new Mod() { Acronym = "DT" },
new Mod() { Acronym = "FL" },
],
Combo = 200,
Misses = 5,
Mehs = 4,
Expand Down
19 changes: 15 additions & 4 deletions Difficalcy.PerformancePlus/Services/OsuCalculatorService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
using Difficalcy.Services;
using Microsoft.Extensions.Configuration;
using osu.Game.Beatmaps.Legacy;
using osu.Game.Online.API;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Difficulty;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring;
using LazerMod = osu.Game.Rulesets.Mods.Mod;

namespace Difficalcy.PerformancePlus.Services
{
Expand Down Expand Up @@ -52,13 +54,13 @@ protected override async Task EnsureBeatmap(string beatmapId)
await beatmapProvider.EnsureBeatmap(beatmapId);
}

protected override (object, string) CalculateDifficultyAttributes(string beatmapId, int bitMods)
protected override (object, string) CalculateDifficultyAttributes(string beatmapId, Mod[] mods)
{
var workingBeatmap = GetWorkingBeatmap(beatmapId);
var mods = OsuRuleset.ConvertFromLegacyMods((LegacyMods)bitMods).ToArray();
var lazerMods = mods.Select(ModToLazerMod).ToArray();

var difficultyCalculator = OsuRuleset.CreateDifficultyCalculator(workingBeatmap);
var difficultyAttributes = difficultyCalculator.Calculate(mods) as OsuDifficultyAttributes;
var difficultyAttributes = difficultyCalculator.Calculate(lazerMods) as OsuDifficultyAttributes;

// Serialising anonymous object with same names because Mods and Skills can't be serialised
return (difficultyAttributes, JsonSerializer.Serialize(new
Expand Down Expand Up @@ -89,7 +91,7 @@ protected override OsuCalculation CalculatePerformance(OsuScore score, object di
var osuDifficultyAttributes = (OsuDifficultyAttributes)difficultyAttributes;

var workingBeatmap = GetWorkingBeatmap(score.BeatmapId);
var mods = OsuRuleset.ConvertFromLegacyMods((LegacyMods)score.Mods).ToArray();
var mods = score.Mods.Select(ModToLazerMod).ToArray();
var beatmap = workingBeatmap.GetPlayableBeatmap(OsuRuleset.RulesetInfo, mods);

var combo = score.Combo ?? beatmap.HitObjects.Count + beatmap.HitObjects.OfType<Slider>().Sum(s => s.NestedHitObjects.Count - 1);
Expand Down Expand Up @@ -122,6 +124,15 @@ private CalculatorWorkingBeatmap GetWorkingBeatmap(string beatmapId)
return new CalculatorWorkingBeatmap(OsuRuleset, beatmapStream);
}

private LazerMod ModToLazerMod(Mod mod)
{
var apiMod = new APIMod { Acronym = mod.Acronym };
foreach (var setting in mod.Settings)
apiMod.Settings.Add(setting.Key, setting.Value);

return apiMod.ToMod(OsuRuleset);
}

private static Dictionary<HitResult, int> GetHitResults(int hitResultCount, int countMiss, int countMeh, int countOk)
{
var countGreat = hitResultCount - countOk - countMeh - countMiss;
Expand Down
2 changes: 1 addition & 1 deletion difficalcy
Submodule difficalcy updated 58 files
+6 −0 .config/dotnet-tools.json
+4 −4 .github/dependabot.yml
+6 −0 .github/workflows/test-on-push.yml
+40 −8 Difficalcy.Catch.Tests/CatchCalculatorServiceTest.cs
+1 −1 Difficalcy.Catch.Tests/Usings.cs
+9 −4 Difficalcy.Catch/Controllers/CatchCalculatorController.cs
+2 −2 Difficalcy.Catch/Difficalcy.Catch.csproj
+1 −3 Difficalcy.Catch/Models/CatchDifficulty.cs
+1 −3 Difficalcy.Catch/Models/CatchPerformance.cs
+4 −1 Difficalcy.Catch/Models/CatchScore.cs
+12 −3 Difficalcy.Catch/Services/CalculatorWorkingBeatmap.cs
+89 −34 Difficalcy.Catch/Services/CatchCalculatorService.cs
+2 −1 Difficalcy.Catch/Startup.cs
+39 −8 Difficalcy.Mania.Tests/ManiaCalculatorServiceTest.cs
+1 −1 Difficalcy.Mania.Tests/Usings.cs
+8 −3 Difficalcy.Mania/Controllers/ManiaCalculatorController.cs
+2 −2 Difficalcy.Mania/Difficalcy.Mania.csproj
+1 −3 Difficalcy.Mania/Models/ManiaDifficulty.cs
+12 −3 Difficalcy.Mania/Services/CalculatorWorkingBeatmap.cs
+80 −28 Difficalcy.Mania/Services/ManiaCalculatorService.cs
+2 −1 Difficalcy.Mania/Startup.cs
+53 −8 Difficalcy.Osu.Tests/OsuCalculatorServiceTest.cs
+1 −1 Difficalcy.Osu.Tests/Usings.cs
+8 −3 Difficalcy.Osu/Controllers/OsuCalculatorController.cs
+1 −1 Difficalcy.Osu/Difficalcy.Osu.csproj
+4 −1 Difficalcy.Osu/Models/OsuScore.cs
+8 −2 Difficalcy.Osu/Services/CalculatorWorkingBeatmap.cs
+84 −38 Difficalcy.Osu/Services/OsuCalculatorService.cs
+2 −1 Difficalcy.Osu/Startup.cs
+41 −9 Difficalcy.Taiko.Tests/TaikoCalculatorServiceTest.cs
+1 −1 Difficalcy.Taiko.Tests/Usings.cs
+8 −3 Difficalcy.Taiko/Controllers/TaikoCalculatorController.cs
+2 −2 Difficalcy.Taiko/Difficalcy.Taiko.csproj
+4 −1 Difficalcy.Taiko/Models/TaikoScore.cs
+12 −3 Difficalcy.Taiko/Services/CalculatorWorkingBeatmap.cs
+67 −28 Difficalcy.Taiko/Services/TaikoCalculatorService.cs
+2 −1 Difficalcy.Taiko/Startup.cs
+15 −6 Difficalcy.Tests/CalculatorServiceTest.cs
+128 −39 Difficalcy.Tests/DummyCalculatorServiceTest.cs
+1 −1 Difficalcy.Tests/Usings.cs
+16 −3 Difficalcy/Controllers/CalculatorController.cs
+14 −4 Difficalcy/DifficalcyStartup.cs
+26 −2 Difficalcy/Models/Score.cs
+2 −3 Difficalcy/Services/BeatmapNotFoundException.cs
+56 −16 Difficalcy/Services/CalculatorService.cs
+2 −1 Difficalcy/Services/InMemoryCache.cs
+3 −1 Difficalcy/Services/TestBeatmapProvider.cs
+33 −7 Difficalcy/Services/WebBeatmapProvider.cs
+6 −0 Makefile
+10 −8 README.md
+30 −8 docs/docs/api-reference/difficalcy-catch.json
+30 −8 docs/docs/api-reference/difficalcy-mania.json
+30 −8 docs/docs/api-reference/difficalcy-osu.json
+30 −8 docs/docs/api-reference/difficalcy-taiko.json
+161 −40 docs/docs/getting-started.md
+6 −6 docs/docs/index.md
+4 −4 docs/poetry.lock
+1 −1 docs/pyproject.toml
38 changes: 30 additions & 8 deletions docs/docs/difficalcy-performanceplus.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@
"name": "Mods",
"in": "query",
"schema": {
"maximum": 2147483647,
"minimum": 0,
"type": "integer",
"format": "int32"
"type": "array",
"items": {
"$ref": "#/components/schemas/Mod"
}
}
}
],
Expand Down Expand Up @@ -166,6 +166,27 @@
},
"additionalProperties": false
},
"Mod": {
"required": [
"acronym"
],
"type": "object",
"properties": {
"acronym": {
"minLength": 1,
"type": "string"
},
"settings": {
"type": "object",
"additionalProperties": {
"type": "string",
"nullable": true
},
"nullable": true
}
},
"additionalProperties": false
},
"OsuCalculation": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -273,10 +294,11 @@
"type": "string"
},
"mods": {
"maximum": 2147483647,
"minimum": 0,
"type": "integer",
"format": "int32"
"type": "array",
"items": {
"$ref": "#/components/schemas/Mod"
},
"nullable": true
},
"combo": {
"maximum": 2147483647,
Expand Down