diff --git a/backend/src/api/schemas/config-schema.ts b/backend/src/api/schemas/config-schema.ts index fd8462794..f37d1d972 100644 --- a/backend/src/api/schemas/config-schema.ts +++ b/backend/src/api/schemas/config-schema.ts @@ -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"), diff --git a/frontend/src/ts/commandline/lists/pace-caret.ts b/frontend/src/ts/commandline/lists/pace-caret.ts index 492da32ac..f71fcc0da 100644 --- a/frontend/src/ts/commandline/lists/pace-caret.ts +++ b/frontend/src/ts/commandline/lists/pace-caret.ts @@ -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...", diff --git a/frontend/src/ts/config.ts b/frontend/src/ts/config.ts index 6d05cfb3c..cc0a3d46c 100644 --- a/frontend/src/ts/config.ts +++ b/frontend/src/ts/config.ts @@ -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; diff --git a/frontend/src/ts/db.ts b/frontend/src/ts/db.ts index f2c8d273b..337797e27 100644 --- a/frontend/src/ts/db.ts +++ b/frontend/src/ts/db.ts @@ -428,6 +428,65 @@ export async function getUserAverage10( return retval; } +export async function getUserDailyBest( + mode: M, + mode2: MonkeyTypes.Mode2, + punctuation: boolean, + language: string, + difficulty: MonkeyTypes.Difficulty, + lazyMode: boolean +): Promise { + 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( mode: M, mode2: MonkeyTypes.Mode2, diff --git a/frontend/src/ts/elements/modes-notice.ts b/frontend/src/ts/elements/modes-notice.ts index ae42e200d..ce4849e4f 100644 --- a/frontend/src/ts/elements/modes-notice.ts +++ b/frontend/src/ts/elements/modes-notice.ts @@ -116,6 +116,8 @@ export async function update(): Promise { ? "pb" : Config.paceCaret === "last" ? "last" + : Config.paceCaret === "daily" + ? "daily" : "custom" } pace${speed}` ); diff --git a/frontend/src/ts/test/pace-caret.ts b/frontend/src/ts/test/pace-caret.ts index 7571f79f6..4643655a2 100644 --- a/frontend/src/ts/test/pace-caret.ts +++ b/frontend/src/ts/test/pace-caret.ts @@ -75,6 +75,16 @@ export async function init(): Promise { 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) { diff --git a/frontend/src/ts/types/types.d.ts b/frontend/src/ts/types/types.d.ts index 487276503..537c96ec6 100644 --- a/frontend/src/ts/types/types.d.ts +++ b/frontend/src/ts/types/types.d.ts @@ -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"; diff --git a/frontend/static/html/pages/settings.html b/frontend/static/html/pages/settings.html index 449709389..da30b7846 100644 --- a/frontend/static/html/pages/settings.html +++ b/frontend/static/html/pages/settings.html @@ -1035,7 +1035,8 @@

pace caret

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.
@@ -1085,6 +1086,14 @@ > last
+
+ daily +