Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix tags personal bests handling of missing numbers flag (fehmer) #5146

Merged
merged 3 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 11 additions & 40 deletions frontend/src/ts/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ export async function getUserResults(offset?: number): Promise<boolean> {
}
if (result.numbers === undefined) result.numbers = false;
if (result.punctuation === undefined) result.punctuation = false;
if (result.numbers === undefined) result.numbers = false;
if (result.quoteLength === undefined) result.quoteLength = -1;
if (result.restartCount === undefined) result.restartCount = 0;
if (result.incompleteTestSeconds === undefined) {
Expand Down Expand Up @@ -403,44 +404,11 @@ export async function deleteCustomTheme(themeId: string): Promise<boolean> {
return true;
}

async function _getUserHighestWpm<M extends SharedTypes.Config.Mode>(
mode: M,
mode2: SharedTypes.Config.Mode2<M>,
punctuation: boolean,
language: string,
difficulty: SharedTypes.Config.Difficulty,
lazyMode: boolean
): Promise<number> {
function cont(): number {
let topWpm = 0;

dbSnapshot?.results?.forEach((result) => {
if (
result.mode === mode &&
`${result.mode2}` === `${mode2 as string | number}` && //using template strings here because legacy results can have numbers in mode2
result.punctuation === punctuation &&
result.language === language &&
result.difficulty === difficulty &&
(result.lazyMode === lazyMode ||
(result.lazyMode === undefined && !lazyMode))
) {
if (result.wpm > topWpm) {
topWpm = result.wpm;
}
}
});
return topWpm;
}

const retval = !dbSnapshot || dbSnapshot.results === undefined ? 0 : cont();

return retval;
}

export async function getUserAverage10<M extends SharedTypes.Config.Mode>(
mode: M,
mode2: SharedTypes.Config.Mode2<M>,
punctuation: boolean,
numbers: boolean,
language: string,
difficulty: SharedTypes.Config.Difficulty,
lazyMode: boolean
Expand Down Expand Up @@ -468,7 +436,8 @@ export async function getUserAverage10<M extends SharedTypes.Config.Mode>(
for (const result of snapshot.results) {
if (
result.mode === mode &&
result.punctuation === punctuation &&
(result.punctuation ?? false) === punctuation &&
(result.numbers ?? false) === numbers &&
result.language === language &&
result.difficulty === difficulty &&
(result.lazyMode === lazyMode ||
Expand Down Expand Up @@ -524,6 +493,7 @@ export async function getUserDailyBest<M extends SharedTypes.Config.Mode>(
mode: M,
mode2: SharedTypes.Config.Mode2<M>,
punctuation: boolean,
numbers: boolean,
language: string,
difficulty: SharedTypes.Config.Difficulty,
lazyMode: boolean
Expand All @@ -546,7 +516,8 @@ export async function getUserDailyBest<M extends SharedTypes.Config.Mode>(
for (const result of snapshot.results) {
if (
result.mode === mode &&
result.punctuation === punctuation &&
(result.punctuation ?? false) === punctuation &&
(result.numbers ?? false) === numbers &&
result.language === language &&
result.difficulty === difficulty &&
(result.lazyMode === lazyMode ||
Expand Down Expand Up @@ -742,8 +713,8 @@ export async function getLocalTagPB<M extends SharedTypes.Config.Mode>(
ret =
personalBests.find(
(pb) =>
pb.punctuation === punctuation &&
pb.numbers === numbers &&
(pb.punctuation ?? false) === punctuation &&
(pb.numbers ?? false) === numbers &&
pb.difficulty === difficulty &&
pb.language === language &&
(pb.lazyMode === lazyMode || (pb.lazyMode === undefined && !lazyMode))
Expand Down Expand Up @@ -797,8 +768,8 @@ export async function saveLocalTagPB<M extends SharedTypes.Config.Mode>(
] as unknown as SharedTypes.PersonalBest[]
).forEach((pb) => {
if (
pb.punctuation === punctuation &&
pb.numbers === numbers &&
(pb.punctuation ?? false) === punctuation &&
(pb.numbers ?? false) === numbers &&
pb.difficulty === difficulty &&
pb.language === language &&
(pb.lazyMode === lazyMode || (pb.lazyMode === undefined && !lazyMode))
Expand Down
1 change: 1 addition & 0 deletions frontend/src/ts/elements/last-10-average.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export async function update(): Promise<void> {
Config.mode,
mode2 as never,
Config.punctuation,
Config.numbers,
Config.language,
Config.difficulty,
Config.lazyMode
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/ts/test/pace-caret.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export async function init(): Promise<void> {
Config.mode,
mode2,
Config.punctuation,
Config.numbers,
Config.language,
Config.difficulty,
Config.lazyMode
Expand All @@ -90,6 +91,7 @@ export async function init(): Promise<void> {
Config.mode,
mode2,
Config.punctuation,
Config.numbers,
Config.language,
Config.difficulty,
Config.lazyMode
Expand Down
Loading