-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
79 lines (64 loc) · 3.24 KB
/
models.py
File metadata and controls
79 lines (64 loc) · 3.24 KB
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
71
72
73
74
75
76
77
78
79
from pydantic import BaseModel, Field, validator
from typing import Optional, List, Dict, Any
import time
from dataclasses import dataclass, field
class LimitObject(BaseModel):
"""資源限制設定"""
time_limit_sec: float = Field(2.0, description="CPU 時間限制 (秒)", gt=0, le=60)
wall_time_limit_sec: float = Field(5.0, description="牆上時鐘限制 (秒)", gt=0, le=120)
memory_limit_kb: int = Field(131072, description="記憶體限制 (KB)", gt=0, le=1048576)
stack_limit_kb: int = Field(65536, description="堆疊大小限制 (KB)", gt=0, le=1048576)
file_size_limit_kb: int = Field(1024, description="檔案大小限制 (KB)", gt=0, le=1048576)
process_limit: int = Field(60, description="行程數量限制", gt=0, le=200)
class SubmissionRequest(BaseModel):
"""提交評測請求模型"""
submission_id: str = Field(..., description="唯一的提交 ID (UUID)")
code: str = Field(..., description="程式碼內容 (Base64 或純文字,視實作而定,這裡假設是純文字或透過 multipart 上傳)")
language: str = Field(..., description="程式語言 (c, cpp, python, java, go)")
is_contest: bool = Field(False, description="是否為比賽提交 (高優先級)")
priority: int = Field(10, description="優先級 (數值越小優先級越高,預設一般為 10,比賽為 1)")
# 資源限制與編譯選項
limits: LimitObject = Field(..., description="資源限制設定")
compile_options: Optional[Dict[str, Any]] = Field(default_factory=dict, description="客製化編譯參數")
# 回調設定
callback_url: Optional[str] = Field(None, description="評測完成後的 Webhook URL")
callback_token: Optional[str] = Field(None, description="Webhook 驗證 Token (Optional)")
@validator('priority', always=True)
def set_priority(cls, v, values):
# 如果 is_contest 為 True,強制設定高優先級 (例如 1)
if values.get('is_contest'):
return 1
return v
@dataclass
class Job:
submission_id: str
language: str
priority: int
timestamp: float
request_data: SubmissionRequest
# New Fields
problem_id: str
mode: str # "zip" | "normal" | "package" | "selftest"
file_path: str # Path to the saved file (binary or zip)
file_hash: str
problem_hash: str = "" # 題目包 Hash
use_checker: bool = False
checker_file_path: Optional[str] = None
use_static_analysis: bool = False
static_analysis_config: Optional[str] = None
stdin: Optional[str] = None # Input for the program
expected_output: Optional[str] = None # Expected output for verification
# Network Security
allow_network: bool = False
network_whitelist: List[str] = field(default_factory=list)
# Sidecar Service
sidecar_image: Optional[str] = None
# Selftest flag (for custom test callback)
is_selftest: bool = False
def __lt__(self, other):
# Priority Queue comparison:
# 1. Lower priority number = Higher priority
# 2. If priority same, Earlier timestamp = Higher priority (FIFO)
if self.priority != other.priority:
return self.priority < other.priority
return self.timestamp < other.timestamp