Show More
Commit Description:
handle the case when problem id or submission id is null. Grader will simply skip such request. Add more report on console (for command line grading)...
Commit Description:
handle the case when problem id or submission id is null. Grader will simply skip such request. Add more report on console (for command line grading)
(mercurial grafted from d233105d3965c5368c9b33125f390e39b25f910e)
References:
File last commit:
Show/Diff file:
Action:
grader_id
| 91 lines
| 2.3 KiB
| text/plain
| TextLexer
|
|
r137 | #!/usr/bin/env ruby | ||
|
r15 | |||
|
r102 | require 'fileutils' | ||
|
r15 | def talk(str) | ||
if TALKATIVE | ||||
puts str | ||||
end | ||||
end | ||||
def save_source(submission,dir,fname) | ||||
f = File.open("#{dir}/#{fname}","w") | ||||
f.write(submission.source) | ||||
f.close | ||||
end | ||||
def call_judge(problem_home,language,problem_out_dir,fname) | ||||
ENV['PROBLEM_HOME'] = problem_home | ||||
Dir.chdir problem_out_dir | ||||
cmd = "#{problem_home}/script/judge #{language} #{fname}" | ||||
# puts "CMD: #{cmd}" | ||||
system(cmd) | ||||
end | ||||
def read_result(test_result_dir) | ||||
cmp_msg_fname = "#{test_result_dir}/compiler_message" | ||||
cmp_msg = File.open(cmp_msg_fname).read | ||||
result_fname = "#{test_result_dir}/result" | ||||
comment_fname = "#{test_result_dir}/comment" | ||||
if FileTest.exist?(result_fname) | ||||
result = File.open(result_fname).readline.to_i | ||||
comment = File.open(comment_fname).readline.chomp | ||||
return {:points => result, | ||||
:comment => comment, | ||||
:cmp_msg => cmp_msg} | ||||
else | ||||
return {:points => 0, | ||||
:comment => 'compile error', | ||||
:cmp_msg => cmp_msg} | ||||
end | ||||
end | ||||
def save_result(submission,result) | ||||
submission.graded_at = Time.now | ||||
submission.points = result[:points] | ||||
submission.grader_comment = report_comment(result[:comment]) | ||||
submission.compiler_message = result[:cmp_msg] | ||||
submission.save | ||||
end | ||||
def grade(submission_id) | ||||
sub = Submission.find(submission_id) | ||||
user = sub.user | ||||
problem = sub.problem | ||||
language = sub.language.name | ||||
lang_ext = sub.language.ext | ||||
# FIX THIS | ||||
talk 'some hack on language' | ||||
if language == 'cpp' | ||||
language = 'c++' | ||||
end | ||||
user_dir = "#{USER_RESULT_DIR}/#{user.login}" | ||||
Dir.mkdir(user_dir) if !FileTest.exist?(user_dir) | ||||
problem_out_dir = "#{user_dir}/#{problem.name}" | ||||
Dir.mkdir(problem_out_dir) if !FileTest.exist?(problem_out_dir) | ||||
problem_home = "#{PROBLEMS_DIR}/#{problem.name}" | ||||
source_name = "#{problem.name}.#{lang_ext}" | ||||
save_source(sub,problem_out_dir,source_name) | ||||
call_judge(problem_home,language,problem_out_dir,source_name) | ||||
save_result(sub,read_result("#{problem_out_dir}/test-result")) | ||||
end | ||||
# reading environment and options | ||||
GRADER_ENV = 'exam' | ||||
puts "environment: #{GRADER_ENV}" | ||||
require File.dirname(__FILE__) + "/environment.rb" | ||||
#main program | ||||
talk 'Reading rails environment' | ||||
RAILS_ENV = 'development' | ||||
require RAILS_APP_DIR + '/config/environment' | ||||
|
r102 | current_dir = FileUtils.pwd | ||
|
r15 | grade(ARGV[0].to_i) | ||