CoolFace
Apppublic

SolusOps/Study-with-ChampAI

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
models.py70 linesDownload Raw Back to quiz
1from __future__ import annotations2from dataclasses import dataclass, field3from typing import List4import time5 6VALID_DIFFICULTIES = {"easy", "medium", "hard"}7VALID_TYPES = {"mcq", "tf", "fill"}8 9@dataclass10class Question:11    text: str12    topic: str                      # subject area — "Determinants" not question text13    options: List[str]14    correct_idx: int15    explanation: str16    difficulty: str17    q_type: str18    is_boss: bool = False19    source_excerpt: str = ""        # snippet from original material for tutor context20    language: str = "en"21 22    def __post_init__(self):23        if self.difficulty not in VALID_DIFFICULTIES:24            raise ValueError(f"difficulty must be one of {VALID_DIFFICULTIES}, got '{self.difficulty}'")25        if self.q_type not in VALID_TYPES:26            raise ValueError(f"q_type must be one of {VALID_TYPES}, got '{self.q_type}'")27        if not (0 <= self.correct_idx < len(self.options)):28            raise ValueError(f"correct_idx {self.correct_idx} out of range for {len(self.options)} options")29 30    @property31    def correct_answer(self) -> str:32        return self.options[self.correct_idx]33 34@dataclass35class QuizSession:36    quest_name: str37    questions: List[Question] = field(default_factory=list)38    current_idx: int = 039    score: int = 040    consecutive_correct: int = 041    xp_earned: int = 042    start_time: float = field(default_factory=time.time)43    wrong_topics: List[str] = field(default_factory=list)  # topic strings, not question text44 45    @property46    def is_finished(self) -> bool:47        return self.current_idx >= len(self.questions)48 49    @property50    def current_question(self) -> Question | None:51        if self.is_finished:52            return None53        return self.questions[self.current_idx]54 55@dataclass56class Quest:57    name: str58    topics: List[str]59    boss_topic: str60    difficulty: str61    questions: List[Question] = field(default_factory=list)62    unlocked: bool = True63    completed: bool = False         # True only after user finishes the quest64 65    def has_questions(self) -> bool:66        return len(self.questions) > 067 68    def total_questions(self) -> int:69        return len(self.questions)70