From a6ec127dec578900e5a7b94a4d93dde68cc4e75c Mon Sep 17 00:00:00 2001
From: Bot
Date: Fri, 25 Dec 2020 20:39:06 +0100
Subject: [PATCH] fix calculating percent of completion
---
public/exampleResults.json | 2 +-
src/components/CodeEditor.vue | 8 +++-----
src/views/Results.vue | 19 +++++++++++--------
3 files changed, 15 insertions(+), 14 deletions(-)
diff --git a/public/exampleResults.json b/public/exampleResults.json
index 383bd7918..a7c0982e7 100644
--- a/public/exampleResults.json
+++ b/public/exampleResults.json
@@ -1914,7 +1914,7 @@
"lastThirdStartTime": 61622,
"timeFromFirstInput": 76782,
"codeLength": 216,
- "correctInputs": 216,
+ "correctLines": 12,
"mode": 0,
"file": {
"languageName": "R",
diff --git a/src/components/CodeEditor.vue b/src/components/CodeEditor.vue
index 9025623ad..d7e6309a3 100644
--- a/src/components/CodeEditor.vue
+++ b/src/components/CodeEditor.vue
@@ -279,6 +279,7 @@ export default {
if (this.currentLine + 1 === this.codeInfo.lines && this.correctCharsInLine === this.cm.getLine(this.currentLine).length) {
+ this.stats.history.push(this.currentChange);
this.completed();
} else if (this.options.underScore) {
if (this.currentChar !== lineText.length) {
@@ -471,6 +472,7 @@ export default {
}
if (this.currentChange.type !== 'initialType') {
+ this.stats.history.push(this.currentChange);
if (this.options.selectedMode === 2 && this.currentChange.type !== 'correct') {
if (this.stats.history.length < 30) {
this.cm.setOption('readOnly', 'nocursor');
@@ -479,7 +481,6 @@ export default {
this.completed();
}
}
- this.stats.history.push(this.currentChange);
} else {
console.red('Current change type equals initial type');
console.log(JSON.parse(JSON.stringify(this.currentChange)));
@@ -604,9 +605,7 @@ export default {
this.$socket.client.emit('completed');
}
- const correctInputs = this.stats.history.reduce((acc, event) => (event.type === 'correct' ? acc + 1 : acc), 0);
-
- const complete = correctInputs === this.codeText.length;
+ const complete = this.currentLine + 1 >= this.codeInfo.lines;
const endMsgList = ['Too long, uh?', 'Time is over', 'Game over'];
this.popUp(true, complete ? 'Congratulations' : endMsgList[this.options.selectedMode]);
@@ -625,7 +624,6 @@ export default {
file: this.codeInfo,
mode: this.options.selectedMode,
complete,
- correctInputs,
};
}
diff --git a/src/views/Results.vue b/src/views/Results.vue
index 6a9bcce45..65a64406d 100644
--- a/src/views/Results.vue
+++ b/src/views/Results.vue
@@ -34,7 +34,7 @@
Characters
- {{ stats.correctInputs }}
+ {{ correctInputs }}
@@ -47,8 +47,8 @@
Longest correction time: {{ format(longestTimeOfCorrection) }} s
- You made a mistake after {{ stats.correctInputs }} correct characters
- {{ stats.codeLength - stats.correctInputs }} characters left
+ You made a mistake after {{ correctInputs }} correct characters
+ {{ stats.file.lines - stats.correctLines }} lines left
{{ percentCompleted }}% completed
@@ -116,6 +116,9 @@ export default {
mistakes() {
return this.history.filter((change) => change.type === 'mistake');
},
+ correctInputs() {
+ return this.history.reduce((acc, event) => (event.type === 'correct' ? acc + 1 : acc), 0);
+ },
minutes() {
return Math.floor(this.stats.timeFromFirstInput / 1000 / 60);
},
@@ -123,13 +126,13 @@ export default {
return Math.round((this.stats.timeFromFirstInput / 1000) % 60);
},
CPM() {
- return this.stats.correctInputs / this.format(this.stats.timeFromFirstInput, 4) * 60;
+ return this.correctInputs / this.format(this.stats.timeFromFirstInput, 4) * 60;
},
WPM() {
return this.CPM / 5;
},
percentCompleted() {
- return this.format(this.stats.correctInputs / this.stats.codeLength, 1, 100);
+ return this.format(this.correctLines / this.stats.file.lines, 1, 100);
},
mostMistakesInARow() {
return this.mistakes.map((obj) => obj.fixQueuePos)
@@ -156,7 +159,7 @@ export default {
return timesAcc;
},
WPMWithoutTimeLost() {
- return this.stats.correctInputs / this.format(this.stats.timeFromFirstInput - this.totalTimeLost, 4) * 60 / 5;
+ return this.correctInputs / this.format(this.stats.timeFromFirstInput - this.totalTimeLost, 4) * 60 / 5;
},
totalTimeLost() {
return this.correctionTimes.reduce((acc, value) => acc + value, 0);
@@ -176,7 +179,7 @@ export default {
wpm: this.format(this.WPM, 0, 1),
minutes: this.minutes,
seconds: this.seconds,
- correct: this.stats.correctInputs,
+ correct: this.correctInputs,
});
// if (this.stats.file.index !== -1) {
@@ -216,7 +219,7 @@ export default {
percentCompleted: this.percentCompleted,
},
misc: {
- correctClicks: this.stats.correctInputs,
+ correctClicks: this.correctInputs,
correctLines: this.stats.correctLines,
backspaceClicks,
deletingTime: this.format(deletingTime, 0),