Пример #1
0
        public void SetText(string text)
        {
            text = text.Replace('–', '-');
            text = text.Replace('—', '-');
            text = text.Replace("\n", "");
            while (text.Contains("\r\r"))
            {
                text = text.Replace("\r\r", "\r");
            }

            StartTime          = DateTime.Now;
            Text               = text;
            CurrentSymbolIndex = 0;
            Finish             = false;
            InputKeyboardSymbolModels.Clear();
            CorrectInputKeyboardSymbolModels.Clear();
        }
Пример #2
0
        public void InputSymbol(string text, int firstLineEnd)
        {
            if (Finish)
            {
                return;
            }

            bool correctness = CurrentSymbol.Equals(text);
            var  model       = new InputSymbolModel(text, DateTime.Now, correctness);

            InputKeyboardSymbolModels.Add(model);

            int count = InputKeyboardSymbolModels.Count;

            if (count > 1)
            {
                var correctnessCount = (double)InputKeyboardSymbolModels.Count(x => x.Сorrectness);
                Сorrectness = correctnessCount / InputKeyboardSymbolModels.Count;
            }

            if (correctness)
            {
                CorrectInputKeyboardSymbolModels.Add(model);
                if (CurrentSymbolIndex == Text.Length - 1)
                {
                    FullTime            = InputKeyboardSymbolModels.Last().Time - InputKeyboardSymbolModels.First().Time;
                    CorrectSymbolsCount = CorrectInputKeyboardSymbolModels.Count;
                    FullSpeed           = CorrectSymbolsCount / FullTime.TotalMinutes;
                    Finish = true;
                    Dictionary <string, int> errorsDict = new Dictionary <string, int>();
                    int numberOfConsecutiveErrors       = 0;
                    for (int i = 0; i < InputKeyboardSymbolModels.Count; i++)
                    {
                        if (!InputKeyboardSymbolModels[i].Сorrectness)
                        {
                            numberOfConsecutiveErrors++;
                        }
                        else if (numberOfConsecutiveErrors != 0)
                        {
                            string symbol = InputKeyboardSymbolModels[i].Symbol;
                            if (!errorsDict.ContainsKey(symbol))
                            {
                                errorsDict[symbol] = numberOfConsecutiveErrors;
                            }
                            else
                            {
                                errorsDict[symbol] += numberOfConsecutiveErrors;
                            }
                            numberOfConsecutiveErrors = 0;
                        }
                    }

                    StringBuilder sb = new StringBuilder();
                    foreach (var pairs in errorsDict.OrderBy(p => - p.Value))
                    {
                        sb.AppendLine($"{pairs.Key}: {pairs.Value}");
                    }

                    BadKeysSummary = sb.ToString();
                }
                else
                {
                    CurrentSymbolIndex++;
                    if (CurrentSymbolIndex >= firstLineEnd - 3)
                    {
                        int buff = CurrentSymbolIndex;
                        CurrentSymbolIndex = 0;
                        Text = Text.Substring(buff);
                    }
                }
            }
        }