added daily pace caret mode

closes #3564
This commit is contained in:
Miodec 2022-09-28 13:07:07 +02:00
parent b9f1caadcd
commit 40addbf97f
8 changed files with 95 additions and 4 deletions

View file

@ -81,7 +81,9 @@ const CONFIG_SCHEMA = joi.object({
soundVolume: joi.string().valid("0.1", "0.5", "1.0"),
startGraphsAtZero: joi.boolean(),
showOutOfFocusWarning: joi.boolean(),
paceCaret: joi.string().valid("off", "average", "pb", "last", "custom"),
paceCaret: joi
.string()
.valid("off", "average", "pb", "last", "daily", "custom"),
paceCaretCustomSpeed: joi.number().min(0),
repeatedPace: joi.boolean(),
pageWidth: joi.string().valid("100", "125", "150", "200", "max"),

View file

@ -41,6 +41,15 @@ const subgroup: MonkeyTypes.CommandsSubgroup = {
TestLogic.restart();
},
},
{
id: "setPaceCaretDaily",
display: "daily",
configValue: "daily",
exec: (): void => {
UpdateConfig.setPaceCaret("daily");
TestLogic.restart();
},
},
{
id: "setPaceCaretCustom",
display: "custom...",

View file

@ -346,7 +346,7 @@ export function setPaceCaret(
): boolean {
if (
!isConfigValueValid("pace caret", val, [
["custom", "off", "average", "pb", "last"],
["custom", "off", "average", "pb", "last", "daily"],
])
) {
return false;

View file

@ -428,6 +428,65 @@ export async function getUserAverage10<M extends MonkeyTypes.Mode>(
return retval;
}
export async function getUserDailyBest<M extends MonkeyTypes.Mode>(
mode: M,
mode2: MonkeyTypes.Mode2<M>,
punctuation: boolean,
language: string,
difficulty: MonkeyTypes.Difficulty,
lazyMode: boolean
): Promise<number> {
const snapshot = getSnapshot();
if (!snapshot) return 0;
function cont(): number {
const activeTagIds: string[] = [];
snapshot.tags?.forEach((tag) => {
if (tag.active === true) {
activeTagIds.push(tag._id);
}
});
let bestWpm = 0;
if (snapshot.results !== undefined) {
for (const result of snapshot.results) {
if (
result.mode === mode &&
result.punctuation === punctuation &&
result.language === language &&
result.difficulty === difficulty &&
(result.lazyMode === lazyMode ||
(result.lazyMode === undefined && lazyMode === false)) &&
(activeTagIds.length === 0 ||
activeTagIds.some((tagId) => result.tags.includes(tagId)))
) {
if (result.timestamp < Date.now() - 86400000) {
continue;
}
// Continue if the mode2 doesn't match and it's not a quote
if (result.mode2 !== mode2 && mode !== "quote") {
continue;
}
if (result.wpm > bestWpm) {
bestWpm = result.wpm;
}
}
}
}
return bestWpm;
}
const retval: number =
snapshot === null || (await getUserResults()) === null ? 0 : cont();
return retval;
}
export async function getLocalPB<M extends MonkeyTypes.Mode>(
mode: M,
mode2: MonkeyTypes.Mode2<M>,

View file

@ -116,6 +116,8 @@ export async function update(): Promise<void> {
? "pb"
: Config.paceCaret === "last"
? "last"
: Config.paceCaret === "daily"
? "daily"
: "custom"
} pace${speed}</div>`
);

View file

@ -75,6 +75,16 @@ export async function init(): Promise<void> {
Config.lazyMode
);
wpm = Math.round(wpm);
} else if (Config.paceCaret === "daily") {
wpm = await DB.getUserDailyBest(
Config.mode,
mode2,
Config.punctuation,
Config.language,
Config.difficulty,
Config.lazyMode
);
wpm = Math.round(wpm);
} else if (Config.paceCaret === "custom") {
wpm = Config.paceCaretCustomSpeed;
} else if (Config.paceCaret === "last" || TestState.isPaceRepeat == true) {

View file

@ -108,7 +108,7 @@ declare namespace MonkeyTypes {
type SoundVolume = "0.1" | "0.5" | "1.0";
type PaceCaret = "off" | "average" | "pb" | "last" | "custom";
type PaceCaret = "off" | "average" | "pb" | "last" | "custom" | "daily";
type PageWidth = "100" | "125" | "150" | "200" | "max";

View file

@ -1035,7 +1035,8 @@
<h1>pace caret</h1>
<div class="text">
Displays a second caret that moves at constant speed. The 'average'
option averages the speed of last 10 results.
option averages the speed of last 10 results. The 'daily' option takes
the highest speed of the last 24 hours.
</div>
<div>
<div class="inputAndButton">
@ -1085,6 +1086,14 @@
>
last
</div>
<div
class="button"
paceCaret="daily"
tabindex="0"
onclick="this.blur();"
>
daily
</div>
<div
class="button"
paceCaret="custom"