Show More
Commit Description:
fix run of php
Commit Description:
fix run of php
References:
File last commit:
Show/Diff file:
Action:
std-script/grade
| 133 lines
| 3.5 KiB
| text/plain
| TextLexer
|
|
r137 | #!/usr/bin/env ruby | ||
|
r0 | |||
|
r31 | CORRECT_MARK = 'P' | ||
INCORRECT_MARK = '-' | ||||
TIMEOUT_MARK = 'T' | ||||
RUN_ERROR_MARK = 'x' | ||||
|
r22 | def log(str='') | ||
if ENV['TALKATIVE']!=nil | ||||
puts str | ||||
end | ||||
if ENV['GRADER_LOGGING']!=nil | ||||
log_fname = ENV['GRADER_LOGGING'] | ||||
fp = File.open(log_fname,"a") | ||||
fp.puts("grade: #{Time.new.strftime("%H:%M")} #{str}") | ||||
fp.close | ||||
end | ||||
end | ||||
|
r0 | def char_comment(comment) | ||
|
r40 | if comment =~ /[Ii]ncorrect/ | ||
|
r31 | INCORRECT_MARK | ||
|
r0 | elsif comment =~ /[Cc]orrect/ | ||
|
r31 | CORRECT_MARK | ||
|
r0 | elsif comment =~ /[Tt]ime/ | ||
|
r31 | TIMEOUT_MARK | ||
|
r40 | elsif res = /^[Cc]omment:(.*)$/.match(comment) | ||
res[1] | ||||
|
r0 | else | ||
|
r31 | RUN_ERROR_MARK # these are run time errors | ||
|
r0 | end | ||
end | ||||
r160 | def extract_time(t) | |||
r165 | #puts "TIME: #{t}" | |||
r164 | if (result=/^(.*)r(.*)u(.*)s(.*)kbytes/.match(t)) | |||
r160 | {:real => result[1], :user => result[2], :sys => result[3], :mem => result[4]} | |||
else | ||||
#{:real => 0, :user => 0, :sys => 0} | ||||
#puts "ERROR READING RUNNING TIME: #{t}" | ||||
raise "Error reading running time: #{t}" | ||||
end | ||||
end | ||||
|
r0 | problem_home = ENV['PROBLEM_HOME'] | ||
require "#{problem_home}/script/test_dsl.rb" | ||||
load "#{problem_home}/test_cases/all_tests.cfg" | ||||
problem = Problem.get_instance | ||||
if problem.well_formed? == false | ||||
|
r22 | log "The problem specification is not well formed." | ||
|
r0 | exit(127) | ||
end | ||||
all_score = 0 | ||||
all_comment = '' | ||||
r160 | peak_memory = -1 | |||
max_runtime = -1 | ||||
|
r0 | (1..(problem.runs.length-1)).each do |k| | ||
|
r22 | log "grade run #{k}" | ||
|
r0 | run = problem.runs[k] | ||
|
r66 | run_score = nil | ||
|
r0 | run_comment = '' | ||
|
r8 | run_comment_short = '' | ||
|
r0 | run.tests.each do |test_num| | ||
result_file_name = "#{test_num}/result" | ||||
if not File.exists?(result_file_name) | ||||
|
r30 | run_comment += "result file for test #{test_num} not found\n" | ||
|
r31 | run_comment_short += RUN_ERROR_MARK | ||
|
r22 | log "Cannot find the file #{test_num}/result!" | ||
|
r30 | else | ||
result_file = File.new(result_file_name, "r") | ||||
result_file_lines = result_file.readlines | ||||
r160 | if result_file_lines.length>=3 | |||
|
r66 | current_run_score = result_file_lines[1].to_i | ||
|
r34 | run_comment += result_file_lines[0] | ||
|
r40 | run_comment_short += char_comment(result_file_lines[0].chomp) | ||
r160 | ||||
#update max runtime & memory | ||||
run_stat = extract_time result_file_lines[2] | ||||
peak_memory = [peak_memory,run_stat[:mem].to_i].max | ||||
max_runtime = [max_runtime,run_stat[:user].to_f + run_stat[:sys].to_f].max | ||||
|
r34 | else | ||
|
r66 | current_run_score = 0 | ||
|
r34 | run_comment += "result file for test #{test_num} error\n" | ||
run_comment_short += RUN_ERROR_MARK | ||||
log "Error in #{test_num}/result!" | ||||
end | ||||
|
r66 | |||
# the score of this run should be the minimum of the score for | ||||
# each test case | ||||
if (run_score==nil) or (run_score>current_run_score) | ||||
run_score = current_run_score | ||||
end | ||||
|
r30 | result_file.close | ||
|
r0 | end | ||
end | ||||
|
r32 | |||
|
r0 | run_result_file = File.new("result-#{k}", "w") | ||
run_result_file.write run_score | ||||
run_result_file.write "\n" | ||||
run_result_file.close | ||||
run_comment_file = File.new("comment-#{k}", "w") | ||||
run_comment_file.write "#{run_comment}\n" | ||||
run_comment_file.close | ||||
all_score = all_score + run_score | ||||
|
r32 | |||
# append comment for test run with many test cases | ||||
if run.tests.length > 1 | ||||
run_comment_short = '[' + run_comment_short + ']' | ||||
end | ||||
|
r8 | all_comment += run_comment_short | ||
|
r0 | end | ||
result_file = File.new("result", "w") | ||||
result_file.write all_score | ||||
result_file.write "\n" | ||||
result_file.close | ||||
comment_file = File.new("comment", "w") | ||||
comment_file.write "#{all_comment}\n" | ||||
comment_file.close | ||||
r157 | ||||
r160 | ||||
File.open("run_stat","w") do |file| | ||||
file.puts max_runtime | ||||
file.puts peak_memory | ||||
end | ||||
log "score = #{all_score}\ncomment = #{all_comment}" | ||||
log "max_runtime = #{max_runtime}\npeak_memory = #{peak_memory}" | ||||