增加了题目的 model 修改几个 typo

This commit is contained in:
virusdefender 2015-07-17 11:00:15 +08:00
parent dd7fe6ee44
commit 3ee4b57802
6 changed files with 61 additions and 17 deletions

View File

@ -36,3 +36,11 @@ class UserRegisterView(APIView):
def post(self, request): def post(self, request):
pass pass
class UserChangePasswordView(APIView):
def get(self, request):
pass
def post(self, request):
pass

View File

@ -4,5 +4,9 @@ from django.db import models
from problem.models import AbstractProblem from problem.models import AbstractProblem
class ContestProblem(AbstractProblem): class Contest(models.Model):
pass pass
class ContestProblem(AbstractProblem):
contest = models.ForeignKey(Contest)

View File

@ -8,7 +8,7 @@ from settings import max_running_number, lrun_gid, lrun_uid, judger_workspace
from language import languages from language import languages
from result import result from result import result
from compiler import compile_ from compiler import compile_
from judge_exceptions import JudgeClientException, CompileError from judge_exceptions import JudgeClientError, CompileError
from utils import parse_lrun_output from utils import parse_lrun_output
@ -47,9 +47,9 @@ class JudgeClient(object):
f = open(self._test_case_dir + "info") f = open(self._test_case_dir + "info")
return json.loads(f.read()) return json.loads(f.read())
except IOError: except IOError:
raise JudgeClientException("Test case config file not found") raise JudgeClientError("Test case config file not found")
except ValueError: 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): def _generate_command(self, test_case_id):
""" """
@ -82,7 +82,7 @@ class JudgeClient(object):
# 倒序找到MEMORY的位置 # 倒序找到MEMORY的位置
output_start = output.rfind("MEMORY") output_start = output.rfind("MEMORY")
if output_start == -1: if output_start == -1:
raise JudgeClientException("Lrun result parse error") raise JudgeClientError("Lrun result parse error")
# 如果不是0说明lrun输出前面有输出也就是程序的stderr有内容 # 如果不是0说明lrun输出前面有输出也就是程序的stderr有内容
if output_start != 0: if output_start != 0:
error = output[0:output_start] error = output[0:output_start]
@ -118,7 +118,7 @@ class JudgeClient(object):
command = self._generate_command(test_case_id) command = self._generate_command(test_case_id)
status_code, output = commands.getstatusoutput(command) status_code, output = commands.getstatusoutput(command)
if status_code: if status_code:
raise JudgeClientException(output) raise JudgeClientError(output)
error, run_result = self._parse_lrun_output(output) error, run_result = self._parse_lrun_output(output)
run_result["test_case_id"] = test_case_id run_result["test_case_id"] = test_case_id
@ -135,7 +135,7 @@ class JudgeClient(object):
elif run_result["exceed"] in ["cpu_time", "real_time"]: elif run_result["exceed"] in ["cpu_time", "real_time"]:
run_result["result"] = result["time_limit_exceeded"] run_result["result"] = result["time_limit_exceeded"]
else: else:
raise JudgeClientException("Error exceeded type: " + run_result["exceed"]) raise JudgeClientError("Error exceeded type: " + run_result["exceed"])
return run_result return run_result
# 下面就是代码正常运行了 需要判断代码的输出是否正确 # 下面就是代码正常运行了 需要判断代码的输出是否正确

View File

@ -2,7 +2,7 @@
import commands import commands
from settings import lrun_uid, lrun_gid from settings import lrun_uid, lrun_gid
from judge_exceptions import CompileError from judge_exceptions import CompileError, JudgeClientError
from utils import parse_lrun_output from utils import parse_lrun_output
@ -22,7 +22,7 @@ def compile_(language_item, src_path, exe_path):
output_start = output.rfind("MEMORY") output_start = output.rfind("MEMORY")
if output_start == -1: if output_start == -1:
raise CompileError("Error running compiler in lrun") raise JudgeClientError("Error running compiler in lrun")
# 返回值不为0 或者 stderr中lrun的输出之前有东西 # 返回值不为0 或者 stderr中lrun的输出之前有东西
if status or output_start: 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"]: if parse_result["exit_code"] or parse_result["term_sig"] or parse_result["siginaled"] or parse_result["exceed"]:
raise CompileError("Compile error") raise CompileError("Compile error")
# 对于正常编译和超时等其他的错误
return exe_path return exe_path

View File

@ -1,9 +1,9 @@
# coding=utf-8 # coding=utf-8
class JudgeClientException(Exception): class JudgeClientError(Exception):
pass pass
class CompileError(Exception): class CompileError(Exception):
pass pass

View File

@ -4,7 +4,45 @@ from django.db import models
from account.models import User from account.models import User
class ProblemTag(models.Model):
pass
class AbstractProblem(models.Model): 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: class Meta:
abstract = True abstract = True
@ -12,8 +50,3 @@ class AbstractProblem(models.Model):
class Problem(AbstractProblem): class Problem(AbstractProblem):
pass pass
class Solution(models.Model):
user = models.ForeignKey(User)
problem = models.ForeignKey(Problem)