Description:
[grader] change messages
git-svn-id: http://theory.cpe.ku.ac.th/grader/judge/trunk/scripts@242 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
r58:b32b8de97eae - - 1 file changed: 8 inserted, 2 deleted
@@ -1,117 +1,123 | |||||
|
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 | if FileTest.exist?(cmp_msg_fname) |
|
51 | if FileTest.exist?(cmp_msg_fname) |
|
52 | cmp_file = File.open(cmp_msg_fname) |
|
52 | cmp_file = File.open(cmp_msg_fname) |
|
53 | cmp_msg = cmp_file.read |
|
53 | cmp_msg = cmp_file.read |
|
54 | cmp_file.close |
|
54 | cmp_file.close |
|
55 | else |
|
55 | else |
|
56 | cmp_msg = "" |
|
56 | cmp_msg = "" |
|
57 | end |
|
57 | end |
|
58 |
|
58 | ||
|
59 | result_fname = "#{test_result_dir}/result" |
|
59 | result_fname = "#{test_result_dir}/result" |
|
60 | comment_fname = "#{test_result_dir}/comment" |
|
60 | comment_fname = "#{test_result_dir}/comment" |
|
61 | if FileTest.exist?(result_fname) |
|
61 | if FileTest.exist?(result_fname) |
|
62 | comment = "" |
|
62 | comment = "" |
|
63 | begin |
|
63 | begin |
|
64 | result_file = File.open(result_fname) |
|
64 | result_file = File.open(result_fname) |
|
65 | result = result_file.readline.to_i |
|
65 | result = result_file.readline.to_i |
|
66 | result_file.close |
|
66 | result_file.close |
|
67 | rescue |
|
67 | rescue |
|
68 | result = 0 |
|
68 | result = 0 |
|
69 | comment = "error reading result file." |
|
69 | comment = "error reading result file." |
|
70 | end |
|
70 | end |
|
71 |
|
71 | ||
|
72 | begin |
|
72 | begin |
|
73 | comment_file = File.open(comment_fname) |
|
73 | comment_file = File.open(comment_fname) |
|
74 | comment += comment_file.readline.chomp |
|
74 | comment += comment_file.readline.chomp |
|
75 | comment_file.close |
|
75 | comment_file.close |
|
76 | rescue |
|
76 | rescue |
|
77 | comment += "" |
|
77 | comment += "" |
|
78 | end |
|
78 | end |
|
79 |
|
79 | ||
|
80 | return {:points => result, |
|
80 | return {:points => result, |
|
81 | :comment => comment, |
|
81 | :comment => comment, |
|
82 | :cmp_msg => cmp_msg} |
|
82 | :cmp_msg => cmp_msg} |
|
83 | else |
|
83 | else |
|
84 | if FileTest.exist?("#{test_result_dir}/a.out") |
|
84 | if FileTest.exist?("#{test_result_dir}/a.out") |
|
85 | return {:points => 0, |
|
85 | return {:points => 0, |
|
86 | :comment => 'error during grading', |
|
86 | :comment => 'error during grading', |
|
87 | :cmp_msg => cmp_msg} |
|
87 | :cmp_msg => cmp_msg} |
|
88 | else |
|
88 | else |
|
89 | return {:points => 0, |
|
89 | return {:points => 0, |
|
90 | :comment => 'compilation error', |
|
90 | :comment => 'compilation error', |
|
91 | :cmp_msg => cmp_msg} |
|
91 | :cmp_msg => cmp_msg} |
|
92 | end |
|
92 | end |
|
93 | end |
|
93 | end |
|
94 | end |
|
94 | end |
|
95 |
|
95 | ||
|
96 | def save_result(submission,result) |
|
96 | def save_result(submission,result) |
|
97 | problem = submission.problem |
|
97 | problem = submission.problem |
|
98 | submission.graded_at = Time.now.gmtime |
|
98 | submission.graded_at = Time.now.gmtime |
|
99 | points = result[:points] |
|
99 | points = result[:points] |
|
100 | submission.points = points |
|
100 | submission.points = points |
|
101 | comment = @config.report_comment(result[:comment]) |
|
101 | comment = @config.report_comment(result[:comment]) |
|
|
102 | + | ||
|
|
103 | + # | ||
|
|
104 | + # TODO: FIX THIS MESSAGE | ||
|
|
105 | + # | ||
|
102 | if problem == nil |
|
106 | if problem == nil |
|
103 | submission.grader_comment = 'PASSED: ' + comment + '(problem is nil)' |
|
107 | submission.grader_comment = 'PASSED: ' + comment + '(problem is nil)' |
|
104 | elsif points == problem.full_score |
|
108 | elsif points == problem.full_score |
|
105 | - submission.grader_comment = 'PASSED: ' + comment |
|
109 | + #submission.grader_comment = 'PASSED: ' + comment |
|
|
110 | + submission.grader_comment = comment | ||
|
106 | elsif result[:comment].chomp =~ /^[\[\]P]+$/ |
|
111 | elsif result[:comment].chomp =~ /^[\[\]P]+$/ |
|
107 | submission.grader_comment = 'PASSED: ' + comment + '(inconsistent score)' |
|
112 | submission.grader_comment = 'PASSED: ' + comment + '(inconsistent score)' |
|
108 | else |
|
113 | else |
|
109 | - submission.grader_comment = 'FAILED: ' + comment |
|
114 | + #submission.grader_comment = 'FAILED: ' + comment |
|
|
115 | + submission.grader_comment = comment | ||
|
110 | end |
|
116 | end |
|
111 | submission.compiler_message = result[:cmp_msg] or '' |
|
117 | submission.compiler_message = result[:cmp_msg] or '' |
|
112 | submission.save |
|
118 | submission.save |
|
113 | end |
|
119 | end |
|
114 |
|
120 | ||
|
115 | end |
|
121 | end |
|
116 |
|
122 | ||
|
117 | end |
|
123 | end |
You need to be logged in to leave comments.
Login now