mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2024-09-21 00:13:18 +00:00
判题暂时可以跑起来了,真要被自己蠢哭了
This commit is contained in:
parent
92ab7e5fb2
commit
66d3cd3bfe
@ -1 +0,0 @@
|
||||
# coding=utf-8
|
@ -1,2 +0,0 @@
|
||||
# coding=utf-8
|
||||
DB_NAME = "db.sqlite3"
|
@ -30,7 +30,7 @@ class JudgeClient(object):
|
||||
:param test_case_dir: 测试用例文件夹路径
|
||||
:return:返回结果list
|
||||
"""
|
||||
self._language = languages[str(language_code)]
|
||||
self._language = languages[language_code]
|
||||
self._exe_path = exe_path
|
||||
self._max_cpu_time = max_cpu_time
|
||||
self._max_real_time = max_real_time
|
||||
|
@ -32,5 +32,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
|
||||
|
@ -6,14 +6,14 @@ languages = {
|
||||
"name": "c",
|
||||
"src_name": "main.c",
|
||||
"code": 1,
|
||||
"compile_command": "gcc -DONLINE_JUDGE -O2 -w -std=c99 -pipe {src_path} -lm -o {exe_path}main",
|
||||
"compile_command": "gcc -DONLINE_JUDGE -O2 -w -std=c99 {src_path} -lm -o {exe_path}main",
|
||||
"execute_command": "{exe_path}main"
|
||||
},
|
||||
2: {
|
||||
"name": "cpp",
|
||||
"src_name": "main.cpp",
|
||||
"code": 2,
|
||||
"compile_command": "g++ -DONLINE_JUDGE -O2 -w -std=c++11 -pipe {src_path} -lm -o {exe_path}main",
|
||||
"compile_command": "g++ -DONLINE_JUDGE -O2 -w -std=c++11 {src_path} -lm -o {exe_path}main",
|
||||
"execute_command": "{exe_path}main"
|
||||
},
|
||||
3: {
|
||||
|
@ -8,14 +8,8 @@ from client import JudgeClient
|
||||
from language import languages
|
||||
from compiler import compile_
|
||||
from result import result
|
||||
from settings import judger_workspace
|
||||
from settings import judger_workspace, mongodb_config
|
||||
|
||||
import sys
|
||||
import os
|
||||
sys.path.append(os.path.abspath(os.path.dirname(__file__) + '/' + '..'))
|
||||
print sys.path
|
||||
|
||||
from oj import settings
|
||||
|
||||
# 简单的解析命令行参数
|
||||
# 参数有 -solution_id -time_limit -memory_limit -test_case_id
|
||||
@ -26,16 +20,13 @@ time_limit = args[4]
|
||||
memory_limit = args[6]
|
||||
test_case_id = args[8]
|
||||
|
||||
|
||||
mongodb_setting = settings.DATABASES["mongodb"]
|
||||
connection = pymongo.MongoClient(host=mongodb_setting["HOST"], port=mongodb_setting["PORT"])
|
||||
connection = pymongo.MongoClient(host=mongodb_config["host"], port=mongodb_config["port"])
|
||||
collection = connection["oj"]["oj_submission"]
|
||||
|
||||
submission = collection.find_one({"_id": ObjectId(solution_id)})
|
||||
if not submission:
|
||||
exit()
|
||||
|
||||
|
||||
# 将代码写入文件
|
||||
language = languages[submission["language"]]
|
||||
src_path = judger_workspace + "run/" + language["src_name"]
|
||||
@ -47,18 +38,18 @@ f.close()
|
||||
try:
|
||||
exe_path = compile_(language, src_path, judger_workspace + "run/")
|
||||
except Exception as e:
|
||||
print e
|
||||
print [{"result": result["compile_error"]}]
|
||||
print {"result": result["compile_error"]}
|
||||
exit()
|
||||
|
||||
try:
|
||||
client = JudgeClient(language_code=language,
|
||||
client = JudgeClient(language_code=submission["language"],
|
||||
exe_path=exe_path,
|
||||
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) + "/")
|
||||
test_case_dir= judger_workspace + "test_case/" + test_case_id + "/")
|
||||
print client.run()
|
||||
except Exception as e:
|
||||
print e
|
||||
print {"result": result["system_error"]}
|
||||
|
||||
|
||||
|
@ -11,5 +11,12 @@ lrun_uid = 1001
|
||||
# lrun用户组gid
|
||||
lrun_gid = 1002
|
||||
|
||||
#judger工作目录
|
||||
# judger工作目录
|
||||
judger_workspace = "/var/judger/"
|
||||
|
||||
mongodb_config = {
|
||||
"host": "192.168.59.3",
|
||||
"username": "root",
|
||||
"password": "root",
|
||||
"port": 27017
|
||||
}
|
||||
|
@ -1,5 +1,10 @@
|
||||
# coding=utf-8
|
||||
from __future__ import absolute_import
|
||||
from celery import Celery
|
||||
from .settings import redis_config
|
||||
|
||||
app = Celery("judge", broker="redis://localhost:6379/0", include=["judger_controller.tasks"])
|
||||
app = Celery("judge", broker="redis://" +
|
||||
redis_config["host"] + ":" +
|
||||
str(redis_config["port"]) +
|
||||
"/" + str(redis_config["db"]),
|
||||
include=["judger_controller.tasks"])
|
||||
|
6
judger_controller/settings.py
Normal file
6
judger_controller/settings.py
Normal file
@ -0,0 +1,6 @@
|
||||
# coding=utf-8
|
||||
redis_config = {
|
||||
"host": "127.0.0.1",
|
||||
"port": 6379,
|
||||
"db": 0
|
||||
}
|
@ -8,13 +8,13 @@ import subprocess32 as subprocess
|
||||
def judge(solution_id, time_limit, memory_limit, test_case_id):
|
||||
try:
|
||||
subprocess.call("docker run -t -i --privileged --rm=true "
|
||||
"-v /var/test_case/:/var/judger/test_case/ "
|
||||
"-v /Users/virusdefender/Desktop/test_case/:/var/judger/test_case/ "
|
||||
"-v /Users/virusdefender/Desktop/:/var/judger/code/ "
|
||||
"-p 27017:27017 "
|
||||
"judger "
|
||||
"python 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, shell=True)
|
||||
# 如果设置的最长运行时间小于1000毫秒,那么/1000就是0,处理一下这个情况,设置为两秒
|
||||
timeout=(time_limit / 1000 * 3) or 2, shell=True)
|
||||
except subprocess.TimeoutExpired:
|
||||
print "docker timeout"
|
||||
|
@ -7,6 +7,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
# 下面是需要自己修改的
|
||||
LOG_PATH = "LOG/"
|
||||
|
||||
# 注意这是web 服务器访问的地址,判题度武器访问的地址不一定一样,因为可能不在一台机器上
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
@ -24,5 +25,6 @@ DATABASES = {
|
||||
|
||||
DEBUG = True
|
||||
|
||||
TEST_CASE_DIR = "/var/test_case/"
|
||||
# 同理 这是 web 服务器的上传路径
|
||||
TEST_CASE_DIR = "/Users/virusdefender/Desktop/test_case/"
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
require(["jquery", "code_mirror"], function ($, code_mirror) {
|
||||
require(["jquery", "code_mirror", "csrf"], function ($, code_mirror, csrfHeader) {
|
||||
var code_editor = code_mirror($("#code-editor")[0], "text/x-csrc");
|
||||
var language = "1";
|
||||
|
||||
@ -21,7 +21,11 @@ require(["jquery", "code_mirror"], function ($, code_mirror) {
|
||||
$("#submit-code-button").click(function () {
|
||||
show_loading();
|
||||
$.ajax({
|
||||
|
||||
beforeSend: csrfHeader,
|
||||
url: "/api/submission/",
|
||||
method: "post",
|
||||
data: JSON.stringify({problem_id: 2, language: language, code: code_editor.getValue()}),
|
||||
contentType: "application/json"
|
||||
});
|
||||
setTimeout(
|
||||
function () {
|
||||
|
@ -32,6 +32,7 @@ class SubmissionnAPIView(APIView):
|
||||
serializer = CreateSubmissionSerializer(data=request.data)
|
||||
if serializer.is_valid():
|
||||
data = serializer.data
|
||||
# data["language"] = int(data["language"])
|
||||
data["user_id"] = request.user.id
|
||||
data["result"] = result["waiting"]
|
||||
try:
|
||||
|
Loading…
Reference in New Issue
Block a user