From 3ee4b57802e11619935bf8dca387fe85c7158d4c Mon Sep 17 00:00:00 2001 From: virusdefender <1670873886@qq.com> Date: Fri, 17 Jul 2015 11:00:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E9=A2=98=E7=9B=AE?= =?UTF-8?q?=E7=9A=84=20model=20=E4=BF=AE=E6=94=B9=E5=87=A0=E4=B8=AA=20typo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- account/views.py | 8 ++++++++ contest/models.py | 6 +++++- judge/client.py | 12 +++++------ judge/compiler.py | 5 ++--- judge/judge_exceptions.py | 4 ++-- problem/models.py | 43 ++++++++++++++++++++++++++++++++++----- 6 files changed, 61 insertions(+), 17 deletions(-) diff --git a/account/views.py b/account/views.py index 32b77c92..8c973204 100644 --- a/account/views.py +++ b/account/views.py @@ -36,3 +36,11 @@ class UserRegisterView(APIView): def post(self, request): pass + + +class UserChangePasswordView(APIView): + def get(self, request): + pass + + def post(self, request): + pass \ No newline at end of file diff --git a/contest/models.py b/contest/models.py index 1088232c..aeb98005 100644 --- a/contest/models.py +++ b/contest/models.py @@ -4,5 +4,9 @@ from django.db import models from problem.models import AbstractProblem -class ContestProblem(AbstractProblem): +class Contest(models.Model): pass + + +class ContestProblem(AbstractProblem): + contest = models.ForeignKey(Contest) diff --git a/judge/client.py b/judge/client.py index 34b717fe..cdac0b22 100644 --- a/judge/client.py +++ b/judge/client.py @@ -8,7 +8,7 @@ from settings import max_running_number, lrun_gid, lrun_uid, judger_workspace from language import languages from result import result from compiler import compile_ -from judge_exceptions import JudgeClientException, CompileError +from judge_exceptions import JudgeClientError, CompileError from utils import parse_lrun_output @@ -47,9 +47,9 @@ class JudgeClient(object): f = open(self._test_case_dir + "info") return json.loads(f.read()) except IOError: - raise JudgeClientException("Test case config file not found") + raise JudgeClientError("Test case config file not found") except ValueError: - raise JudgeClientException("Test case config file format error") + raise JudgeClientError("Test case config file format error") def _generate_command(self, test_case_id): """ @@ -82,7 +82,7 @@ class JudgeClient(object): # 倒序找到MEMORY的位置 output_start = output.rfind("MEMORY") if output_start == -1: - raise JudgeClientException("Lrun result parse error") + raise JudgeClientError("Lrun result parse error") # 如果不是0,说明lrun输出前面有输出,也就是程序的stderr有内容 if output_start != 0: error = output[0:output_start] @@ -118,7 +118,7 @@ class JudgeClient(object): command = self._generate_command(test_case_id) status_code, output = commands.getstatusoutput(command) if status_code: - raise JudgeClientException(output) + raise JudgeClientError(output) error, run_result = self._parse_lrun_output(output) run_result["test_case_id"] = test_case_id @@ -135,7 +135,7 @@ class JudgeClient(object): elif run_result["exceed"] in ["cpu_time", "real_time"]: run_result["result"] = result["time_limit_exceeded"] else: - raise JudgeClientException("Error exceeded type: " + run_result["exceed"]) + raise JudgeClientError("Error exceeded type: " + run_result["exceed"]) return run_result # 下面就是代码正常运行了 需要判断代码的输出是否正确 diff --git a/judge/compiler.py b/judge/compiler.py index 69f7bb55..d4bca4bb 100644 --- a/judge/compiler.py +++ b/judge/compiler.py @@ -2,7 +2,7 @@ import commands from settings import lrun_uid, lrun_gid -from judge_exceptions import CompileError +from judge_exceptions import CompileError, JudgeClientError from utils import parse_lrun_output @@ -22,7 +22,7 @@ def compile_(language_item, src_path, exe_path): output_start = output.rfind("MEMORY") if output_start == -1: - raise CompileError("Error running compiler in lrun") + raise JudgeClientError("Error running compiler in lrun") # 返回值不为0 或者 stderr中lrun的输出之前有东西 if status or output_start: @@ -33,5 +33,4 @@ def compile_(language_item, src_path, exe_path): if parse_result["exit_code"] or parse_result["term_sig"] or parse_result["siginaled"] or parse_result["exceed"]: raise CompileError("Compile error") - # 对于正常编译和超时等其他的错误 return exe_path diff --git a/judge/judge_exceptions.py b/judge/judge_exceptions.py index 5d22d950..3a9bc608 100644 --- a/judge/judge_exceptions.py +++ b/judge/judge_exceptions.py @@ -1,9 +1,9 @@ # coding=utf-8 -class JudgeClientException(Exception): +class JudgeClientError(Exception): pass class CompileError(Exception): - pass + pass \ No newline at end of file diff --git a/problem/models.py b/problem/models.py index 584fc24d..53f654e3 100644 --- a/problem/models.py +++ b/problem/models.py @@ -4,7 +4,45 @@ from django.db import models from account.models import User +class ProblemTag(models.Model): + pass + + class AbstractProblem(models.Model): + # 标题 + title = models.CharField(max_length=50) + # 问题描述 HTML 格式 + description = models.TextField() + # 样例输入 可能会存储 json 格式的数据 + sample_input = models.TextField(blank=True) + # 样例输出 同上 + sample_output = models.TextField(blank=True) + # 测试用例id 这个id 可以用来拼接得到测试用例的文件存储位置 + test_case_id = models.CharField(max_length=40) + # 提示 + hint = models.TextField(blank=True) + # 创建时间 + create_time = models.DateTimeField(auth_now_add=True) + # 最后更新时间 + last_update_time = models.DateTimeField(auto_now=True) + # 这个题是谁创建的 + author = models.ForeignKey(User) + # 来源 + source = models.CharField(max_length=30, blank=True) + # 时间限制 单位是毫秒 + time_limit = models.IntegerField() + # 内存限制 单位是MB + memory_limit = models.IntegerField() + # 是否可见 false的话相当于删除 + visible = models.BooleanField(default=True) + # 总共提交数量 + total_submit_number = models.IntegerField(default=0) + # 通过数量 + total_accepted_number = models.IntegerField(default=0) + # 标签 + tags = models.ManyToManyField(ProblemTag, null=True) + # 难度 0 - n + difficulty = models.IntegerField() class Meta: abstract = True @@ -12,8 +50,3 @@ class AbstractProblem(models.Model): class Problem(AbstractProblem): pass - - -class Solution(models.Model): - user = models.ForeignKey(User) - problem = models.ForeignKey(Problem) \ No newline at end of file