Skip to content

Commit

Permalink
fix: leaderboard consistency being null (#5055)
Browse files Browse the repository at this point in the history
  • Loading branch information
fehmer authored Feb 14, 2024
1 parent 29fce99 commit a72aa04
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
22 changes: 22 additions & 0 deletions backend/__tests__/dal/leaderboards.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,28 @@ describe("LeaderboardsDal", () => {
expect(lb[0]).not.toHaveProperty("discordAvatar");
});

it("should remove consistency from results if null", async () => {
//GIVEN
const stats = pb(100, 90, 2);
//@ts-ignore
stats["consistency"] = undefined;

await createUser(lbBests(stats));

//WHEN
//WHEN
await LeaderboardsDal.update("time", "15", "english");
const lb = (await LeaderboardsDal.get(
"time",
"15",
"english",
0
)) as SharedTypes.LeaderboardEntry[];

//THEN
expect(lb[0]).not.toHaveProperty("consistency");
});

it("should update public speedHistogram for time english 15", async () => {
//GIVEN
const rank1 = await createUser(lbBests(pb(10), pb(60)));
Expand Down
3 changes: 3 additions & 0 deletions backend/src/dal/leaderboards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ export async function update(
[`${key}.discordAvatar`]: {
$ifNull: ["$discordAvatar", "$$REMOVE"],
},
[`${key}.consistency`]: {
$ifNull: [`$${key}.consistency`, "$$REMOVE"],
},
[`${key}.rank`]: {
$function: {
body: "function() {try {row_number+= 1;} catch (e) {row_number= 1;}return row_number;}",
Expand Down
8 changes: 2 additions & 6 deletions frontend/src/ts/elements/leaderboards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,7 @@ function updateFooter(lb: LbKey): void {
<div class="sub">${entry.acc.toFixed(2)}%</div></td>
<td class="alignRight">${typingSpeedUnit.fromWpm(entry.raw).toFixed(2)}<br>
<div class="sub">${
entry.consistency === undefined || entry.consistency === "-"
? "-"
: entry.consistency.toFixed(2) + "%"
entry.consistency === undefined ? "-" : entry.consistency.toFixed(2) + "%"
}</div></td>
<td class="alignRight">${format(date, "dd MMM yyyy")}<br>
<div class='sub'>${format(date, "HH:mm")}</div></td>
Expand Down Expand Up @@ -341,9 +339,7 @@ async function fillTable(lb: LbKey): Promise<void> {
<div class="sub">${entry.acc.toFixed(2)}%</div></td>
<td class="alignRight">${typingSpeedUnit.fromWpm(entry.raw).toFixed(2)}<br>
<div class="sub">${
entry.consistency === undefined || entry.consistency === "-"
? "-"
: entry.consistency.toFixed(2) + "%"
entry.consistency === undefined ? "-" : entry.consistency.toFixed(2) + "%"
}</div></td>
<td class="alignRight">${format(date, "dd MMM yyyy")}<br>
<div class='sub'>${format(date, "HH:mm")}</div></td>
Expand Down
2 changes: 1 addition & 1 deletion shared-types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ declare namespace SharedTypes {
acc: number;
timestamp: number;
raw: number;
consistency: number | "-";
consistency?: number;
uid: string;
name: string;
discordId?: string;
Expand Down

0 comments on commit a72aa04

Please sign in to comment.