Merge pull request #809 from Jonny-exe/patch-2

Added an personal average pace maker
This commit is contained in:
Jack 2021-01-10 14:40:49 +00:00 committed by GitHub
commit af996d3e84
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 68 additions and 4 deletions

View file

@ -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

View file

@ -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) => {
});
}
});

View file

@ -1001,6 +1001,13 @@ let commandsPaceCaret = {
setPaceCaret("pb");
},
},
{
id: "setPaceCaretAverage",
display: "average",
exec: () => {
setPaceCaret("average");
},
},
{
id: "setPaceCaretCustom",
display: "custom...",

View file

@ -162,6 +162,44 @@ export async function db_getUserHighestWpm(
return retval;
}
export async function db_getUserAverageWpm10(
mode,
punctuation,
language,
difficulty
) {
function cont() {
let wpmSum = 0;
let count = 0;
// You have to use every so you can break out of the loop
dbSnapshot.results.every((result) => {
if (
result.mode == mode &&
result.punctuation == punctuation &&
result.language == language &&
result.difficulty == difficulty
) {
wpmSum += result.wpm;
count++;
if (count < 10) {
return true;
}
}
});
return Math.round(wpmSum / count);
}
let retval = 0;
if (dbSnapshot == null) return retval;
var dbSnapshotValid = await db_getUserResults();
if (dbSnapshotValid === false) {
return retval;
}
retval = cont();
return retval;
}
export async function db_getLocalPB(
mode,
mode2,

View file

@ -14,6 +14,7 @@ import {
db_getUserResults,
db_getUserHighestWpm,
db_getLocalPB,
db_getUserAverageWpm10,
db_saveLocalPB,
db_getLocalTagPB,
db_saveLocalTagPB,

View file

@ -3591,7 +3591,11 @@ function updateTestModesNotice() {
if (config.paceCaret !== "off") {
$(".pageTest #testModesNotice").append(
`<div class="text-button" commands="commandsPaceCaret"><i class="fas fa-tachometer-alt"></i>${
config.paceCaret === "pb" ? "pb" : config.paceCaretCustomSpeed + " wpm"
config.paceCaret === "average"
? "average"
: config.paceCaret === "pb"
? "pb"
: config.paceCaretCustomSpeed + " wpm"
} pace</div>`
);
}
@ -3931,6 +3935,13 @@ async function initPaceCaret() {
config.language,
config.difficulty
);
} else if (config.paceCaret === "average") {
wpm = await db_getUserAverageWpm10(
config.mode,
config.punctuation,
config.language,
config.difficulty
);
} else if (config.paceCaret === "custom") {
wpm = config.paceCaretCustomSpeed;
}

View file

@ -2211,6 +2211,14 @@
>
off
</div>
<div
class="button"
paceCaret="average"
tabindex="0"
onclick="this.blur();"
>
average
</div>
<div
class="button"
paceCaret="pb"