Skip to content

Commit

Permalink
chore: simplify level calculation code
Browse files Browse the repository at this point in the history
  • Loading branch information
kemuru committed Dec 11, 2024
1 parent 56627ab commit d8da344
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions web/src/utils/userLevelCalculation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ const levelCriteria: ILevelCriteria[] = [
];

export const getUserLevelData = (coherenceScore: number, totalResolvedDisputes: number) => {
for (const criteria of levelCriteria) {
for (const criteria of [...levelCriteria].sort((a, b) => b.level - a.level)) {
if (
criteria.level > 0 &&
totalResolvedDisputes >= criteria.minDisputes &&
coherenceScore >= criteria.minScore &&
coherenceScore <= criteria.maxScore
Expand All @@ -26,13 +25,5 @@ export const getUserLevelData = (coherenceScore: number, totalResolvedDisputes:
}
}

if (
totalResolvedDisputes >= levelCriteria[0].minDisputes &&
coherenceScore >= levelCriteria[0].minScore &&
coherenceScore <= levelCriteria[0].maxScore
) {
return levelCriteria[0];
}

return levelCriteria.find(({ level }) => level === 1);
};

0 comments on commit d8da344

Please sign in to comment.