Skip to content

Commit

Permalink
feat(online_judge)!: 将OJ相关配置从ccf_parser移动到online_judge内
Browse files Browse the repository at this point in the history
  • Loading branch information
XYCode-Kerman committed Apr 15, 2024
1 parent 8e6d02b commit 2623008
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 32 deletions.
1 change: 0 additions & 1 deletion ccf_parser/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from ccf_parser.base import CCF, CCFHeader, Contest
from ccf_parser.configs import ContestIndex, ContestIndexList
from ccf_parser.oj import OJConfig
from ccf_parser.problems import CheckPoint, JudgeConfig, Problem
from ccf_parser.results import CheckPointResult, JudgingResult
3 changes: 0 additions & 3 deletions ccf_parser/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from pydantic import BaseModel

from ccf_parser.oj import OJConfig
from ccf_parser.problems import Problem


Expand All @@ -12,8 +11,6 @@ class CCFHeader(BaseModel):
path: pathlib.Path
description: str
contest_type: Literal['OI', 'IOI']
enable_oj: bool
oj_config: Optional[OJConfig] = None


class Contest(BaseModel):
Expand Down
8 changes: 0 additions & 8 deletions ccf_parser/oj.py

This file was deleted.

2 changes: 1 addition & 1 deletion online_judge/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from fastapi.security import APIKeyCookie
from tinydb import Query

from .models.user import User
from .oj_models.user import User
from .utils import usercol

router = APIRouter(prefix='/auth', tags=['用户验证'])
Expand Down
22 changes: 3 additions & 19 deletions online_judge/contests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,11 @@
import fastapi
from fastapi import APIRouter, HTTPException

import ccf_parser
from .oj_models import OJContest

router = APIRouter(prefix='/contests', tags=['比赛'])


@router.get('/', response_model=List[ccf_parser.CCF])
@router.get('/', name='获取注册在 OJ 中的比赛', response_model=List[OJContest])
async def get_contests():
contest_indexes_path = Path('./config/contests.json')
contest_indexes = [
ccf_parser.ContestIndex.model_validate(x)
for x in json.loads(contest_indexes_path.read_text('utf-8'))
]

ccfs: List[ccf_parser.CCF] = [
ccf_parser.CCF.model_validate_json(
x.ccf_file.joinpath('ccf.json').read_text('utf-8'))
for x in contest_indexes
]

# 抹除题目数据
for ccf in ccfs:
ccf.contest.problems = []

return ccfs
pass
2 changes: 2 additions & 0 deletions online_judge/oj_models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .contest import OJContest
from .user import User
21 changes: 21 additions & 0 deletions online_judge/oj_models/contest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from datetime import datetime
from pathlib import Path
from uuid import UUID

from pydantic import BaseModel

from ccf_parser import CCF


class OJContest(BaseModel):
"""有别于 ccf_parser 中的 Contest,更加详细的比赛信息需要从 ccf_parser 中获取"""
contest_id: UUID
ccf_file: Path

start_time: datetime
end_time: datetime

@property
def read_ccf(self) -> CCF:
data = self.ccf_file.read_text('utf-8')
return CCF.model_validate_json(data)
File renamed without changes.

0 comments on commit 2623008

Please sign in to comment.