Skip to content

Commit 42823b0

Browse files
Feature/add global ranking (#120)
* feat: add global ranking to sync script and profile history * ranking from data * taking global ranking from original api instead of snapshots * Remove ranking changes from leaderboard sync logic Removed ranking data from leaderboard calculations. * Format codebase using Prettier * Simplify ranking assignment in fetch-student-info Remove unnecessary ranking assignment logic. * Add 'use strict' directive to sync-leaderboard.js
1 parent e9462c6 commit 42823b0

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

scripts/fetch-student-info.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,27 @@ async function fetchStudentHistory(username) {
1515
console.log("Fetching history for:", username);
1616

1717
let history = [];
18+
let ranking = null;
1819
let missingFilesCount = 0;
1920
const maxDays = 365;
2021
const chunkSize = 100;
2122

23+
try {
24+
const liveApiUrl = `https://leetcode-api-dun.vercel.app/${username}`;
25+
const apiResponse = await fetch(liveApiUrl);
26+
if (apiResponse.ok) {
27+
const apiData = await apiResponse.json();
28+
// Captures the live ranking directly from the endpoint payload
29+
ranking = apiData.ranking || 0;
30+
console.log(`Live ranking fetched for ${username}:`, ranking);
31+
}
32+
} catch (err) {
33+
console.error(
34+
"Failed to fetch live global ranking from API wrapper:",
35+
err.message,
36+
);
37+
}
38+
2239
let done = false;
2340

2441
for (let chunkStart = 0; chunkStart < maxDays; chunkStart += chunkSize) {
@@ -82,6 +99,7 @@ async function fetchStudentHistory(username) {
8299

83100
return {
84101
username,
102+
ranking,
85103
history,
86104
};
87105
}

scripts/sync-leaderboard.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,12 @@ async function computeRankChanges(currentSorted, filename) {
196196
dailyData.splice(i--, 1);
197197
continue;
198198
}
199+
199200
dailyData[i].data.easySolved -= previousData[previousIndex].data.easySolved;
200201
dailyData[i].data.mediumSolved -=
201202
previousData[previousIndex].data.mediumSolved;
202203
dailyData[i].data.hardSolved -= previousData[previousIndex].data.hardSolved;
204+
203205
dailyData[i].score =
204206
dailyData[i].data.easySolved +
205207
dailyData[i].data.mediumSolved * 3 +

0 commit comments

Comments
 (0)