From 6f8a48696afa1c91a77c709f04c423a01b4141a8 Mon Sep 17 00:00:00 2001 From: Jack Date: Sun, 17 May 2020 13:17:08 +0100 Subject: [PATCH] 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 --- public/css/style.scss | 2 +- public/index.html | 9 +++++++++ public/js/account.js | 14 ++++++++++++-- public/js/script.js | 16 ++++++++++++---- public/js/userconfig.js | 5 +++-- 5 files changed, 37 insertions(+), 9 deletions(-) diff --git a/public/css/style.scss b/public/css/style.scss index 202f12f6b..adc793ee8 100644 --- a/public/css/style.scss +++ b/public/css/style.scss @@ -907,7 +907,7 @@ key { } .triplegroup{ display: grid; - grid-auto-flow: column; + grid-template-columns: 1fr 1fr 2fr; gap: 1rem; } .group{ diff --git a/public/index.html b/public/index.html index 47c2f51e3..7e24bb3cd 100644 --- a/public/index.html +++ b/public/index.html @@ -287,6 +287,15 @@
favourite test
words 10
+
+
test completion
+
-
+
+
+
+
avg restarts per completed test
+
-
+
diff --git a/public/js/account.js b/public/js/account.js index 68de0fe38..001bef253 100644 --- a/public/js/account.js +++ b/public/js/account.js @@ -320,13 +320,16 @@ function refreshAccountPage() { custom: [] } - let topWpm = 0; let topMode = ''; + let testRestarts = 0; let testCount = dbSnapshot.length; $(".pageAccount .history table tbody").empty(); dbSnapshot.forEach(result => { + if (result.restartCount != undefined) { + testRestarts += result.restartCount; + } let withpunc = ''; if (result.punctuation) { withpunc = ', with punctuation'; @@ -397,9 +400,16 @@ function refreshAccountPage() { $(".pageAccount .highestWpm .val").text(topWpm); $(".pageAccount .highestWpm .mode").html(topMode); - $(".pageAccount .testsTaken .val").text(testCount); + $(".pageAccount .testCompletion .val").text( + Math.floor((testCount / (testCount + testRestarts) * 100)) + "%" + ); + + $(".pageAccount .avgRestart .val").text( + ((testCount + testRestarts) / testCount).toFixed(1) + ); + let favMode = testModes.words10; let favModeName = 'words10'; $.each(testModes, (key, mode) => { diff --git a/public/js/script.js b/public/js/script.js index 827af3d48..c73650b3f 100644 --- a/public/js/script.js +++ b/public/js/script.js @@ -8,6 +8,7 @@ let testActive = false; let testStart, testEnd; let wpmHistory = []; let currentCommands = commands; +let restartCount = 0; let accuracyStats = { correct: 0, @@ -432,14 +433,12 @@ function showCrown() { } function showResult() { - //TODO: #2 Sometimes the caret jumps to the top left corner when showing results testEnd = Date.now(); let stats = calculateStats(); clearIntervals(); $("#result .stats .wpm .bottom").text(stats.wpm); $("#result .stats .acc .bottom").text(stats.acc + "%"); $("#result .stats .key .bottom").text(stats.correctChars + "/" + stats.incorrectChars); - let mode2 = ""; if (config.mode == "time") { mode2 = config.time; @@ -456,8 +455,11 @@ function showResult() { mode2: mode2, punctuation: config.punctuation, timestamp: Date.now(), - language: config.language + language: config.language, + restartCount: restartCount }; + console.log(restartCount); + restartCount = 0; if (stats.wpm > 0 && stats.wpm < 250 && stats.acc > 50 && stats.acc <= 100) { if (firebase.auth().currentUser != null) { db_getUserHighestWpm(config.mode, mode2).then(data => { @@ -538,7 +540,6 @@ function restartTest() { hideCaret(); testActive = false; hideLiveWpm(); - $("#words").stop(true, true).animate({ opacity: 0 }, 125); $("#result").stop(true, true).animate({ opacity: 0 @@ -633,6 +634,7 @@ function changePage(page) { history.pushState('/', null, '/'); showTestConfig(); hideSignOutButton(); + restartCount = 0; } else if (page == "about") { $(".page.pageAbout").addClass('active'); swapElements(activePage, $(".page.pageAbout"), 250); @@ -838,6 +840,9 @@ $(window).on('popstate', (e) => { $(document).on("keypress", "#restartTestButton", (event) => { if (event.keyCode == 32 || event.keyCode == 13) { + if (testActive) { + restartCount++; + } restartTest(); } }); @@ -936,6 +941,9 @@ $(document).keydown((event) => { if (event["keyCode"] == 9) { if (config.quickTab && $(".pageTest").hasClass("active")) { event.preventDefault(); + if (testActive) { + restartCount++; + } restartTest(); } } diff --git a/public/js/userconfig.js b/public/js/userconfig.js index d49fefb28..cf75971d6 100644 --- a/public/js/userconfig.js +++ b/public/js/userconfig.js @@ -14,8 +14,9 @@ let config = { //cookies function saveConfigToCookie() { let d = new Date(); - d.setFullYear(d.getFullYear() + 1) - $.cookie("config", JSON.stringify(config), { expires: d }) + d.setFullYear(d.getFullYear() + 1); + $.cookie("config", JSON.stringify(config), { expires: d }); + restartCount = 0; } function loadConfigFromCookie() {