Skip to content

Commit abc39d1

Browse files
Yashaswini-K-Pjagdish-15github-actions[bot]
authored
feat: implement BALANCED badge dynamically on user profiles (#492)
* feat: implement BALANCED badge dynamically on user profiles * style: auto-format code with Prettier (/format) --------- Co-authored-by: Jagdish Prajapati <jagadishdrp@gmail.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 7b7a8a1 commit abc39d1

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

‎frontend/js/user/badges.js‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ const ALL_BADGES = [
1414
id: "TOP_BRASS",
1515
title: "Currently ranked in the top 10 on the overall leaderboard",
1616
},
17+
{
18+
id: "BALANCED",
19+
title:
20+
"Solved at least 5 Easy, Medium, and Hard with counts within 5% of each other",
21+
},
1722
{
1823
id: "SPRINTER",
1924
title: "Solved 7 or more problems in a single 24-hour period",
@@ -55,6 +60,23 @@ export async function loadBadges(data) {
5560
}
5661
}
5762

63+
if (history.length >= 1) {
64+
const latest = history[history.length - 1];
65+
const easy = latest.easy || 0;
66+
const medium = latest.medium || 0;
67+
const hard = latest.hard || 0;
68+
69+
if (easy >= 5 && medium >= 5 && hard >= 5) {
70+
const maxCount = Math.max(easy, medium, hard);
71+
const minCount = Math.min(easy, medium, hard);
72+
const diff = maxCount - minCount;
73+
74+
if (diff <= 0.05 * maxCount) {
75+
earnedSet.add("BALANCED");
76+
}
77+
}
78+
}
79+
5880
if (history.length >= 2) {
5981
const latest = history[history.length - 1];
6082
const previous = history[history.length - 2];
@@ -103,7 +125,6 @@ export async function loadBadges(data) {
103125
const badge = document.createElement("div");
104126
const safeClass = badgeDef.id.toLowerCase().replace(/_/g, "");
105127

106-
// Apply locked class if the user hasn't earned it
107128
badge.className = isEarned
108129
? `badge badge-${safeClass}`
109130
: `badge badge-${safeClass} badge-locked`;

‎frontend/user.html‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,13 @@
238238
text-shadow: 0 0 5px rgba(0, 229, 255, 0.3);
239239
}
240240

241+
.badge-balanced {
242+
color: #00f5d4;
243+
background: rgba(0, 245, 212, 0.15);
244+
border-color: rgba(0, 245, 212, 0.5);
245+
text-shadow: 0 0 8px rgba(0, 245, 212, 0.6);
246+
}
247+
241248
.badge-topbrass {
242249
color: #ffffff;
243250
background: linear-gradient(

0 commit comments

Comments
 (0)