mirror of
https://github.com/ppy/osu.git
synced 2025-01-29 03:43:00 +08:00
Merge pull request #9974 from bdach/fix-fail-graph-crash
This commit is contained in:
commit
8439e28d6b
@ -7,8 +7,10 @@ using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Framework.Utils;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Overlays.BeatmapSet;
|
||||
using osu.Game.Screens.Select.Details;
|
||||
@ -72,6 +74,32 @@ namespace osu.Game.Tests.Visual.Online
|
||||
};
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestOnlyFailMetrics()
|
||||
{
|
||||
AddStep("set beatmap", () => successRate.Beatmap = new BeatmapInfo
|
||||
{
|
||||
Metrics = new BeatmapMetrics
|
||||
{
|
||||
Fails = Enumerable.Range(1, 100).ToArray(),
|
||||
}
|
||||
});
|
||||
AddAssert("graph max values correct",
|
||||
() => successRate.ChildrenOfType<BarGraph>().All(graph => graph.MaxValue == 100));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestEmptyMetrics()
|
||||
{
|
||||
AddStep("set beatmap", () => successRate.Beatmap = new BeatmapInfo
|
||||
{
|
||||
Metrics = new BeatmapMetrics()
|
||||
});
|
||||
|
||||
AddAssert("graph max values correct",
|
||||
() => successRate.ChildrenOfType<BarGraph>().All(graph => graph.MaxValue == 0));
|
||||
}
|
||||
|
||||
private class GraphExposingSuccessRate : SuccessRate
|
||||
{
|
||||
public new FailRetryGraph Graph => base.Graph;
|
||||
|
@ -236,7 +236,7 @@ namespace osu.Game.Screens.Select
|
||||
private void updateMetrics()
|
||||
{
|
||||
var hasRatings = beatmap?.BeatmapSet?.Metrics?.Ratings?.Any() ?? false;
|
||||
var hasRetriesFails = (beatmap?.Metrics?.Retries?.Any() ?? false) && (beatmap?.Metrics.Fails?.Any() ?? false);
|
||||
var hasRetriesFails = (beatmap?.Metrics?.Retries?.Any() ?? false) || (beatmap?.Metrics?.Fails?.Any() ?? false);
|
||||
|
||||
if (hasRatings)
|
||||
{
|
||||
|
@ -29,16 +29,30 @@ namespace osu.Game.Screens.Select.Details
|
||||
|
||||
var retries = Metrics?.Retries ?? Array.Empty<int>();
|
||||
var fails = Metrics?.Fails ?? Array.Empty<int>();
|
||||
var retriesAndFails = sumRetriesAndFails(retries, fails);
|
||||
|
||||
float maxValue = fails.Any() ? fails.Zip(retries, (fail, retry) => fail + retry).Max() : 0;
|
||||
float maxValue = retriesAndFails.Any() ? retriesAndFails.Max() : 0;
|
||||
failGraph.MaxValue = maxValue;
|
||||
retryGraph.MaxValue = maxValue;
|
||||
|
||||
failGraph.Values = fails.Select(f => (float)f);
|
||||
retryGraph.Values = retries.Zip(fails, (retry, fail) => retry + Math.Clamp(fail, 0, maxValue));
|
||||
failGraph.Values = fails.Select(v => (float)v);
|
||||
retryGraph.Values = retriesAndFails.Select(v => (float)v);
|
||||
}
|
||||
}
|
||||
|
||||
private int[] sumRetriesAndFails(int[] retries, int[] fails)
|
||||
{
|
||||
var result = new int[Math.Max(retries.Length, fails.Length)];
|
||||
|
||||
for (int i = 0; i < retries.Length; ++i)
|
||||
result[i] = retries[i];
|
||||
|
||||
for (int i = 0; i < fails.Length; ++i)
|
||||
result[i] += fails[i];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public FailRetryGraph()
|
||||
{
|
||||
Children = new[]
|
||||
|
Loading…
Reference in New Issue
Block a user