fixed leaderboard rank and flags not correct numbers

main
Alex 5 months ago
parent 39befe8e9f
commit 9ba9f13576

@ -22,8 +22,8 @@
</tr> </tr>
</thead> </thead>
<tbody id="LeaderTBody"> <tbody id="LeaderTBody">
<tr *ngFor="let user of users"> <tr *ngFor="let user of users; let index = index">
<td>{{ getRank() - 12 }}</td> <td>{{ getRank(index+1) }}</td>
<td>{{ user.Name }}</td> <td>{{ user.Name }}</td>
<td>{{ user.Flags }}</td> <td>{{ user.Flags }}</td>
</tr> </tr>

@ -23,7 +23,6 @@ import { Submission } from '../models/submission.model';
}) })
export class LeaderboardComponent { export class LeaderboardComponent {
users: User[] = []; // array of all usrs users: User[] = []; // array of all usrs
rank: number = 0; // rank number for indexing table
contest: string | null = ""; // contest name contest: string | null = ""; // contest name
contestObj : Contest | null = null; contestObj : Contest | null = null;
contestID : number | undefined = 0; // contest ID contestID : number | undefined = 0; // contest ID
@ -35,7 +34,6 @@ export class LeaderboardComponent {
// on initialize // on initialize
ngOnInit() { ngOnInit() {
this.rank = 0;
this.PopulateTable(); this.PopulateTable();
this.contest = sessionStorage.getItem('ContestString'); this.contest = sessionStorage.getItem('ContestString');
} }
@ -85,19 +83,18 @@ export class LeaderboardComponent {
let user = this.users[i]; let user = this.users[i];
this.users[i].Flags = 0; this.users[i].Flags = 0;
for (let j=0; j < this.subs.length; j++) { 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) { if (user.UserID == sub.UserID && sub.IsCorrect == true) {
this.users[i].Flags++; 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 // increment rank and insert into table
getRank(): number { getRank(index: number): number {
this.rank++; return index++;
return this.rank;
} }
} }

Loading…
Cancel
Save