M1: FastAPI 分层后端(judge.engine hydro/judge0 + AI 多厂商) + 前端工作台(真实API/速查表/公式小课堂)
这个提交包含在:
@@ -0,0 +1 @@
|
||||
"""ORM 模型:题目、提交记录、学习进度。"""
|
||||
@@ -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,
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
"""学习进度:今日完成数、连续打卡、目标。"""
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import date, datetime
|
||||
|
||||
from sqlalchemy import Date, DateTime, Integer, String, func
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from app.core.db import Base
|
||||
|
||||
|
||||
class Progress(Base):
|
||||
__tablename__ = "progress"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
uid: Mapped[str] = mapped_column(String(64), index=True)
|
||||
course: Mapped[str] = mapped_column(String(64), index=True, default="ap-csa")
|
||||
# 当日已 AC 题数
|
||||
day_done: Mapped[int] = mapped_column(Integer, default=0)
|
||||
# 当日目标
|
||||
day_goal: Mapped[int] = mapped_column(Integer, default=8)
|
||||
streak_days: Mapped[int] = mapped_column(Integer, default=0)
|
||||
last_ac_date: Mapped[date] = mapped_column(Date, nullable=True)
|
||||
updated_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now(), onupdate=func.now())
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
return {
|
||||
"uid": self.uid,
|
||||
"course": self.course,
|
||||
"day_done": self.day_done,
|
||||
"day_goal": self.day_goal,
|
||||
"streak_days": self.streak_days,
|
||||
"last_ac_date": self.last_ac_date.isoformat() if self.last_ac_date else None,
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
"""提交记录:每次判题落库,前端按 rid 轮询。"""
|
||||
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 Submission(Base):
|
||||
__tablename__ = "submissions"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
# HydroOJ 返回的判题记录 ID
|
||||
rid: Mapped[str] = mapped_column(String(64), unique=True, index=True)
|
||||
hydro_pid: Mapped[str] = mapped_column(String(64), index=True)
|
||||
uid: Mapped[str] = mapped_column(String(64), index=True, default="guest")
|
||||
lang: Mapped[str] = mapped_column(String(16), default="java")
|
||||
code: Mapped[str] = mapped_column(Text)
|
||||
# Hydro status 码:2=AC 3=WA 5=TLE 7=RE 8=CE 0=等待 1=判题中
|
||||
status: Mapped[int] = mapped_column(Integer, default=0)
|
||||
score: Mapped[int] = mapped_column(Integer, default=0)
|
||||
time_ms: Mapped[int] = mapped_column(Integer, default=0)
|
||||
memory_kb: Mapped[int] = mapped_column(Integer, default=0)
|
||||
test_cases: Mapped[str] = mapped_column(Text, default="[]") # JSON
|
||||
judge_texts: Mapped[str] = mapped_column(Text, default="[]")
|
||||
verdict: Mapped[str] = mapped_column(String(16), default="PENDING") # AC/WA/TLE/RE/CE/PENDING
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
|
||||
updated_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now(), onupdate=func.now())
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
import json
|
||||
|
||||
return {
|
||||
"rid": self.rid,
|
||||
"hydro_pid": self.hydro_pid,
|
||||
"lang": self.lang,
|
||||
"code": self.code,
|
||||
"status": self.status,
|
||||
"verdict": self.verdict,
|
||||
"score": self.score,
|
||||
"time_ms": self.time_ms,
|
||||
"memory_kb": self.memory_kb,
|
||||
"test_cases": json.loads(self.test_cases),
|
||||
"judge_texts": json.loads(self.judge_texts),
|
||||
"created_at": self.created_at.isoformat() if self.created_at else None,
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户