修改判题设置;增加web 和 mongodb 数据库的操作

This commit is contained in:
virusdefender
2015-08-12 14:01:34 +08:00
parent 8979def927
commit 88be032a38
19 changed files with 127 additions and 46 deletions

3
judge/README.md Normal file
View File

@@ -0,0 +1,3 @@
/usr/bin/docker run -t -i --privileged -v /var/test_case/:/var/judger/test_case/ -v /var/code/:/var/judger/code/ judger /bin/bash
python judge/judger/run.py -solution_id 1 -max_cpu_time 1 -max_memory 1 -test_case_id 1

View File

@@ -2,21 +2,21 @@
languages = {
"1": {
1: {
"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",
"execute_command": "{exe_path}main"
},
"2": {
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",
"execute_command": "{exe_path}main"
},
"3": {
3: {
"name": "java",
"src_name": "Main.java",
"code": 3,

View File

@@ -1,12 +1,17 @@
# coding=utf-8
import sys
import pymongo
from bson.objectid import ObjectId
from client import JudgeClient
from language import languages
from compiler import compile_
from result import result
from settings import judger_workspace
from oj import settings
judger_workspace = "/var/judger/run/"
# 简单的解析命令行参数
# 参数有 -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']
@@ -16,37 +21,37 @@ max_cpu_time = args[4]
max_memory = args[6]
test_case_id = args[8]
# todo 去数据库查一下
language_code = 1
source_string = """
#include <stdio.h>
int main()
{
int a, b;
scanf("%d %d", &a, &b);
printf("%d", a + b);
return 0;
}
"""
language = languages[str(language_code)]
src_path = judger_workspace + language["src_name"]
mongodb_setting = settings.DATABASES["mongodb"]
connection = pymongo.MongoClient(host=mongodb_setting["HOST"], port=mongodb_setting["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"]
f = open(src_path, "w")
f.write(source_string)
f.write(submission["code"])
f.close()
# 编译
try:
exe_path = compile_(languages[str(language_code)], src_path, judger_workspace)
exe_path = compile_(language, src_path, judger_workspace + "run/")
except Exception as e:
print e
print [{"result": result["compile_error"]}]
exit()
client = JudgeClient(language_code=language_code,
client = JudgeClient(language_code=language,
exe_path=exe_path,
max_cpu_time=1000000,
max_real_time=200000,
max_memory=1000,
test_case_dir="/var/test_cases/1/")
test_case_dir="/var/judger/test_case/" + str(test_case_id) + "/")
print client.run()