sathwikabhavaraju2005 commited on
Commit
5c6797c
Β·
verified Β·
1 Parent(s): d6db648

Create badge.py

Browse files
Files changed (1) hide show
  1. utils/badge.py +46 -0
utils/badge.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+
3
+ def assign_badges(csv_file):
4
+ """
5
+ Assigns badges based on quiz performance, speed, and consistency.
6
+
7
+ Expected CSV columns:
8
+ - Name
9
+ - AverageScore (0–100)
10
+ - TimeTaken (in minutes)
11
+ - Consistency (0–1 scale)
12
+
13
+ Returns:
14
+ str: Badge assignment summary.
15
+ """
16
+ try:
17
+ df = pd.read_csv(csv_file)
18
+
19
+ # Validate columns
20
+ expected_cols = {"Name", "AverageScore", "TimeTaken", "Consistency"}
21
+ if not expected_cols.issubset(df.columns):
22
+ return "❌ CSV must contain: Name, AverageScore, TimeTaken, Consistency"
23
+
24
+ result = "πŸ… Badge Assignment Summary:\n\n"
25
+ for index, row in df.iterrows():
26
+ name = row["Name"]
27
+ score = row["AverageScore"]
28
+ time_taken = row["TimeTaken"]
29
+ consistency = row["Consistency"]
30
+
31
+ # Rule-based badge logic
32
+ if score >= 85 and consistency >= 0.9 and time_taken <= 20:
33
+ badge = "πŸ₯‡ Gold"
34
+ elif score >= 70 and consistency >= 0.7 and time_taken <= 30:
35
+ badge = "πŸ₯ˆ Silver"
36
+ elif score >= 50:
37
+ badge = "πŸ₯‰ Bronze"
38
+ else:
39
+ badge = "❌ No Badge"
40
+
41
+ result += f"{name}: {badge}\n"
42
+
43
+ return result
44
+
45
+ except Exception as e:
46
+ return f"Error assigning badges: {str(e)}"