Created
August 7, 2019 09:39
-
-
Save peppy/3a11cb58c856b6af7c1916422f668899 to your computer and use it in GitHub Desktop.
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
List<double> result = GetErrorStatisticsArray(score.HitErrors); | |
hint = String.Format("Accuracy:\nError: {0:0.00}ms - {1:0.00}ms avg\nUnstable Rate: {2:0.00}\n", result[0], result[1], result[4] * 10, result[6], result[5]); | |
// input is a list of (user_hit_time - correct_time) | |
internal List<double> GetErrorStatisticsArray(List<int> list) | |
{ | |
if (list == null || list.Count == 0) | |
return null; | |
List<double> result = new List<double>(4); | |
double total = 0, _total = 0, totalAll = 0; | |
int count = 0, _count = 0; | |
int max = 0, min = int.MaxValue; | |
for (int i = 0; i < list.Count; i++) | |
{ | |
if (list[i] > max) | |
max = list[i]; | |
if (list[i] < min) | |
min = list[i]; | |
totalAll += list[i]; | |
if (list[i] >= 0) | |
{ | |
total += list[i]; | |
count++; | |
} | |
else | |
{ | |
_total += list[i]; | |
_count++; | |
} | |
} | |
double avarage = totalAll / list.Count; | |
double variance = 0; | |
for (int i = 0; i < list.Count; i++) | |
{ | |
variance += Math.Pow(list[i] - avarage, 2); | |
} | |
variance = variance / list.Count; | |
result.Add(_count == 0 ? 0 : _total / _count); //0 | |
result.Add(count == 0 ? 0 : total / count); //1 | |
result.Add(avarage); //2 | |
result.Add(variance); //3 | |
result.Add(Math.Sqrt(variance)); //4 | |
result.Add(max); //5 | |
result.Add(min); //6 | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment