// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; using System.Collections.Generic; using System.Linq; using osu.Game.Rulesets.Scoring; namespace osu.Game.Screens.Ranking.Statistics { /// /// Displays the unstable rate statistic for a given play. /// public class UnstableRate : SimpleStatisticItem { /// /// Creates and computes an statistic. /// /// Sequence of s to calculate the unstable rate based on. public UnstableRate(IEnumerable hitEvents) : base("Unstable Rate") { var timeOffsets = hitEvents.Select(ev => ev.TimeOffset).ToArray(); Value = 10 * standardDeviation(timeOffsets); } private static double standardDeviation(double[] timeOffsets) { if (timeOffsets.Length == 0) return double.NaN; var mean = timeOffsets.Average(); var squares = timeOffsets.Select(offset => Math.Pow(offset - mean, 2)).Sum(); return Math.Sqrt(squares / timeOffsets.Length); } protected override string DisplayValue(double value) => double.IsNaN(value) ? "(not available)" : value.ToString("N2"); } }