Initial commit
This commit is contained in:
69
backend/app/models.py
Normal file
69
backend/app/models.py
Normal file
@@ -0,0 +1,69 @@
|
||||
from datetime import datetime
|
||||
from sqlalchemy import DateTime, Float, ForeignKey, Integer, String, Text, UniqueConstraint
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
from .database import Base
|
||||
|
||||
|
||||
class Student(Base):
|
||||
__tablename__ = "students"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True)
|
||||
first_name: Mapped[str] = mapped_column(String(100))
|
||||
age: Mapped[int] = mapped_column(Integer)
|
||||
grade: Mapped[str] = mapped_column(String(50))
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
||||
|
||||
messages = relationship("Message", back_populates="student", cascade="all, delete-orphan")
|
||||
mastery = relationship("StudentSkillMastery", back_populates="student", cascade="all, delete-orphan")
|
||||
|
||||
|
||||
class Message(Base):
|
||||
__tablename__ = "messages"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
||||
student_id: Mapped[int] = mapped_column(ForeignKey("students.id"), index=True)
|
||||
role: Mapped[str] = mapped_column(String(20))
|
||||
content: Mapped[str] = mapped_column(Text)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
||||
|
||||
student = relationship("Student", back_populates="messages")
|
||||
|
||||
|
||||
class Skill(Base):
|
||||
__tablename__ = "skills"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
||||
code: Mapped[str] = mapped_column(String(100), unique=True)
|
||||
subject: Mapped[str] = mapped_column(String(50))
|
||||
label: Mapped[str] = mapped_column(String(255))
|
||||
description: Mapped[str] = mapped_column(Text)
|
||||
|
||||
|
||||
class StudentSkillMastery(Base):
|
||||
__tablename__ = "student_skill_mastery"
|
||||
__table_args__ = (UniqueConstraint("student_id", "skill_id", name="uq_student_skill"),)
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
||||
student_id: Mapped[int] = mapped_column(ForeignKey("students.id"), index=True)
|
||||
skill_id: Mapped[int] = mapped_column(ForeignKey("skills.id"), index=True)
|
||||
mastery_score: Mapped[float] = mapped_column(Float, default=50.0)
|
||||
confidence: Mapped[float] = mapped_column(Float, default=0.2)
|
||||
evidence_count: Mapped[int] = mapped_column(Integer, default=0)
|
||||
updated_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
|
||||
student = relationship("Student", back_populates="mastery")
|
||||
skill = relationship("Skill")
|
||||
|
||||
|
||||
class AssessmentAttempt(Base):
|
||||
__tablename__ = "assessment_attempts"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
||||
student_id: Mapped[int] = mapped_column(ForeignKey("students.id"), index=True)
|
||||
skill_code: Mapped[str] = mapped_column(String(100), index=True)
|
||||
question: Mapped[str] = mapped_column(Text)
|
||||
expected_answer: Mapped[str] = mapped_column(Text)
|
||||
student_answer: Mapped[str] = mapped_column(Text)
|
||||
is_correct: Mapped[int] = mapped_column(Integer)
|
||||
feedback: Mapped[str] = mapped_column(Text)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
||||
Reference in New Issue
Block a user