文件

50 行
2.1 KiB
Python

此文件含有模棱两可的 Unicode 字符
此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。
"""题目元数据:本地目录 + HydroOJ 判题 ID 关联。"""
from __future__ import annotations
from datetime import datetime
from sqlalchemy import DateTime, Integer, String, Text, func
from sqlalchemy.orm import Mapped, mapped_column
from app.core.db import Base
class Problem(Base):
__tablename__ = "problems"
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
# HydroOJ 题目 ID(如 P1021 / p1021)
hydro_pid: Mapped[str] = mapped_column(String(64), unique=True, index=True)
title: Mapped[str] = mapped_column(String(200))
course: Mapped[str] = mapped_column(String(64), index=True, default="ap-csa") # ap-calc/ap-phys/ap-chem/ap-bio...
unit: Mapped[str] = mapped_column(String(64), default="")
difficulty: Mapped[int] = mapped_column(Integer, default=1)
lang: Mapped[str] = mapped_column(String(16), default="java")
# 题干 Markdown(可含 LaTeX)
statement_md: Mapped[str] = mapped_column(Text, default="")
# 选择题配置(JSON 字符串;无则纯编程题)
quiz_json: Mapped[str] = mapped_column(Text, default="")
# 该题涉及的核心考点(逗号分隔),用于 AI 讲解与路径自适应
tags: Mapped[str] = mapped_column(String(255), default="")
latex_explain: Mapped[str] = mapped_column(Text, default="") # 题干公式用法解释(可空)
sort_order: Mapped[int] = mapped_column(Integer, default=0)
created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
def to_dict(self) -> dict:
import json
return {
"id": self.id,
"hydro_pid": self.hydro_pid,
"title": self.title,
"course": self.course,
"unit": self.unit,
"difficulty": self.difficulty,
"lang": self.lang,
"statement_md": self.statement_md,
"quiz": json.loads(self.quiz_json) if self.quiz_json else None,
"tags": [t.strip() for t in self.tags.split(",") if t.strip()],
"latex_explain": self.latex_explain,
"sort_order": self.sort_order,
}