PointBasedLeaderboards - IEEE-Team-3/map GitHub Wiki

Overview

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.

Sorting Logic

The leaderboard is primarily sorted by the total points. Additional criteria can include factors such as task completion time, bonus points, etc.

Example Structure

  1. Rank: Position in the leaderboard.
  2. User: The name or ID of the user.
  3. Points: Total number of points accumulated.
  4. Tasks Completed: Number of tasks completed.

Example Schema

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 },
});

Example Use Case

Users can view their rankings based on their accumulated points through the dashboard, and the leaderboard will update periodically to reflect the current rankings.

Example Backend Logic

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
}
⚠️ **GitHub.com Fallback** ⚠️