Skip to content

Commit c5e3ee7

Browse files
committed
added a restart counter
added a stat on how many times the user restarted the test before completion, on average added a stat on the percentage of completed tests
1 parent 19bfa00 commit c5e3ee7

5 files changed

Lines changed: 37 additions & 9 deletions

File tree

public/css/style.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ key {
907907
}
908908
.triplegroup{
909909
display: grid;
910-
grid-auto-flow: column;
910+
grid-template-columns: 1fr 1fr 2fr;
911911
gap: 1rem;
912912
}
913913
.group{

public/index.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,15 @@ <h1>theme</h1>
287287
<div class="title">favourite test</div>
288288
<div class="val">words 10</div>
289289
</div>
290+
<div class="group testCompletion">
291+
<div class="title">test completion</div>
292+
<div class="val">-</div>
293+
</div>
294+
<div></div>
295+
<div class="group avgRestart">
296+
<div class="title">avg restarts per completed test</div>
297+
<div class="val">-</div>
298+
</div>
290299
</div>
291300
<div class="group history">
292301
<!-- <div class="title">result history</div> -->

public/js/account.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,13 +320,16 @@ function refreshAccountPage() {
320320
custom: []
321321
}
322322

323-
324323
let topWpm = 0;
325324
let topMode = '';
325+
let testRestarts = 0;
326326

327327
let testCount = dbSnapshot.length;
328328
$(".pageAccount .history table tbody").empty();
329329
dbSnapshot.forEach(result => {
330+
if (result.restartCount != undefined) {
331+
testRestarts += result.restartCount;
332+
}
330333
let withpunc = '';
331334
if (result.punctuation) {
332335
withpunc = ', with punctuation';
@@ -397,9 +400,16 @@ function refreshAccountPage() {
397400

398401
$(".pageAccount .highestWpm .val").text(topWpm);
399402
$(".pageAccount .highestWpm .mode").html(topMode);
400-
401403
$(".pageAccount .testsTaken .val").text(testCount);
402404

405+
$(".pageAccount .testCompletion .val").text(
406+
Math.floor((testCount / (testCount + testRestarts) * 100)) + "%"
407+
);
408+
409+
$(".pageAccount .avgRestart .val").text(
410+
((testCount + testRestarts) / testCount).toFixed(1)
411+
);
412+
403413
let favMode = testModes.words10;
404414
let favModeName = 'words10';
405415
$.each(testModes, (key, mode) => {

public/js/script.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ let testActive = false;
88
let testStart, testEnd;
99
let wpmHistory = [];
1010
let currentCommands = commands;
11+
let restartCount = 0;
1112

1213
let accuracyStats = {
1314
correct: 0,
@@ -432,14 +433,12 @@ function showCrown() {
432433
}
433434

434435
function showResult() {
435-
//TODO: #2 Sometimes the caret jumps to the top left corner when showing results
436436
testEnd = Date.now();
437437
let stats = calculateStats();
438438
clearIntervals();
439439
$("#result .stats .wpm .bottom").text(stats.wpm);
440440
$("#result .stats .acc .bottom").text(stats.acc + "%");
441441
$("#result .stats .key .bottom").text(stats.correctChars + "/" + stats.incorrectChars);
442-
443442
let mode2 = "";
444443
if (config.mode == "time") {
445444
mode2 = config.time;
@@ -456,8 +455,11 @@ function showResult() {
456455
mode2: mode2,
457456
punctuation: config.punctuation,
458457
timestamp: Date.now(),
459-
language: config.language
458+
language: config.language,
459+
restartCount: restartCount
460460
};
461+
console.log(restartCount);
462+
restartCount = 0;
461463
if (stats.wpm > 0 && stats.wpm < 250 && stats.acc > 50 && stats.acc <= 100) {
462464
if (firebase.auth().currentUser != null) {
463465
db_getUserHighestWpm(config.mode, mode2).then(data => {
@@ -538,7 +540,6 @@ function restartTest() {
538540
hideCaret();
539541
testActive = false;
540542
hideLiveWpm();
541-
542543
$("#words").stop(true, true).animate({ opacity: 0 }, 125);
543544
$("#result").stop(true, true).animate({
544545
opacity: 0
@@ -633,6 +634,7 @@ function changePage(page) {
633634
history.pushState('/', null, '/');
634635
showTestConfig();
635636
hideSignOutButton();
637+
restartCount = 0;
636638
} else if (page == "about") {
637639
$(".page.pageAbout").addClass('active');
638640
swapElements(activePage, $(".page.pageAbout"), 250);
@@ -838,6 +840,9 @@ $(window).on('popstate', (e) => {
838840

839841
$(document).on("keypress", "#restartTestButton", (event) => {
840842
if (event.keyCode == 32 || event.keyCode == 13) {
843+
if (testActive) {
844+
restartCount++;
845+
}
841846
restartTest();
842847
}
843848
});
@@ -936,6 +941,9 @@ $(document).keydown((event) => {
936941
if (event["keyCode"] == 9) {
937942
if (config.quickTab && $(".pageTest").hasClass("active")) {
938943
event.preventDefault();
944+
if (testActive) {
945+
restartCount++;
946+
}
939947
restartTest();
940948
}
941949
}

public/js/userconfig.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ let config = {
1414
//cookies
1515
function saveConfigToCookie() {
1616
let d = new Date();
17-
d.setFullYear(d.getFullYear() + 1)
18-
$.cookie("config", JSON.stringify(config), { expires: d })
17+
d.setFullYear(d.getFullYear() + 1);
18+
$.cookie("config", JSON.stringify(config), { expires: d });
19+
restartCount = 0;
1920
}
2021

2122
function loadConfigFromCookie() {

0 commit comments

Comments
 (0)