Skip to content

Commit 412dddd

Browse files
authored
Merge pull request #49 from encap/dev
fix calculating percent of completion
2 parents a1d8e4f + a6ec127 commit 412dddd

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

public/exampleResults.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1914,7 +1914,7 @@
19141914
"lastThirdStartTime": 61622,
19151915
"timeFromFirstInput": 76782,
19161916
"codeLength": 216,
1917-
"correctInputs": 216,
1917+
"correctLines": 12,
19181918
"mode": 0,
19191919
"file": {
19201920
"languageName": "R",

src/components/CodeEditor.vue

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ export default {
279279
280280
281281
if (this.currentLine + 1 === this.codeInfo.lines && this.correctCharsInLine === this.cm.getLine(this.currentLine).length) {
282+
this.stats.history.push(this.currentChange);
282283
this.completed();
283284
} else if (this.options.underScore) {
284285
if (this.currentChar !== lineText.length) {
@@ -471,6 +472,7 @@ export default {
471472
}
472473
473474
if (this.currentChange.type !== 'initialType') {
475+
this.stats.history.push(this.currentChange);
474476
if (this.options.selectedMode === 2 && this.currentChange.type !== 'correct') {
475477
if (this.stats.history.length < 30) {
476478
this.cm.setOption('readOnly', 'nocursor');
@@ -479,7 +481,6 @@ export default {
479481
this.completed();
480482
}
481483
}
482-
this.stats.history.push(this.currentChange);
483484
} else {
484485
console.red('Current change type equals initial type');
485486
console.log(JSON.parse(JSON.stringify(this.currentChange)));
@@ -604,9 +605,7 @@ export default {
604605
this.$socket.client.emit('completed');
605606
}
606607
607-
const correctInputs = this.stats.history.reduce((acc, event) => (event.type === 'correct' ? acc + 1 : acc), 0);
608-
609-
const complete = correctInputs === this.codeText.length;
608+
const complete = this.currentLine + 1 >= this.codeInfo.lines;
610609
611610
const endMsgList = ['Too long, uh?', 'Time is over', 'Game over'];
612611
this.popUp(true, complete ? 'Congratulations' : endMsgList[this.options.selectedMode]);
@@ -625,7 +624,6 @@ export default {
625624
file: this.codeInfo,
626625
mode: this.options.selectedMode,
627626
complete,
628-
correctInputs,
629627
};
630628
}
631629

src/views/Results.vue

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
Characters
3535
</p>
3636
<h2 class="value">
37-
{{ stats.correctInputs }}
37+
{{ correctInputs }}
3838
</h2>
3939
</div>
4040
</div>
@@ -47,8 +47,8 @@
4747
<p>Longest correction time: {{ format(longestTimeOfCorrection) }} s</p>
4848
</template>
4949
<template v-else>
50-
<p>You made a mistake after {{ stats.correctInputs }} correct characters</p>
51-
<p>{{ stats.codeLength - stats.correctInputs }} characters left</p>
50+
<p>You made a mistake after {{ correctInputs }} correct characters</p>
51+
<p>{{ stats.file.lines - stats.correctLines }} lines left</p>
5252
<p>{{ percentCompleted }}% completed</p>
5353
</template>
5454
</div>
@@ -116,20 +116,23 @@ export default {
116116
mistakes() {
117117
return this.history.filter((change) => change.type === 'mistake');
118118
},
119+
correctInputs() {
120+
return this.history.reduce((acc, event) => (event.type === 'correct' ? acc + 1 : acc), 0);
121+
},
119122
minutes() {
120123
return Math.floor(this.stats.timeFromFirstInput / 1000 / 60);
121124
},
122125
seconds() {
123126
return Math.round((this.stats.timeFromFirstInput / 1000) % 60);
124127
},
125128
CPM() {
126-
return this.stats.correctInputs / this.format(this.stats.timeFromFirstInput, 4) * 60;
129+
return this.correctInputs / this.format(this.stats.timeFromFirstInput, 4) * 60;
127130
},
128131
WPM() {
129132
return this.CPM / 5;
130133
},
131134
percentCompleted() {
132-
return this.format(this.stats.correctInputs / this.stats.codeLength, 1, 100);
135+
return this.format(this.correctLines / this.stats.file.lines, 1, 100);
133136
},
134137
mostMistakesInARow() {
135138
return this.mistakes.map((obj) => obj.fixQueuePos)
@@ -156,7 +159,7 @@ export default {
156159
return timesAcc;
157160
},
158161
WPMWithoutTimeLost() {
159-
return this.stats.correctInputs / this.format(this.stats.timeFromFirstInput - this.totalTimeLost, 4) * 60 / 5;
162+
return this.correctInputs / this.format(this.stats.timeFromFirstInput - this.totalTimeLost, 4) * 60 / 5;
160163
},
161164
totalTimeLost() {
162165
return this.correctionTimes.reduce((acc, value) => acc + value, 0);
@@ -176,7 +179,7 @@ export default {
176179
wpm: this.format(this.WPM, 0, 1),
177180
minutes: this.minutes,
178181
seconds: this.seconds,
179-
correct: this.stats.correctInputs,
182+
correct: this.correctInputs,
180183
});
181184
182185
// if (this.stats.file.index !== -1) {
@@ -216,7 +219,7 @@ export default {
216219
percentCompleted: this.percentCompleted,
217220
},
218221
misc: {
219-
correctClicks: this.stats.correctInputs,
222+
correctClicks: this.correctInputs,
220223
correctLines: this.stats.correctLines,
221224
backspaceClicks,
222225
deletingTime: this.format(deletingTime, 0),

0 commit comments

Comments
 (0)