File size: 2,715 Bytes
7c6ffa6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | from __future__ import annotations
from datetime import datetime
from typing import TYPE_CHECKING
from sqlalchemy import Boolean, DateTime, Float, ForeignKey, Integer, JSON, String, Text, func
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.core.database import Base
from app.utils.ids import prefixed_id
if TYPE_CHECKING:
from app.models.previous_paper import PreviousPaper
class PreviousQuestion(Base):
__tablename__ = "previous_questions"
id: Mapped[str] = mapped_column(
String(40),
primary_key=True,
default=lambda: prefixed_id("pq"),
)
previous_paper_id: Mapped[str] = mapped_column(
String(40),
ForeignKey("previous_papers.id", ondelete="CASCADE"),
index=True,
nullable=False,
)
question_number: Mapped[str | None] = mapped_column(String(40), nullable=True)
question_text: Mapped[str] = mapped_column(Text, nullable=False)
marks: Mapped[int | None] = mapped_column(Integer, nullable=True)
subject: Mapped[str | None] = mapped_column(String(120), nullable=True)
syllabus: Mapped[str | None] = mapped_column(String(120), nullable=True)
year: Mapped[int | None] = mapped_column(Integer, nullable=True)
chapter: Mapped[str | None] = mapped_column(String(180), nullable=True)
topic: Mapped[str | None] = mapped_column(String(180), nullable=True)
question_type: Mapped[str] = mapped_column(
String(40),
default="unknown",
nullable=False,
)
difficulty: Mapped[str] = mapped_column(
String(40),
default="unknown",
nullable=False,
)
keywords_json: Mapped[list[str]] = mapped_column(JSON, default=list, nullable=False)
# ββ T2: Enhanced PYQ extraction fields ββββββββββββββββββββββββββββββββββ
answer_type: Mapped[str | None] = mapped_column(String(40), nullable=True)
formula_needed: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
diagram_needed: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
extracted_answer_if_available: Mapped[str | None] = mapped_column(Text, nullable=True)
confidence: Mapped[float] = mapped_column(Float, default=0.0, nullable=False)
source_origin: Mapped[str] = mapped_column(
String(30),
default="user_uploaded",
nullable=False,
)
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True),
server_default=func.now(),
nullable=False,
)
previous_paper: Mapped["PreviousPaper"] = relationship(
"PreviousPaper",
back_populates="questions",
)
|