Skip to content

Commit

Permalink
Fix: Mania pp calc
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotrekol committed Oct 21, 2022
1 parent 5f1e7ee commit 8d55b74
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 23 deletions.
4 changes: 2 additions & 2 deletions PpCalculator/CtbCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ 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)
protected override Dictionary<HitResult, int> GenerateHitResults(double accuracy, IReadOnlyList<HitObject> hitObjects, int countMiss, int? countMeh, int? countGood, int? countKatu = null, int? hit300 = null)
{
var maxCombo = GetMaxCombo(hitObjects);
int maxTinyDroplets = hitObjects.OfType<JuiceStream>().Sum(s => s.NestedHitObjects.OfType<TinyDroplet>().Count());
Expand All @@ -37,7 +37,7 @@ protected override Dictionary<HitResult, int> GenerateHitResults(double accuracy
int countTinyDroplets = countMeh ?? (int)Math.Round(accuracy * (maxCombo + maxTinyDroplets)) - countFruits - countDroplets;

// Whatever droplets are left
int countTinyMisses = countKatsu ?? maxTinyDroplets - countTinyDroplets;
int countTinyMisses = countKatu ?? maxTinyDroplets - countTinyDroplets;

return new Dictionary<HitResult, int>
{
Expand Down
27 changes: 18 additions & 9 deletions PpCalculator/ManiaCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,28 @@ public class ManiaCalculator : PpCalculator

protected override int GetMaxCombo(IReadOnlyList<HitObject> hitObjects) => 0;

protected override Dictionary<HitResult, int> GenerateHitResults(double accuracy, IReadOnlyList<HitObject> hitObjects, int countMiss, int? countMeh, int? countGood, int? countKatsu = null)
protected override Dictionary<HitResult, int> GenerateHitResults(double accuracy, IReadOnlyList<HitObject> hitObjects, int countMiss, int? countMeh, int? countGood, int? countKatu = null, int? hit300 = null)
{
var totalHits = hitObjects.Count;
if (!(countMeh.HasValue && countGood.HasValue && countKatu.HasValue && hit300.HasValue))
return new Dictionary<HitResult, int>
{
{ HitResult.Perfect, hitObjects.Count },
{ HitResult.Great, 0 },
{ HitResult.Ok, 0 },
{ HitResult.Good, 0 },
{ HitResult.Meh, 0 },
{ HitResult.Miss, 0 }
};

// Only total number of hits is considered currently, so specifics don't matter
var otherCounts = countMiss + countMeh.Value + countGood.Value + countKatu.Value + hit300.Value;
return new Dictionary<HitResult, int>
{
{ HitResult.Perfect, totalHits },
{ HitResult.Great, 0 },
{ HitResult.Ok, 0 },
{ HitResult.Good, 0 },
{ HitResult.Meh, 0 },
{ HitResult.Miss, 0 }
{ HitResult.Perfect, hitObjects.Count - otherCounts },
{ HitResult.Great, hit300.Value },
{ HitResult.Ok, countGood.Value },
{ HitResult.Good, countKatu.Value },
{ HitResult.Meh, countMeh.Value },
{ HitResult.Miss, countMiss }
};
}

Expand Down
2 changes: 1 addition & 1 deletion PpCalculator/OsuCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected override int GetMaxCombo(IReadOnlyList<HitObject> hitObjects) =>



protected override Dictionary<HitResult, int> GenerateHitResults(double accuracy, IReadOnlyList<HitObject> hitObjects, int countMiss, int? countMeh, int? countGood, int? countKatsu = null)
protected override Dictionary<HitResult, int> GenerateHitResults(double accuracy, IReadOnlyList<HitObject> hitObjects, int countMiss, int? countMeh, int? countGood, int? countKatu = null, int? hit300 = null)
{
int countGreat;

Expand Down
8 changes: 5 additions & 3 deletions PpCalculator/PpCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public virtual string[] Mods
public virtual int Misses { get; set; }
public virtual int? Mehs { get; set; }
public virtual int? Goods { get; set; }
public int? Katsus { get; set; }
public int? Katus { get; set; }
public int? Hit300 { get; set; }

protected virtual ScoreInfo ScoreInfo { get; set; } = new ScoreInfo();
protected PerformanceCalculator PerformanceCalculator { get; set; }
Expand Down Expand Up @@ -169,9 +170,10 @@ private PpCalculatorTypes.PerformanceAttributes InternalCalculate(CancellationTo
if (!hitObjects.Any())
return null;

ScoreInfo.Statistics = GenerateHitResults(Accuracy / 100, hitObjects, Misses, Mehs, Goods, Katsus);
ScoreInfo.Statistics = GenerateHitResults(Accuracy / 100, hitObjects, Misses, Mehs, Goods, Katus, Hit300);
ScoreInfo.Accuracy = GetAccuracy(ScoreInfo.Statistics);
ScoreInfo.MaxCombo = Combo ?? (int)Math.Round(PercentCombo / 100 * GetMaxCombo(hitObjects));
//TODO: bug - score will get applied twice on top when provided score is read from memory
ScoreInfo.TotalScore = (int)Math.Round(Score * ScoreMultiplier);

if (createPerformanceCalculator)
Expand Down Expand Up @@ -267,7 +269,7 @@ protected int GetComboToTime(IBeatmap beatmap, int toTime) =>

protected abstract int GetMaxCombo(IReadOnlyList<HitObject> hitObjects);

protected abstract Dictionary<HitResult, int> GenerateHitResults(double accuracy, IReadOnlyList<HitObject> hitObjects, int countMiss, int? countMeh, int? countGood, int? countKatsu = null);
protected abstract Dictionary<HitResult, int> GenerateHitResults(double accuracy, IReadOnlyList<HitObject> hitObjects, int countMiss, int? countMeh, int? countGood, int? countKatu = null, int? hit300 = null);

protected abstract double GetAccuracy(Dictionary<HitResult, int> statistics);

Expand Down
2 changes: 1 addition & 1 deletion PpCalculator/TaikoCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class TaikoCalculator : PpCalculator
protected override int GetMaxCombo(IReadOnlyList<HitObject> hitObjects) =>
hitObjects.OfType<Hit>().Count();

protected override Dictionary<HitResult, int> GenerateHitResults(double accuracy, IReadOnlyList<HitObject> hitObjects, int countMiss, int? countMeh, int? countGood, int? countKatsu = null)
protected override Dictionary<HitResult, int> GenerateHitResults(double accuracy, IReadOnlyList<HitObject> hitObjects, int countMiss, int? countMeh, int? countGood, int? countKatu = null, int? hit300 = null)
{
var totalResultCount = GetMaxCombo(hitObjects);

Expand Down
13 changes: 8 additions & 5 deletions PpCalculatorTests/PpCalculatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,17 @@ public void CalculateCtbTest(int c100, int c50, int cMiss, int combo, string mod
=> CalculateTest(c100, c50, cMiss, combo, mods, expectedPp, mapId, new CtbCalculator());

[Test]
[TestCase(1, 0, 0, 2782, "", 671.780, 1270895, 993209)]
[TestCase(6, 2, 4, 1830, "", 941.637, 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);
//mania score consists of: Geki(c300P, auto calculated),c300,Katu(c200),c100,c50,cMiss
[TestCase(673, 20, 0, 0, 0, 3835, "", 901.925, 3563179, 990307)]
[TestCase(1486, 131, 13, 11, 28, 1256, "", 795.277, 3449261, 913494)]
public void CalculateManiaTest(int c300, int cKatu, 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, c300, cKatu);

public void CalculateTest(int c100, int c50, int cMiss, int combo, string mods, double expectedPp, int mapId, PpCalculator ppCalculator, int score = 0)
public void CalculateTest(int c100, int c50, int cMiss, int combo, string mods, double expectedPp, int mapId, PpCalculator ppCalculator, int score = 0, int c300 = 0, int cKatu = 0)
{
ppCalculator.PreProcess(GetMapPath(mapId));
ppCalculator.Hit300 = c300;
ppCalculator.Katus = cKatu;
ppCalculator.Goods = c100;
ppCalculator.Mehs = c50;
ppCalculator.Misses = cMiss;
Expand Down
3 changes: 2 additions & 1 deletion PpCalculatorTypes/IPpCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public interface IPpCalculator
int Misses { get; set; }
int? Mehs { get; set; }
int? Goods { get; set; }
int? Katsus { get; set; }
int? Katus { get; set; }
int? Hit300 { get; set; }
int RulesetId { get; }
double BeatmapLength { get; }
void PreProcess(string file);
Expand Down
3 changes: 2 additions & 1 deletion plugins/OsuMemoryEventSource/LivePerformanceCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ private void PreparePpCalculator(IPpCalculator ppCalculator, RulesetPlayData pla
ppCalculator.Goods = play.Hit100;
ppCalculator.Mehs = play.Hit50;
ppCalculator.Misses = play.HitMiss;
ppCalculator.Katsus = Play.HitKatu;
ppCalculator.Katus = Play.HitKatu;
ppCalculator.Hit300 = Play.Hit300;
ppCalculator.Combo = play.MaxCombo;
ppCalculator.Score = play.Score;
}
Expand Down

0 comments on commit 8d55b74

Please sign in to comment.