From 9ba9f13576c1b99bdd977f215693d602d82af7a3 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 2 May 2025 01:11:27 -0400 Subject: [PATCH] fixed leaderboard rank and flags not correct numbers --- .../src/app/leaderboard/leaderboard.component.html | 4 ++-- .../src/app/leaderboard/leaderboard.component.ts | 11 ++++------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/CTF/CTF-Frontend/src/app/leaderboard/leaderboard.component.html b/CTF/CTF-Frontend/src/app/leaderboard/leaderboard.component.html index 72fe8a2..f63078a 100644 --- a/CTF/CTF-Frontend/src/app/leaderboard/leaderboard.component.html +++ b/CTF/CTF-Frontend/src/app/leaderboard/leaderboard.component.html @@ -22,8 +22,8 @@ - - {{ getRank() - 12 }} + + {{ getRank(index+1) }} {{ user.Name }} {{ user.Flags }} diff --git a/CTF/CTF-Frontend/src/app/leaderboard/leaderboard.component.ts b/CTF/CTF-Frontend/src/app/leaderboard/leaderboard.component.ts index 0f730ab..99efab8 100644 --- a/CTF/CTF-Frontend/src/app/leaderboard/leaderboard.component.ts +++ b/CTF/CTF-Frontend/src/app/leaderboard/leaderboard.component.ts @@ -23,7 +23,6 @@ import { Submission } from '../models/submission.model'; }) export class LeaderboardComponent { users: User[] = []; // array of all usrs - rank: number = 0; // rank number for indexing table contest: string | null = ""; // contest name contestObj : Contest | null = null; contestID : number | undefined = 0; // contest ID @@ -35,7 +34,6 @@ export class LeaderboardComponent { // on initialize ngOnInit() { - this.rank = 0; this.PopulateTable(); this.contest = sessionStorage.getItem('ContestString'); } @@ -85,19 +83,18 @@ export class LeaderboardComponent { let user = this.users[i]; this.users[i].Flags = 0; for (let j=0; j < this.subs.length; j++) { - let sub = this.subs[i]; + let sub = this.subs[j]; if (user.UserID == sub.UserID && sub.IsCorrect == true) { this.users[i].Flags++; } } } - this.users = this.users.sort((a,b) => a.Flags + b.Flags); // sort the users + this.users = this.users.sort((a,b) => b.Flags - a.Flags); // sort the users } // increment rank and insert into table - getRank(): number { - this.rank++; - return this.rank; + getRank(index: number): number { + return index++; } }