mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 14:09:29 +08:00
170 lines
4.4 KiB
Python
170 lines
4.4 KiB
Python
from __future__ import annotations
|
|
|
|
import time
|
|
from enum import Enum
|
|
from typing import Any, Literal
|
|
|
|
from pydantic import BaseModel, ConfigDict, Field
|
|
|
|
|
|
class KnowledgeType(str, Enum):
|
|
MEMORY = "记忆型"
|
|
CONCEPT = "概念型"
|
|
PROCEDURE = "程序型"
|
|
DESIGN = "设计型"
|
|
|
|
|
|
class ErrorType(str, Enum):
|
|
KNOWLEDGE_STRUCTURAL = "知识结构性"
|
|
UNDERSTANDING_DEVIATION = "理解偏差型"
|
|
APPLICATION_ERROR = "应用错误"
|
|
METACOGNITIVE = "元认知型"
|
|
|
|
|
|
class MasteryLevel(int, Enum):
|
|
LEVEL_1 = 1
|
|
LEVEL_2 = 2
|
|
LEVEL_3 = 3
|
|
LEVEL_4 = 4
|
|
MASTERED = 5
|
|
|
|
|
|
class LearningStage(str, Enum):
|
|
DIAGNOSTIC_PHASE1 = "diagnostic_phase1"
|
|
DIAGNOSTIC_PHASE2 = "diagnostic_phase2"
|
|
METACOGNITIVE_INTRO = "metacognitive_intro"
|
|
PLAN = "plan"
|
|
PRETEST = "pretest"
|
|
EXPLAIN = "explain"
|
|
FEYNMAN_CHECK = "feynman_check"
|
|
PRACTICE = "practice"
|
|
ERROR_DIAGNOSIS = "error_diagnosis"
|
|
MODULE_TEST = "module_test"
|
|
REVIEW = "review"
|
|
COMPLETED = "completed"
|
|
|
|
|
|
class KnowledgePoint(BaseModel):
|
|
model_config = ConfigDict(extra="ignore")
|
|
|
|
id: str
|
|
name: str
|
|
type: KnowledgeType
|
|
module_id: str
|
|
|
|
|
|
class LearningModule(BaseModel):
|
|
model_config = ConfigDict(extra="ignore")
|
|
|
|
id: str
|
|
name: str
|
|
order: int
|
|
pass_threshold: float = 0.7
|
|
knowledge_points: list[KnowledgePoint] = Field(default_factory=list)
|
|
|
|
|
|
class DiagnosticResult(BaseModel):
|
|
model_config = ConfigDict(extra="ignore")
|
|
|
|
module_mastery: dict[str, float] = Field(default_factory=dict)
|
|
weak_modules: list[str] = Field(default_factory=list)
|
|
skipped_modules: list[str] = Field(default_factory=list)
|
|
inferred_modules: list[str] = Field(default_factory=list)
|
|
total_questions: int = 0
|
|
phase1_result: dict = Field(default_factory=dict)
|
|
phase2_results: dict[str, dict] = Field(default_factory=dict)
|
|
|
|
|
|
class QuizAttempt(BaseModel):
|
|
model_config = ConfigDict(extra="ignore")
|
|
|
|
question_id: str
|
|
knowledge_point_id: str
|
|
module_id: str = ""
|
|
is_correct: bool
|
|
user_answer: Any = None
|
|
error_type: ErrorType | None = None
|
|
self_attribution: str = ""
|
|
mastery_estimate: float = 0.0
|
|
timestamp: float = Field(default_factory=time.time)
|
|
|
|
|
|
class RetryAttempt(BaseModel):
|
|
model_config = ConfigDict(extra="ignore")
|
|
|
|
timestamp: float
|
|
is_correct: bool
|
|
attempt_number: int
|
|
|
|
|
|
class ErrorRecord(BaseModel):
|
|
model_config = ConfigDict(extra="ignore")
|
|
|
|
id: str
|
|
question_id: str
|
|
knowledge_point_id: str
|
|
module_id: str
|
|
error_type: ErrorType
|
|
self_attribution: str = ""
|
|
ai_confirmation: str = ""
|
|
retry_history: list[RetryAttempt] = Field(default_factory=list)
|
|
status: Literal["active", "retrying", "review", "graduated"] = "active"
|
|
created_at: float = Field(default_factory=time.time)
|
|
|
|
|
|
class RepetitionState(BaseModel):
|
|
model_config = ConfigDict(extra="ignore")
|
|
|
|
interval_index: int = 0
|
|
consecutive_correct: int = 0
|
|
consecutive_wrong: int = 0
|
|
next_review_at: float
|
|
|
|
|
|
class ReviewTask(BaseModel):
|
|
model_config = ConfigDict(extra="ignore")
|
|
|
|
id: str
|
|
knowledge_point_id: str
|
|
knowledge_type: KnowledgeType
|
|
due_at: float
|
|
priority: int
|
|
state: RepetitionState
|
|
|
|
|
|
class LearningProgress(BaseModel):
|
|
model_config = ConfigDict(extra="allow")
|
|
|
|
book_id: str
|
|
diagnostic: DiagnosticResult | None = None
|
|
modules: list[LearningModule] = Field(default_factory=list)
|
|
current_module_id: str = ""
|
|
current_stage: LearningStage = LearningStage.DIAGNOSTIC_PHASE1
|
|
current_kp_index: int = 0
|
|
mastery_levels: dict[str, float] = Field(default_factory=dict)
|
|
knowledge_types: dict[str, KnowledgeType] = Field(default_factory=dict)
|
|
error_records: list[ErrorRecord] = Field(default_factory=list)
|
|
repetition_states: dict[str, RepetitionState] = Field(default_factory=dict)
|
|
review_queue: list[ReviewTask] = Field(default_factory=list)
|
|
module_stage: dict[str, LearningStage] = Field(default_factory=dict)
|
|
learning_mode: Literal["mastery", "exam"] = "mastery"
|
|
created_at: float = Field(default_factory=time.time)
|
|
updated_at: float = Field(default_factory=time.time)
|
|
|
|
|
|
__all__ = [
|
|
"KnowledgeType",
|
|
"ErrorType",
|
|
"MasteryLevel",
|
|
"LearningStage",
|
|
"KnowledgePoint",
|
|
"LearningModule",
|
|
"DiagnosticResult",
|
|
"QuizAttempt",
|
|
"RetryAttempt",
|
|
"ErrorRecord",
|
|
"RepetitionState",
|
|
"ReviewTask",
|
|
"LearningProgress",
|
|
]
|