您的位置:首页 > 其它

在线云评测系统日志(十):获取输入文件的评测数据进行程序评测

2017-06-23 11:34 281 查看
获取评测数据的个数

def get_data_count(problem_id):
'''获得测试数据的个数信息'''
full_path = os.path.join(config.data_dir, str(problem_id))
try:
files = os.listdir(full_path)
except OSError as e:
logging.error(e)
return 0
count = 0
for item in files:
if item.endswith(".in") and item.startswith("data"):
count += 1
return count


运行程序,把结果输出到一个临时的输出文件中

def judge_one_mem_time(
solution_id, problem_id, data_num, time_limit, mem_limit, language):
low_level()
'''评测一组数据'''
input_path = os.path.join(
config.data_dir, str(problem_id), 'data%s.in' %
data_num)
try:
input_data = file(input_path)
except:
return False
output_path = os.path.join(
config.work_dir, str(solution_id), 'out%s.txt' %
data_num)
temp_out_data = file(output_path, 'w')
if language == 'java':
cmd = 'java -cp %s Main' % (
os.path.join(config.work_dir,
str(solution_id)))
main_exe = shlex.split(cmd)
logging.info(main_exe)
elif language == 'python2':
cmd = 'python %s' % (
os.path.join(config.work_dir,
str(solution_id),
'main.pyc'))
main_exe = shlex.split(cmd)
elif language == 'python3':
cmd = 'python3 %s' % (
os.path.join(config.work_dir,
str(solution_id),
'__pycache__/main.cpython-33.pyc'))
main_exe = shlex.split(cmd)
elif language == 'lua':
cmd = "lua %s" % (
os.path.join(config.work_dir,
str(solution_id),
"main"))
main_exe = shlex.split(cmd)
elif language == "ruby":
cmd = "ruby %s" % (
os.path.join(config.work_dir,
str(solution_id),
"main.rb"))
main_exe = shlex.split(cmd)
elif language == "perl":
cmd = "perl %s" % (
os.path.join(config.work_dir,
str(solution_id),
"main.pl"))
main_exe = shlex.split(cmd)
else:
main_exe = [os.path.join(config.work_dir, str(solution_id), 'main'), ]
runcfg = {
'args': main_exe,
'fd_in': input_data.fileno(),
'fd_out': temp_out_data.fileno(),
'timelimit': time_limit, # in MS
'memorylimit': mem_limit, # in KB
}
low_level()
rst = lorun.run(runcfg)
logging.info("the lorun result is : "+str(rst))
input_data.close()
temp_out_data.close()
logging.debug(rst)
return rst
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐