修改部分命名风格

This commit is contained in:
virusdefender 2015-08-12 14:56:18 +08:00
parent 88be032a38
commit 2ba1fa5669
4 changed files with 21 additions and 12 deletions

View File

@ -3,9 +3,11 @@ from __future__ import absolute_import
from judge.controller.celery import app
import subprocess32 as subprocess
subprocess.call("ping baidu.com", timeout=5)
@app.task
def judge(source_code, language, test_case_id):
pass
def judge(solution_id, time_limit, memory_limit, test_case_id):
subprocess.call("/usr/bin/docker run -t -i --privileged -v /var/test_case/:/var/judger/test_case/ "
"-v /var/code/:/var/judger/code/ judger python judge/judger/run.py "
"--solution_id %s --time_limit %s --memory_limit %s --test_case_id %s" %
(solution_id, str(time_limit), str(memory_limit), test_case_id),
timeout=(time_limit / 100) * 20)

View File

@ -13,12 +13,12 @@ from settings import judger_workspace
from oj import settings
# 简单的解析命令行参数
# 参数有 -solution_id -max_cpu_time -max_memory -test_case_id
# 获取到的值是['xxx.py', '-solution_id', '1111', '-max_cpu_time', '1000', '-max_memory', '100', '-test_case_id', 'aaaa']
# 参数有 -solution_id -time_limit -memory_limit -test_case_id
# 获取到的值是['xxx.py', '-solution_id', '1111', '-time_limit', '1000', '-memory_limit', '100', '-test_case_id', 'aaaa']
args = sys.argv
solution_id = args[2]
max_cpu_time = args[4]
max_memory = args[6]
time_limit = args[4]
memory_limit = args[6]
test_case_id = args[8]
@ -48,9 +48,9 @@ except Exception as e:
client = JudgeClient(language_code=language,
exe_path=exe_path,
max_cpu_time=1000000,
max_real_time=200000,
max_memory=1000,
max_cpu_time=int(time_limit),
max_real_time=int(time_limit) * 2,
max_memory=int(memory_limit),
test_case_dir="/var/judger/test_case/" + str(test_case_id) + "/")
print client.run()

View File

@ -187,7 +187,7 @@ class TestCaseUploadAPIView(APIView):
return error_response(u"测试用例文件不完整,缺少" + name[0] + ".in")
problem_test_dir = rand_str()
test_case_dir = settings.TEST_CASE_DIR + "test_case/" + problem_test_dir + "/"
test_case_dir = settings.TEST_CASE_DIR + problem_test_dir + "/"
# 得到了合法的测试用例文件列表 然后去解压缩
os.mkdir(test_case_dir)

View File

@ -9,7 +9,9 @@ from rest_framework.views import APIView
from django.conf import settings
from judge.judger.result import result
from judge.controller.tasks import judge
from account.decorators import login_required
from problem.models import Problem
from utils.shortcuts import serializer_invalid_response, error_response, success_response
from .serializers import CreateSubmissionSerializer
@ -32,10 +34,15 @@ class SubmissionnAPIView(APIView):
data = serializer.data
data["user_id"] = request.user.id
data["result"] = result["waiting"]
try:
problem = Problem.objects.get(id=data["problem_id"])
except Problem.DoesNotExist:
return error_response(u"题目不存在")
mongodb_setting = settings.DATABASES["mongodb"]
connection = pymongo.MongoClient(host=mongodb_setting["HOST"], port=mongodb_setting["PORT"])
collection = connection["oj"]["oj_submission"]
submission_id = str(collection.insert_one(data).inserted_id)
judge.deply(submission_id, problem.max_cpu_time, problem_)
return success_response({"submission_id": submission_id})
else:
return serializer_invalid_response(serializer)