LeaderboardModel - IEEE-Team-3/map GitHub Wiki
The leaderboard model stores information about the ranking system, allowing users to view rankings based on points accumulated through tasks, achievements, and other actions.
The leaderboard tracks the following information:
- User: The user being ranked.
- Points: The points the user has earned.
- Rank: The position of the user on the leaderboard.
- Date: The date when the leaderboard was generated.
const LeaderboardSchema = new Schema({
userId: { type: Schema.Types.ObjectId, ref: 'User' },
points: { type: Number, required: true },
rank: { type: Number, required: true },
createdAt: { type: Date, default: Date.now }
});
The leaderboard will be updated periodically based on users’ activity and point accumulation.
function updateLeaderboard(userId, points) {
const leaderboardEntry = new Leaderboard({
userId,
points,
rank: calculateRank(points),
});
leaderboardEntry.save();
}
function calculateRank(points) {
// Logic for calculating the user's rank based on points
return 1; // Example logic
}