Study-with-ChampAI / quiz /scoring.py
SolusOps's picture
feat: quiz package
676d6d1 verified
Raw
History Blame Contribute Delete
1.32 kB
from __future__ import annotations
_XP_TABLE = {"easy": 10, "medium": 20, "hard": 40}
_BOSS_XP = 75
_WEAK_THRESHOLD = 0.5
_STREAK_LABELS = {0: "", 1: "Nice!", 2: "Good!", 3: "Great!", 4: "Excellent!"}
def xp_for_question(difficulty: str, is_boss: bool) -> int:
if is_boss:
return _BOSS_XP
return _XP_TABLE.get(difficulty, 10)
def streak_label(consecutive: int) -> str:
if consecutive >= 5:
return "LEGENDARY!"
return _STREAK_LABELS.get(consecutive, "")
def compute_grade(score: int, total: int) -> str:
if total == 0:
return "Apprentice"
pct = score / total * 100
if pct >= 80: return "Champion"
if pct >= 60: return "Warrior"
return "Apprentice"
def compute_mastery_delta(correct: int, total: int) -> float:
if total == 0:
return 0.0
return correct / total
def should_unlock_revision_quest(mastery: float) -> bool:
return mastery < _WEAK_THRESHOLD
def mastery_recommendation(mastery: float) -> str:
if mastery < 0.3:
return "Seriously review this topic before moving on."
if mastery < 0.5:
return "More practice needed β€” try the revision quest."
if mastery < 0.8:
return "Getting there β€” a few more battles will sharpen this."
return "Strong mastery β€” ready for the next challenge!"