Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/components/ranking-display.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from 'react';
import { BountyData, sortBounties } from '../features/ranking-system';

interface RankingDisplayProps {
bounties: BountyData[];
}

const RankingDisplay: React.FC<RankingDisplayProps> = ({ bounties }) => {
// Sort bounties based on the score
const sortedBounties = sortBounties(bounties);

return (
<div>
<h2>Leaderboard</h2>
<ul>
{sortedBounties.map(bounty => (
<li key={bounty.id}>
<div>
<h3>{bounty.title}</h3>
<p>Reward: ${bounty.reward}</p>
<p>Difficulty: {bounty.difficulty}</p>
<p>Progress: {bounty.progress}%</p>
<p>Score: {bounty.score.toFixed(2)}</p>
</div>
</li>
))}
</ul>
</div>
);
};

export default RankingDisplay;
34 changes: 34 additions & 0 deletions src/features/ranking-system.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// This module provides a ranking algorithm to score and sort mock data based on predefined criteria.

// Define the structure of the data to be scored
export interface BountyData {
id: string;
title: string;
reward: number;
difficulty: number;
progress: number;
tags: string[];
}

// Score the bounty data based on reward, difficulty, and progress
function calculateScore(bounty: BountyData): number {
// Reward has the highest weight, followed by progress and difficulty
const rewardScore = bounty.reward * 0.5;
const progressScore = bounty.progress * 0.3;
const difficultyScore = (1 / bounty.difficulty) * 0.2;

// Return total score
return rewardScore + progressScore + difficultyScore;
}

// Sort bounties by their calculated score in descending order
export function sortBounties(bounties: BountyData[]): BountyData[] {
// Calculate score for each bounty
const bountiesWithScore = bounties.map(bounty => ({...bounty, score: calculateScore(bounty)}));

// Sort bounties by score in descending order
bountiesWithScore.sort((a, b) => b.score - a.score);

// Return sorted bounties
return bountiesWithScore.map(bounty => ({ id: bounty.id, title: bounty.title, reward: bounty.reward, difficulty: bounty.difficulty, progress: bounty.progress, tags: bounty.tags, score: bounty.score }));
}