LeaderboardModel - IEEE-Team-3/map GitHub Wiki

Overview

The leaderboard model stores information about the ranking system, allowing users to view rankings based on points accumulated through tasks, achievements, and other actions.

Schema Structure

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.

Example Schema

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

Example Use Case

The leaderboard will be updated periodically based on users’ activity and point accumulation.

Backend Logic

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