PointBasedLeaderboards - IEEE-Team-3/map GitHub Wiki
The point-based leaderboard ranks users based on the total number of points they have accumulated. This leaderboard will be sorted from the highest to the lowest number of points.
The leaderboard is primarily sorted by the total points. Additional criteria can include factors such as task completion time, bonus points, etc.
- Rank: Position in the leaderboard.
- User: The name or ID of the user.
- Points: Total number of points accumulated.
- Tasks Completed: Number of tasks completed.
const PointBasedLeaderboardSchema = new Schema({
rank: { type: Number, required: true },
userId: { type: Schema.Types.ObjectId, ref: 'User' },
totalPoints: { type: Number, required: true },
completedTasks: { type: Number, required: true },
});
Users can view their rankings based on their accumulated points through the dashboard, and the leaderboard will update periodically to reflect the current rankings.
function updatePointBasedLeaderboard(userId, points) {
const leaderboard = new PointBasedLeaderboard({
userId,
totalPoints: points,
completedTasks: getCompletedTasks(userId),
rank: calculateRank(points),
});
leaderboard.save();
}
function calculateRank(points) {
// Calculate rank based on total points
return 1; // Example logic
}
function getCompletedTasks(userId) {
// Fetch completed tasks for the user
return 10; // Example logic
}