Files
AI-Testing/backend/app/models.py
2026-04-18 20:20:38 +08:00

49 lines
2.2 KiB
Python

from datetime import datetime
from sqlalchemy import Date, DateTime, Float, Integer, String, Text
from sqlalchemy.orm import Mapped, mapped_column
from .database import Base
class Resource(Base):
__tablename__ = "resources"
id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True)
title: Mapped[str] = mapped_column(String(255), nullable=False)
resource_type: Mapped[str] = mapped_column(String(20), nullable=False) # link/file
url: Mapped[str | None] = mapped_column(String(1024), nullable=True)
file_name: Mapped[str | None] = mapped_column(String(255), nullable=True)
category: Mapped[str] = mapped_column(String(50), nullable=False)
tags: Mapped[str | None] = mapped_column(String(255), nullable=True)
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
class Mistake(Base):
__tablename__ = "mistakes"
id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True)
title: Mapped[str] = mapped_column(String(255), nullable=False)
image_url: Mapped[str | None] = mapped_column(String(1024), nullable=True)
category: Mapped[str] = mapped_column(String(50), nullable=False)
difficulty: Mapped[str | None] = mapped_column(String(20), nullable=True) # easy/medium/hard
question_content: Mapped[str | None] = mapped_column(Text, nullable=True)
answer: Mapped[str | None] = mapped_column(Text, nullable=True)
explanation: Mapped[str | None] = mapped_column(Text, nullable=True)
note: Mapped[str | None] = mapped_column(Text, nullable=True)
wrong_count: Mapped[int] = mapped_column(Integer, default=1)
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
class ScoreRecord(Base):
__tablename__ = "score_records"
id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True)
exam_name: Mapped[str] = mapped_column(String(255), nullable=False)
exam_date: Mapped[Date] = mapped_column(Date, nullable=False)
total_score: Mapped[float] = mapped_column(Float, nullable=False)
module_scores: Mapped[str | None] = mapped_column(
String(255), nullable=True
) # JSON string for simplicity
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)