Skip to content

Commit

Permalink
Add accuracy column
Browse files Browse the repository at this point in the history
  • Loading branch information
kashparty committed Jul 29, 2021
1 parent c674c6f commit 2430bab
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ private static bool RunRound(QLearn qLearn) {
bool doneTyping = false;
bool escaped = false;
int currentPos = 0;
int mistakes = 0;
bool currentMistake = false;

Stopwatch stopwatch = new Stopwatch();
List<long> keyTimes = new List<long>();
Expand All @@ -53,8 +55,15 @@ private static bool RunRound(QLearn qLearn) {
keyTimes.Add(stopwatch.ElapsedMilliseconds);
Console.Write(pressedKey.KeyChar);
currentPos++;

if (currentMistake) {
mistakes++;
currentMistake = false;
}

stopwatch.Restart();
} else {
currentMistake = true;
}

if (currentPos >= target.Length) doneTyping = true;
Expand All @@ -71,6 +80,9 @@ private static bool RunRound(QLearn qLearn) {

Console.Write($" WPM: {Math.Round(wordsPerMinute)}".PadRight(11));

double accuracy = (double)(keyTimes.Count - mistakes) * 100.0 / keyTimes.Count;
Console.Write($" Accuracy: {Math.Round(accuracy)}".PadRight(17));

qLearn.UpdateModel(target, keyTimes);
qLearn.FinishRound();
}
Expand Down

0 comments on commit 2430bab

Please sign in to comment.