From da6bc165a2dbfc604ec57c3e0a1f8fbe7b569700 Mon Sep 17 00:00:00 2001 From: Jonny-exe <69385502+Jonny-exe@users.noreply.github.com> Date: Thu, 7 Jan 2021 10:41:12 +0100 Subject: [PATCH 1/3] removed dot to make it more consistent --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dbb899141..38378c79d 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ Montydrei for the name suggestion Everyone who provided valuable feedback on the original reddit post for the prototype of this website -Contributors that have helped with implementing various features, adding themes and more. +Contributors that have helped with implementing various features, adding themes and more # support From 751264c99ba7e51298aeb2bea99bc3360d88a392 Mon Sep 17 00:00:00 2001 From: jonny-exe <69385502+Jonny-exe@users.noreply.github.com> Date: Sat, 9 Jan 2021 15:00:23 +0100 Subject: [PATCH 2/3] Added an average speed pace maker --- src/js/account.js | 3 +-- src/js/commandline.js | 7 +++++++ src/js/db.js | 35 +++++++++++++++++++++++++++++++++++ src/js/global-dependencies.js | 1 + src/js/script.js | 14 +++++++++++++- static/index.html | 8 ++++++++ 6 files changed, 65 insertions(+), 3 deletions(-) diff --git a/src/js/account.js b/src/js/account.js index b586aa0d4..997d40c89 100644 --- a/src/js/account.js +++ b/src/js/account.js @@ -317,7 +317,7 @@ function getAccountDataAndInit() { } else { accountIconLoading(false); } - if (config.paceCaret === "pb") { + if (config.paceCaret === "pb" || config.paceCaret === "average") { if (!testActive) { initPaceCaret(true); } @@ -2433,4 +2433,3 @@ $(".pageLogin #forgotPasswordButton").click((e) => { }); } }); - diff --git a/src/js/commandline.js b/src/js/commandline.js index 7289504d6..b733a1403 100644 --- a/src/js/commandline.js +++ b/src/js/commandline.js @@ -1001,6 +1001,13 @@ let commandsPaceCaret = { setPaceCaret("pb"); }, }, + { + id: "setPaceCaretAverage", + display: "average", + exec: () => { + setPaceCaret("average"); + }, + }, { id: "setPaceCaretCustom", display: "custom...", diff --git a/src/js/db.js b/src/js/db.js index aa8a37dc3..36f446d41 100644 --- a/src/js/db.js +++ b/src/js/db.js @@ -157,6 +157,41 @@ export async function db_getUserHighestWpm( return retval; } +export async function db_getUserAverageWpm10( + mode, + punctuation, + language, + difficulty +) { + function cont() { + let wpmSum = 0; + let count = 0; + dbSnapshot.results.forEach((result) => { + if ( + result.mode == mode && + result.punctuation == punctuation && + result.language == language && + result.difficulty == difficulty + ) { + wpmSum += result.wpm; + count++; + if (count >= 10) { + return Math.round(wpmSum / 10); + } + } + }); + return Math.round(wpmSum / count); + } + + let retval; + if (dbSnapshot == null || dbSnapshot.results === undefined) { + retval = 0; + } else { + retval = cont(); + } + return retval; +} + export async function db_getLocalPB( mode, mode2, diff --git a/src/js/global-dependencies.js b/src/js/global-dependencies.js index fd3476f1a..dc414488a 100644 --- a/src/js/global-dependencies.js +++ b/src/js/global-dependencies.js @@ -14,6 +14,7 @@ import { db_getUserResults, db_getUserHighestWpm, db_getLocalPB, + db_getUserAverageWpm10, db_saveLocalPB, db_getLocalTagPB, db_saveLocalTagPB, diff --git a/src/js/script.js b/src/js/script.js index 2bc091c5d..2beb9175f 100644 --- a/src/js/script.js +++ b/src/js/script.js @@ -3591,7 +3591,11 @@ function updateTestModesNotice() { if (config.paceCaret !== "off") { $(".pageTest #testModesNotice").append( `
` ); } @@ -3931,6 +3935,14 @@ async function initPaceCaret() { config.language, config.difficulty ); + } else if (config.paceCaret === "average") { + await db_getUserResults(); + wpm = await db_getUserAverageWpm10( + config.mode, + config.punctuation, + config.language, + config.difficulty + ); } else if (config.paceCaret === "custom") { wpm = config.paceCaretCustomSpeed; } diff --git a/static/index.html b/static/index.html index 3c1949077..57b9c3ee3 100644 --- a/static/index.html +++ b/static/index.html @@ -2211,6 +2211,14 @@ > off +