private void TypingSpeed_MistakesCount() { mistakesList.Clear(); for (int i = 0; i < 10000; i += 50) { string query = string.Format("SELECT COUNT(id) FROM MistakesView WHERE typing_speed between {0} and {1} {2}", i + 1, i + 50, whereAnd); int mistakes_count = DBUtils.ExecuteScalar(query); //double speed = (double)(i + 50) / (double)1000; if (mistakes_count != 0) { double speed = (double)1000 / (double)(i + 50); TypingSpeed_MistakesCount typS = new TypingSpeed_MistakesCount(Math.Round(speed, 2), mistakes_count); mistakesList.Add(typS); } } PercentageCalc(); isLoadedMistakes = true; }
private void PercentageCalc() { int totalCount = 0; foreach (var item in mistakesList) { totalCount += item.mistakesCount; } List <TypingSpeed_MistakesCount> tempList = new List <TypingSpeed_MistakesCount>(); foreach (var item in mistakesList) { double percentage = (item.mistakesCount / (double)totalCount) * 100; if (percentage >= 0.5) { TypingSpeed_MistakesCount newItem = new TypingSpeed_MistakesCount(Math.Round(item.speed, 1), item.mistakesCount, Math.Round(percentage, 1)); tempList.Add(newItem); } } mistakesList = tempList; }