M1: FastAPI 分层后端(judge.engine hydro/judge0 + AI 多厂商) + 前端工作台(真实API/速查表/公式小课堂)

这个提交包含在:
langxm
2026-10-13 17:30:47 +08:00
当前提交 b5aebf6100
共修改 38 个文件,包含 3297 行新增和 0 行删除
+49
查看文件
@@ -0,0 +1,49 @@
"""题目元数据:本地目录 + 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,
}