在线云评测系统日志(十):获取输入文件的评测数据进行程序评测
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
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
相关文章推荐
- 使用smartUpload组件进行文件上传以及获取文本数据
- 关于使用while(!filePCloud.eof())判断文件结尾进行数据输入装换时注意事项
- 将键盘输入的几个数据存储到文件里的程序
- ajax--将获取到的文件内的数据转化成json格式并使用---输入提示
- 用vs制作安装程序的时候 如何获取用户输入的序列号,并进行判定
- 运行hadoop程序,如何在map中获取输入数据的全路径(fullpath)
- (1) 输入学生的基本信息,计算每个学生的平均分,并将学生信息存入磁盘文件“stud”中; (2) 将文件stud中的数据按平均分从高到低的顺序进行排序,并将排序结果存放到文件“stud_sort”中
- 编写程序,从键盘输入各位职工的工资数据,存入磁盘文件Salary.dat中,然后从该文件读出职工的工资数据,并计算输出每位职工的实发工资。实发工资的计算方法如下:实发工资=基本工资+加班工奖金-扣除
- 面程序的功能是将一个4×4的数组进行逆时针旋转90度后输出,要求原始数组的数据随机输入,原新数组以4行4列的方式输出
- struts2 + ajax(由前台的form提交数据到后台,再根据form所调用返回获取的后台json格式的数据返回到前端,然后前端用jquery对json数据进行解析)==》》涉及文件上传的部分
- 用堆对大文件进行多路归并的在线算法程序
- 微信小程序简单实现form表单获取输入数据功能示例
- 【java IO】使用Java输入输出流 读取txt文件内数据,进行拼接后写入到另一个文件中
- 无废话Android之android下junit测试框架配置、保存文件到手机内存、android下文件访问的权限、保存文件到SD卡、获取SD卡大小、使用SharedPreferences进行数据存储、使用Pull解析器操作XML文件、android下操作sqlite数据库和事务(2)
- 安装程序检测到 HTML 帮助数据文件已损坏,无法继续进行
- 数据读取 ,在cmd dos 命令下输入文件地址 进行测试
- linux之用echo输入数据到文本末尾以及用open ssl命令在证书文件里面获取公钥
- 安装程序检测到 HTML 帮助数据文件已损坏,无法继续进行。单击“确定”可关闭安装程序。
- asp下输入数据转换成htm文件显示
- 获取当前程序文件的路径