|
import pandas as pd |
|
|
|
def assign_badges(csv_file): |
|
""" |
|
Assigns badges based on quiz performance, speed, and consistency. |
|
|
|
Expected CSV columns: |
|
- Name |
|
- AverageScore (0β100) |
|
- TimeTaken (in minutes) |
|
- Consistency (0β1 scale) |
|
|
|
Returns: |
|
str: Badge assignment summary. |
|
""" |
|
try: |
|
df = pd.read_csv(csv_file) |
|
|
|
|
|
expected_cols = {"Name", "AverageScore", "TimeTaken", "Consistency"} |
|
if not expected_cols.issubset(df.columns): |
|
return "β CSV must contain: Name, AverageScore, TimeTaken, Consistency" |
|
|
|
result = "π
Badge Assignment Summary:\n\n" |
|
for index, row in df.iterrows(): |
|
name = row["Name"] |
|
score = row["AverageScore"] |
|
time_taken = row["TimeTaken"] |
|
consistency = row["Consistency"] |
|
|
|
|
|
if score >= 85 and consistency >= 0.9 and time_taken <= 20: |
|
badge = "π₯ Gold" |
|
elif score >= 70 and consistency >= 0.7 and time_taken <= 30: |
|
badge = "π₯ Silver" |
|
elif score >= 50: |
|
badge = "π₯ Bronze" |
|
else: |
|
badge = "β No Badge" |
|
|
|
result += f"{name}: {badge}\n" |
|
|
|
return result |
|
|
|
except Exception as e: |
|
return f"Error assigning badges: {str(e)}" |
|
|