Description:
[grader] fixed the case when result file is ill-formatted
git-svn-id: http://theory.cpe.ku.ac.th/grader/judge/trunk/scripts@130 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r34:4907486f53b2 - - 2 files changed: 16 inserted, 6 deleted
@@ -1,111 +1,115 | |||||
|
1 | module Grader |
|
1 | module Grader |
|
2 |
|
2 | ||
|
3 | class SubmissionRoomMaker |
|
3 | class SubmissionRoomMaker |
|
4 | def initialize |
|
4 | def initialize |
|
5 | @config = Grader::Configuration.get_instance |
|
5 | @config = Grader::Configuration.get_instance |
|
6 | end |
|
6 | end |
|
7 |
|
7 | ||
|
8 | def produce_grading_room(submission) |
|
8 | def produce_grading_room(submission) |
|
9 | user = submission.user |
|
9 | user = submission.user |
|
10 | problem = submission.problem |
|
10 | problem = submission.problem |
|
11 | grading_room = "#{@config.user_result_dir}/" + |
|
11 | grading_room = "#{@config.user_result_dir}/" + |
|
12 | "#{user.login}/#{problem.name}/#{submission.id}" |
|
12 | "#{user.login}/#{problem.name}/#{submission.id}" |
|
13 |
|
13 | ||
|
14 | FileUtils.mkdir_p(grading_room) |
|
14 | FileUtils.mkdir_p(grading_room) |
|
15 | grading_room |
|
15 | grading_room |
|
16 | end |
|
16 | end |
|
17 |
|
17 | ||
|
18 | def find_problem_home(submission) |
|
18 | def find_problem_home(submission) |
|
19 | problem = submission.problem |
|
19 | problem = submission.problem |
|
20 | "#{@config.problems_dir}/#{problem.name}" |
|
20 | "#{@config.problems_dir}/#{problem.name}" |
|
21 | end |
|
21 | end |
|
22 |
|
22 | ||
|
23 | def save_source(submission,source_name) |
|
23 | def save_source(submission,source_name) |
|
24 | dir = self.produce_grading_room(submission) |
|
24 | dir = self.produce_grading_room(submission) |
|
25 | f = File.open("#{dir}/#{source_name}","w") |
|
25 | f = File.open("#{dir}/#{source_name}","w") |
|
26 | f.write(submission.source) |
|
26 | f.write(submission.source) |
|
27 | f.close |
|
27 | f.close |
|
28 | end |
|
28 | end |
|
29 |
|
29 | ||
|
30 | def clean_up(submission) |
|
30 | def clean_up(submission) |
|
31 | end |
|
31 | end |
|
32 | end |
|
32 | end |
|
33 |
|
33 | ||
|
34 | class SubmissionReporter |
|
34 | class SubmissionReporter |
|
35 | def initialize |
|
35 | def initialize |
|
36 | @config = Grader::Configuration.get_instance |
|
36 | @config = Grader::Configuration.get_instance |
|
37 | end |
|
37 | end |
|
38 |
|
38 | ||
|
39 | def report(sub,test_result_dir) |
|
39 | def report(sub,test_result_dir) |
|
40 | save_result(sub,read_result(test_result_dir)) |
|
40 | save_result(sub,read_result(test_result_dir)) |
|
41 | end |
|
41 | end |
|
42 |
|
42 | ||
|
43 | def report_error(sub,msg) |
|
43 | def report_error(sub,msg) |
|
44 | save_result(sub,{:points => 0, |
|
44 | save_result(sub,{:points => 0, |
|
45 | :comment => "Grading error: #{msg}" }) |
|
45 | :comment => "Grading error: #{msg}" }) |
|
46 | end |
|
46 | end |
|
47 |
|
47 | ||
|
48 | protected |
|
48 | protected |
|
49 | def read_result(test_result_dir) |
|
49 | def read_result(test_result_dir) |
|
50 | cmp_msg_fname = "#{test_result_dir}/compiler_message" |
|
50 | cmp_msg_fname = "#{test_result_dir}/compiler_message" |
|
51 |
- |
|
51 | + if FileTest.exist?(cmp_msg_fname) |
|
52 | - cmp_msg = cmp_file.read |
|
52 | + cmp_file = File.open(cmp_msg_fname) |
|
53 |
- cmp_file. |
|
53 | + cmp_msg = cmp_file.read |
|
|
54 | + cmp_file.close | ||
|
|
55 | + else | ||
|
|
56 | + cmp_msg = "" | ||
|
|
57 | + end | ||
|
54 |
|
58 | ||
|
55 | result_fname = "#{test_result_dir}/result" |
|
59 | result_fname = "#{test_result_dir}/result" |
|
56 | comment_fname = "#{test_result_dir}/comment" |
|
60 | comment_fname = "#{test_result_dir}/comment" |
|
57 | if FileTest.exist?(result_fname) |
|
61 | if FileTest.exist?(result_fname) |
|
58 | comment = "" |
|
62 | comment = "" |
|
59 | begin |
|
63 | begin |
|
60 | result_file = File.open(result_fname) |
|
64 | result_file = File.open(result_fname) |
|
61 | result = result_file.readline.to_i |
|
65 | result = result_file.readline.to_i |
|
62 | result_file.close |
|
66 | result_file.close |
|
63 | rescue |
|
67 | rescue |
|
64 | result = 0 |
|
68 | result = 0 |
|
65 | comment = "error reading result file." |
|
69 | comment = "error reading result file." |
|
66 | end |
|
70 | end |
|
67 |
|
71 | ||
|
68 | begin |
|
72 | begin |
|
69 | comment_file = File.open(comment_fname) |
|
73 | comment_file = File.open(comment_fname) |
|
70 | comment += comment_file.readline.chomp |
|
74 | comment += comment_file.readline.chomp |
|
71 | comment_file.close |
|
75 | comment_file.close |
|
72 | rescue |
|
76 | rescue |
|
73 | comment += "" |
|
77 | comment += "" |
|
74 | end |
|
78 | end |
|
75 |
|
79 | ||
|
76 | return {:points => result, |
|
80 | return {:points => result, |
|
77 | :comment => comment, |
|
81 | :comment => comment, |
|
78 | :cmp_msg => cmp_msg} |
|
82 | :cmp_msg => cmp_msg} |
|
79 | else |
|
83 | else |
|
80 | if FileTest.exist?("#{test_result_dir}/a.out") |
|
84 | if FileTest.exist?("#{test_result_dir}/a.out") |
|
81 | return {:points => 0, |
|
85 | return {:points => 0, |
|
82 | :comment => 'error during grading', |
|
86 | :comment => 'error during grading', |
|
83 | :cmp_msg => cmp_msg} |
|
87 | :cmp_msg => cmp_msg} |
|
84 | else |
|
88 | else |
|
85 | return {:points => 0, |
|
89 | return {:points => 0, |
|
86 | :comment => 'compile error', |
|
90 | :comment => 'compile error', |
|
87 | :cmp_msg => cmp_msg} |
|
91 | :cmp_msg => cmp_msg} |
|
88 | end |
|
92 | end |
|
89 | end |
|
93 | end |
|
90 | end |
|
94 | end |
|
91 |
|
95 | ||
|
92 | def save_result(submission,result) |
|
96 | def save_result(submission,result) |
|
93 | problem = submission.problem |
|
97 | problem = submission.problem |
|
94 | submission.graded_at = Time.now |
|
98 | submission.graded_at = Time.now |
|
95 | points = result[:points] |
|
99 | points = result[:points] |
|
96 | submission.points = points |
|
100 | submission.points = points |
|
97 | comment = @config.report_comment(result[:comment]) |
|
101 | comment = @config.report_comment(result[:comment]) |
|
98 | if problem == nil |
|
102 | if problem == nil |
|
99 | submission.grader_comment = 'PASSED: ' + comment + '(problem is nil)' |
|
103 | submission.grader_comment = 'PASSED: ' + comment + '(problem is nil)' |
|
100 | elsif points == problem.full_score |
|
104 | elsif points == problem.full_score |
|
101 | submission.grader_comment = 'PASSED: ' + comment |
|
105 | submission.grader_comment = 'PASSED: ' + comment |
|
102 | else |
|
106 | else |
|
103 | submission.grader_comment = 'FAILED: ' + comment |
|
107 | submission.grader_comment = 'FAILED: ' + comment |
|
104 | end |
|
108 | end |
|
105 | submission.compiler_message = result[:cmp_msg] or '' |
|
109 | submission.compiler_message = result[:cmp_msg] or '' |
|
106 | submission.save |
|
110 | submission.save |
|
107 | end |
|
111 | end |
|
108 |
|
112 | ||
|
109 | end |
|
113 | end |
|
110 |
|
114 | ||
|
111 | end |
|
115 | end |
@@ -1,100 +1,106 | |||||
|
1 | #!/usr/bin/ruby |
|
1 | #!/usr/bin/ruby |
|
2 |
|
2 | ||
|
3 | CORRECT_MARK = 'P' |
|
3 | CORRECT_MARK = 'P' |
|
4 | INCORRECT_MARK = '-' |
|
4 | INCORRECT_MARK = '-' |
|
5 | TIMEOUT_MARK = 'T' |
|
5 | TIMEOUT_MARK = 'T' |
|
6 | RUN_ERROR_MARK = 'x' |
|
6 | RUN_ERROR_MARK = 'x' |
|
7 |
|
7 | ||
|
8 | def log(str='') |
|
8 | def log(str='') |
|
9 | if ENV['TALKATIVE']!=nil |
|
9 | if ENV['TALKATIVE']!=nil |
|
10 | puts str |
|
10 | puts str |
|
11 | end |
|
11 | end |
|
12 | if ENV['GRADER_LOGGING']!=nil |
|
12 | if ENV['GRADER_LOGGING']!=nil |
|
13 | log_fname = ENV['GRADER_LOGGING'] |
|
13 | log_fname = ENV['GRADER_LOGGING'] |
|
14 | fp = File.open(log_fname,"a") |
|
14 | fp = File.open(log_fname,"a") |
|
15 | fp.puts("grade: #{Time.new.strftime("%H:%M")} #{str}") |
|
15 | fp.puts("grade: #{Time.new.strftime("%H:%M")} #{str}") |
|
16 | fp.close |
|
16 | fp.close |
|
17 | end |
|
17 | end |
|
18 | end |
|
18 | end |
|
19 |
|
19 | ||
|
20 | def char_comment(comment) |
|
20 | def char_comment(comment) |
|
21 | if comment =~ /[iI]ncorrect/ |
|
21 | if comment =~ /[iI]ncorrect/ |
|
22 | INCORRECT_MARK |
|
22 | INCORRECT_MARK |
|
23 | elsif comment =~ /[Cc]orrect/ |
|
23 | elsif comment =~ /[Cc]orrect/ |
|
24 | CORRECT_MARK |
|
24 | CORRECT_MARK |
|
25 | elsif comment =~ /[Tt]ime/ |
|
25 | elsif comment =~ /[Tt]ime/ |
|
26 | TIMEOUT_MARK |
|
26 | TIMEOUT_MARK |
|
27 | else |
|
27 | else |
|
28 | RUN_ERROR_MARK # these are run time errors |
|
28 | RUN_ERROR_MARK # these are run time errors |
|
29 | end |
|
29 | end |
|
30 | end |
|
30 | end |
|
31 |
|
31 | ||
|
32 | problem_home = ENV['PROBLEM_HOME'] |
|
32 | problem_home = ENV['PROBLEM_HOME'] |
|
33 | require "#{problem_home}/script/test_dsl.rb" |
|
33 | require "#{problem_home}/script/test_dsl.rb" |
|
34 | load "#{problem_home}/test_cases/all_tests.cfg" |
|
34 | load "#{problem_home}/test_cases/all_tests.cfg" |
|
35 | problem = Problem.get_instance |
|
35 | problem = Problem.get_instance |
|
36 |
|
36 | ||
|
37 | if problem.well_formed? == false |
|
37 | if problem.well_formed? == false |
|
38 | log "The problem specification is not well formed." |
|
38 | log "The problem specification is not well formed." |
|
39 | exit(127) |
|
39 | exit(127) |
|
40 | end |
|
40 | end |
|
41 |
|
41 | ||
|
42 | all_score = 0 |
|
42 | all_score = 0 |
|
43 | all_comment = '' |
|
43 | all_comment = '' |
|
44 | (1..(problem.runs.length-1)).each do |k| |
|
44 | (1..(problem.runs.length-1)).each do |k| |
|
45 | log "grade run #{k}" |
|
45 | log "grade run #{k}" |
|
46 | run = problem.runs[k] |
|
46 | run = problem.runs[k] |
|
47 | run_score = 0 |
|
47 | run_score = 0 |
|
48 | run_comment = '' |
|
48 | run_comment = '' |
|
49 | run_comment_short = '' |
|
49 | run_comment_short = '' |
|
50 | run.tests.each do |test_num| |
|
50 | run.tests.each do |test_num| |
|
51 | result_file_name = "#{test_num}/result" |
|
51 | result_file_name = "#{test_num}/result" |
|
52 | if not File.exists?(result_file_name) |
|
52 | if not File.exists?(result_file_name) |
|
53 | run_comment += "result file for test #{test_num} not found\n" |
|
53 | run_comment += "result file for test #{test_num} not found\n" |
|
54 | run_comment_short += RUN_ERROR_MARK |
|
54 | run_comment_short += RUN_ERROR_MARK |
|
55 | log "Cannot find the file #{test_num}/result!" |
|
55 | log "Cannot find the file #{test_num}/result!" |
|
56 | else |
|
56 | else |
|
57 | result_file = File.new(result_file_name, "r") |
|
57 | result_file = File.new(result_file_name, "r") |
|
58 | result_file_lines = result_file.readlines |
|
58 | result_file_lines = result_file.readlines |
|
59 | - run_score = run_score + result_file_lines[1].to_i |
|
59 | + if result_file_lines.length>=2 |
|
60 |
- |
|
60 | + run_score = run_score + result_file_lines[1].to_i |
|
61 |
- run_comment |
|
61 | + run_comment += result_file_lines[0] |
|
|
62 | + run_comment_short += char_comment(result_file_lines[0]) | ||
|
|
63 | + else | ||
|
|
64 | + run_comment += "result file for test #{test_num} error\n" | ||
|
|
65 | + run_comment_short += RUN_ERROR_MARK | ||
|
|
66 | + log "Error in #{test_num}/result!" | ||
|
|
67 | + end | ||
|
62 | result_file.close |
|
68 | result_file.close |
|
63 | end |
|
69 | end |
|
64 | end |
|
70 | end |
|
65 |
|
71 | ||
|
66 | # find total score for this run |
|
72 | # find total score for this run |
|
67 | run_total_score = 0 |
|
73 | run_total_score = 0 |
|
68 | problem = Problem.get_instance |
|
74 | problem = Problem.get_instance |
|
69 | run.tests.each { |test_num| run_total_score += problem.get_score(test_num) } |
|
75 | run.tests.each { |test_num| run_total_score += problem.get_score(test_num) } |
|
70 |
|
76 | ||
|
71 | if run_total_score!=run_score # fail in some test cases, fail the run |
|
77 | if run_total_score!=run_score # fail in some test cases, fail the run |
|
72 | run_score = 0 |
|
78 | run_score = 0 |
|
73 | end |
|
79 | end |
|
74 |
|
80 | ||
|
75 | run_result_file = File.new("result-#{k}", "w") |
|
81 | run_result_file = File.new("result-#{k}", "w") |
|
76 | run_result_file.write run_score |
|
82 | run_result_file.write run_score |
|
77 | run_result_file.write "\n" |
|
83 | run_result_file.write "\n" |
|
78 | run_result_file.close |
|
84 | run_result_file.close |
|
79 |
|
85 | ||
|
80 | run_comment_file = File.new("comment-#{k}", "w") |
|
86 | run_comment_file = File.new("comment-#{k}", "w") |
|
81 | run_comment_file.write "#{run_comment}\n" |
|
87 | run_comment_file.write "#{run_comment}\n" |
|
82 | run_comment_file.close |
|
88 | run_comment_file.close |
|
83 |
|
89 | ||
|
84 | all_score = all_score + run_score |
|
90 | all_score = all_score + run_score |
|
85 |
|
91 | ||
|
86 | # append comment for test run with many test cases |
|
92 | # append comment for test run with many test cases |
|
87 | if run.tests.length > 1 |
|
93 | if run.tests.length > 1 |
|
88 | run_comment_short = '[' + run_comment_short + ']' |
|
94 | run_comment_short = '[' + run_comment_short + ']' |
|
89 | end |
|
95 | end |
|
90 | all_comment += run_comment_short |
|
96 | all_comment += run_comment_short |
|
91 | end |
|
97 | end |
|
92 |
|
98 | ||
|
93 | result_file = File.new("result", "w") |
|
99 | result_file = File.new("result", "w") |
|
94 | result_file.write all_score |
|
100 | result_file.write all_score |
|
95 | result_file.write "\n" |
|
101 | result_file.write "\n" |
|
96 | result_file.close |
|
102 | result_file.close |
|
97 |
|
103 | ||
|
98 | comment_file = File.new("comment", "w") |
|
104 | comment_file = File.new("comment", "w") |
|
99 | comment_file.write "#{all_comment}\n" |
|
105 | comment_file.write "#{all_comment}\n" |
|
100 | comment_file.close |
|
106 | comment_file.close |
You need to be logged in to leave comments.
Login now