"""提交记录:每次判题落库,前端按 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, }