Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion public/exampleResults.json
Original file line number Diff line number Diff line change
Expand Up @@ -1914,7 +1914,7 @@
"lastThirdStartTime": 61622,
"timeFromFirstInput": 76782,
"codeLength": 216,
"correctInputs": 216,
"correctLines": 12,
"mode": 0,
"file": {
"languageName": "R",
Expand Down
8 changes: 3 additions & 5 deletions src/components/CodeEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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');
Expand All @@ -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)));
Expand Down Expand Up @@ -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]);
Expand All @@ -625,7 +624,6 @@ export default {
file: this.codeInfo,
mode: this.options.selectedMode,
complete,
correctInputs,
};
}

Expand Down
19 changes: 11 additions & 8 deletions src/views/Results.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
Characters
</p>
<h2 class="value">
{{ stats.correctInputs }}
{{ correctInputs }}
</h2>
</div>
</div>
Expand All @@ -47,8 +47,8 @@
<p>Longest correction time: {{ format(longestTimeOfCorrection) }} s</p>
</template>
<template v-else>
<p>You made a mistake after {{ stats.correctInputs }} correct characters</p>
<p>{{ stats.codeLength - stats.correctInputs }} characters left</p>
<p>You made a mistake after {{ correctInputs }} correct characters</p>
<p>{{ stats.file.lines - stats.correctLines }} lines left</p>
<p>{{ percentCompleted }}% completed</p>
</template>
</div>
Expand Down Expand Up @@ -116,20 +116,23 @@ 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);
},
seconds() {
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)
Expand All @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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),
Expand Down