-
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migration to .NET 5 & diffcalc update (#234)
- Loading branch information
Showing
128 changed files
with
1,822 additions
and
4,199 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using osu.Game.Rulesets; | ||
using osu.Game.Rulesets.Catch; | ||
using osu.Game.Rulesets.Catch.Objects; | ||
using osu.Game.Rulesets.Objects; | ||
using osu.Game.Rulesets.Scoring; | ||
using osu.Game.Rulesets.Taiko; | ||
using osu.Game.Rulesets.Taiko.Objects; | ||
|
||
namespace PpCalculator | ||
{ | ||
public class CtbCalculator : PpCalculator | ||
{ | ||
public override Ruleset Ruleset { get; } = new CatchRuleset(); | ||
|
||
protected override int GetMaxCombo(IReadOnlyList<HitObject> hitObjects) => | ||
hitObjects.Count(h => h is Fruit) | ||
+ hitObjects.OfType<JuiceStream>().SelectMany(j => j.NestedHitObjects).Count(h => !(h is TinyDroplet)); | ||
|
||
protected override Dictionary<HitResult, int> GenerateHitResults(double accuracy, IReadOnlyList<HitObject> hitObjects, int countMiss, int? countMeh, int? countGood, int? countKatsu = null) | ||
{ | ||
var maxCombo = GetMaxCombo(hitObjects); | ||
int maxTinyDroplets = hitObjects.OfType<JuiceStream>().Sum(s => s.NestedHitObjects.OfType<TinyDroplet>().Count()); | ||
int maxDroplets = hitObjects.OfType<JuiceStream>().Sum(s => s.NestedHitObjects.OfType<Droplet>().Count()) - maxTinyDroplets; | ||
int maxFruits = hitObjects.OfType<Fruit>().Count() + 2 * hitObjects.OfType<JuiceStream>().Count() + hitObjects.OfType<JuiceStream>().Sum(s => s.RepeatCount); | ||
|
||
// Either given or max value minus misses | ||
int countDroplets = countGood ?? Math.Max(0, maxDroplets - countMiss); | ||
|
||
// Max value minus whatever misses are left. Negative if impossible missCount | ||
int countFruits = maxFruits - (countMiss - (maxDroplets - countDroplets)); | ||
|
||
// Either given or the max amount of hit objects with respect to accuracy minus the already calculated fruits and drops. | ||
// Negative if accuracy not feasable with missCount. | ||
int countTinyDroplets = countMeh ?? (int)Math.Round(accuracy * (maxCombo + maxTinyDroplets)) - countFruits - countDroplets; | ||
|
||
// Whatever droplets are left | ||
int countTinyMisses = countKatsu ?? maxTinyDroplets - countTinyDroplets; | ||
|
||
return new Dictionary<HitResult, int> | ||
{ | ||
{ HitResult.Great, countFruits }, | ||
{ HitResult.LargeTickHit, countDroplets }, | ||
{ HitResult.SmallTickHit, countTinyDroplets }, | ||
{ HitResult.SmallTickMiss, countTinyMisses }, | ||
{ HitResult.Miss, countMiss } | ||
}; | ||
} | ||
|
||
protected override double GetAccuracy(Dictionary<HitResult, int> statistics) | ||
{ | ||
double hits = statistics[HitResult.Great] + statistics[HitResult.LargeTickHit] + statistics[HitResult.SmallTickHit]; | ||
double total = hits + statistics[HitResult.Miss] + statistics[HitResult.SmallTickMiss]; | ||
|
||
return hits / total; | ||
} | ||
} | ||
} |
This file contains 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 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 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 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 |
---|---|---|
@@ -1,20 +1,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<RestoreProjectStyle>PackageReference</RestoreProjectStyle> | ||
<Platforms>AnyCPU;x64</Platforms> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\submodules\osu\osu.Game.Rulesets.Catch\osu.Game.Rulesets.Catch.csproj" /> | ||
<ProjectReference Include="..\submodules\osu\osu.Game.Rulesets.Mania\osu.Game.Rulesets.Mania.csproj" /> | ||
<ProjectReference Include="..\submodules\osu\osu.Game.Rulesets.Osu\osu.Game.Rulesets.Osu.csproj" /> | ||
<ProjectReference Include="..\submodules\osu\osu.Game.Rulesets.Taiko\osu.Game.Rulesets.Taiko.csproj" /> | ||
<ProjectReference Include="..\submodules\osu\osu.Game\osu.Game.csproj"> | ||
<EmbedInteropTypes>false</EmbedInteropTypes> | ||
<Private>true</Private> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<PropertyGroup> | ||
<TargetFramework>netstandard2.1</TargetFramework> | ||
<OutputType>Library</OutputType> | ||
<Platforms>AnyCPU;x86</Platforms> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\submodules\osu\osu.Game\osu.Game.csproj" /> | ||
<ProjectReference Include="..\submodules\osu\osu.Game.Rulesets.Catch\osu.Game.Rulesets.Catch.csproj" /> | ||
<ProjectReference Include="..\submodules\osu\osu.Game.Rulesets.Mania\osu.Game.Rulesets.Mania.csproj" /> | ||
<ProjectReference Include="..\submodules\osu\osu.Game.Rulesets.Osu\osu.Game.Rulesets.Osu.csproj" /> | ||
<ProjectReference Include="..\submodules\osu\osu.Game.Rulesets.Taiko\osu.Game.Rulesets.Taiko.csproj" /> | ||
</ItemGroup> | ||
</Project> |
This file contains 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 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 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 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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using CollectionManager.DataTypes; | ||
using NUnit.Framework; | ||
using osu.Framework.IO.Network; | ||
using Beatmap = StreamCompanionTypes.DataTypes.Beatmap; | ||
|
||
|
||
namespace PpCalculator.Tests | ||
{ | ||
[TestFixture()] | ||
public class PpCalculatorTests | ||
{ | ||
private const string base_url = "https://osu.ppy.sh"; | ||
|
||
[Test] | ||
[TestCase(5, 0, 0, 595, "HD,DT", 628.534, 1185330)] | ||
[TestCase(9, 0, 0, 858, "HD,DT", 698.977, 2333273)] | ||
public void CalculateOsuTest(int c100, int c50, int cMiss, int combo, string mods, double expectedPp, int mapId) | ||
=> CalculateTest(c100, c50, cMiss, combo, mods, expectedPp, mapId, new OsuCalculator()); | ||
|
||
[Test] | ||
[TestCase(76, 0, 2, 1679, "HD,DT", 594.078, 1251239)] | ||
[TestCase(36, 0, 0, 2110, "HD,DT", 521.732, 2495119)] | ||
public void CalculateTaikoTest(int c100, int c50, int cMiss, int combo, string mods, double expectedPp, int mapId) | ||
=> CalculateTest(c100, c50, cMiss, combo, mods, expectedPp, mapId, new TaikoCalculator()); | ||
|
||
[Test] | ||
[TestCase(73, 79, 0, 1241, "HR", 822.357, 1972148)] | ||
[TestCase(25, 216, 0, 567, "HD,HR", 378.109, 2424031)] | ||
public void CalculateCtbTest(int c100, int c50, int cMiss, int combo, string mods, double expectedPp, int mapId) | ||
=> CalculateTest(c100, c50, cMiss, combo, mods, expectedPp, mapId, new CtbCalculator()); | ||
|
||
[Ignore("Star rating is diferent in osu and on site itself, resulting in slightly changed pp values(calculator SR has same values as one in osu! itself)")] | ||
[Test] | ||
[TestCase(1, 0, 0, 2782, "", 641.782, 1270895, 993209)] | ||
[TestCase(6, 2, 4, 1830, "", 768.33, 2513195, 948258)] | ||
public void CalculateManiaTest(int c100, int c50, int cMiss, int combo, string mods, double expectedPp, int mapId, int score) | ||
=> CalculateTest(c100, c50, cMiss, combo, mods, expectedPp, mapId, new ManiaCalculator(), score); | ||
|
||
public void CalculateTest(int c100, int c50, int cMiss, int combo, string mods, double expectedPp, int mapId, PpCalculator ppCalculator, int score = 0) | ||
{ | ||
ppCalculator.PreProcess(GetMapPath(mapId)); | ||
ppCalculator.Goods = c100; | ||
ppCalculator.Mehs = c50; | ||
ppCalculator.Misses = cMiss; | ||
ppCalculator.Combo = combo; | ||
ppCalculator.Score = score; | ||
ppCalculator.Mods = mods.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries); | ||
|
||
var calculatedPp = ppCalculator.Calculate(); | ||
|
||
Assert.That(calculatedPp, Is.EqualTo(expectedPp).Within(0.01)); | ||
} | ||
|
||
private string GetMapPath(int mapId) | ||
{ | ||
if (!Directory.Exists("cache")) | ||
Directory.CreateDirectory("cache"); | ||
|
||
string cachePath = Path.Combine("cache", $"{mapId}.osu"); | ||
if (!File.Exists(cachePath)) | ||
{ | ||
new FileWebRequest(cachePath, $"{base_url}/osu/{mapId}").Perform(); | ||
} | ||
|
||
return cachePath; | ||
} | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net5.0-windows</TargetFramework> | ||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" /> | ||
<PackageReference Include="NUnit"> | ||
<Version>3.12.0</Version> | ||
</PackageReference> | ||
<PackageReference Include="NUnit3TestAdapter"> | ||
<Version>3.15.1</Version> | ||
</PackageReference> | ||
<PackageReference Include="StreamCompanionTypes"> | ||
<Version>5.2.1</Version> | ||
</PackageReference> | ||
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" /> | ||
<PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\PpCalculator\PpCalculator.csproj" /> | ||
</ItemGroup> | ||
<Choose> | ||
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'"> | ||
<ItemGroup> | ||
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> | ||
<Private>False</Private> | ||
</Reference> | ||
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> | ||
<Private>False</Private> | ||
</Reference> | ||
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> | ||
<Private>False</Private> | ||
</Reference> | ||
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> | ||
<Private>False</Private> | ||
</Reference> | ||
</ItemGroup> | ||
</When> | ||
</Choose> | ||
</Project> |
Oops, something went wrong.