Description:
[grader] formatting output of test_request
git-svn-id: http://theory.cpe.ku.ac.th/grader/judge/trunk/scripts@140 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
r38:53204d348092 - - 1 file changed: 1 inserted, 1 deleted
@@ -56,135 +56,135 | |||
|
56 | 56 | protected |
|
57 | 57 | def grading_room_dir(test_request) |
|
58 | 58 | problem_name = test_request.problem_name |
|
59 | 59 | user = test_request.user |
|
60 | 60 | "#{@config.user_result_dir}" + |
|
61 | 61 | "/#{user.login}/test_request" + |
|
62 | 62 | "/#{problem_name}/#{test_request.id}" |
|
63 | 63 | end |
|
64 | 64 | |
|
65 | 65 | def problem_home_dir(test_request) |
|
66 | 66 | problem_name = test_request.problem_name |
|
67 | 67 | user = test_request.user |
|
68 | 68 | "#{@config.user_result_dir}" + |
|
69 | 69 | "/#{user.login}/test_request/#{problem_name}" |
|
70 | 70 | end |
|
71 | 71 | |
|
72 | 72 | def copy_problem_template(template_dir,problem_home) |
|
73 | 73 | cmd = "cp -R #{template_dir}/* #{problem_home}" |
|
74 | 74 | system_and_raise_when_fail(cmd,"Test Request: cannot copy problem template") |
|
75 | 75 | end |
|
76 | 76 | |
|
77 | 77 | def link_input_file(test_request,problem_home) |
|
78 | 78 | cmd = "ln -s #{test_request.input_file_name} #{problem_home}/test_cases/1/input-1.txt" |
|
79 | 79 | system_and_raise_when_fail(cmd,"Test Request: cannot link input file") |
|
80 | 80 | end |
|
81 | 81 | |
|
82 | 82 | def remove_data_files(problem_home) |
|
83 | 83 | if File.exists?("#{problem_home}/test_cases/1/input-1.txt") |
|
84 | 84 | cmd = "rm #{problem_home}/test_cases/1/*" |
|
85 | 85 | system_and_raise_when_fail(cmd,"Test Request: cannot remove data files") |
|
86 | 86 | end |
|
87 | 87 | end |
|
88 | 88 | |
|
89 | 89 | def system_and_raise_when_fail(cmd,msg) |
|
90 | 90 | if !system(cmd) |
|
91 | 91 | raise msg |
|
92 | 92 | end |
|
93 | 93 | end |
|
94 | 94 | |
|
95 | 95 | end |
|
96 | 96 | |
|
97 | 97 | class TestRequestReporter |
|
98 | 98 | def initialize |
|
99 | 99 | @config = Grader::Configuration.get_instance |
|
100 | 100 | end |
|
101 | 101 | |
|
102 | 102 | def report(test_request,test_result_dir) |
|
103 | 103 | save_result(test_request,read_result(test_result_dir)) |
|
104 | 104 | end |
|
105 | 105 | |
|
106 | 106 | def report_error(test_request, msg) |
|
107 | 107 | save_result(test_request, {:running_stat => "#{msg}"}) |
|
108 | 108 | end |
|
109 | 109 | |
|
110 | 110 | protected |
|
111 | 111 | def read_result(test_result_dir) |
|
112 | 112 | # TODO: |
|
113 | 113 | cmp_msg_fname = "#{test_result_dir}/compiler_message" |
|
114 | 114 | cmp_file = File.open(cmp_msg_fname) |
|
115 | 115 | cmp_msg = cmp_file.read |
|
116 | 116 | cmp_file.close |
|
117 | 117 | |
|
118 | 118 | result_file_name = "#{test_result_dir}/1/result" |
|
119 | 119 | |
|
120 | 120 | if File.exists?(result_file_name) |
|
121 | 121 | output_file_name = "#{test_result_dir}/1/output.txt" |
|
122 | 122 | results = File.open("#{test_result_dir}/1/result").readlines |
|
123 | 123 | stat = format_running_stat(results) |
|
124 | 124 | |
|
125 | 125 | return { |
|
126 | 126 | :output_file_name => output_file_name, |
|
127 | 127 | :running_stat => stat, |
|
128 | 128 | :comment => "", |
|
129 | 129 | :cmp_msg => cmp_msg} |
|
130 | 130 | else |
|
131 | 131 | return { |
|
132 | 132 | :running_stat => "", |
|
133 | 133 | :comment => "Compilation error", |
|
134 | 134 | :cmp_msg => cmp_msg} |
|
135 | 135 | end |
|
136 | 136 | end |
|
137 | 137 | |
|
138 | 138 | def format_running_stat(results) |
|
139 | 139 | running_time_line = results[-1] |
|
140 | 140 | |
|
141 | 141 | run_stat = "" |
|
142 | 142 | if !(/[Cc]orrect/.match(results[0])) |
|
143 | 143 | run_stat = results[0].chomp |
|
144 | 144 | end |
|
145 | 145 | |
|
146 | 146 | if res = /r(.*)u(.*)s/.match(running_time_line) |
|
147 | 147 | seconds = (res[1].to_f + res[2].to_f) |
|
148 | 148 | time_stat = "Time used: #{seconds} sec." |
|
149 | 149 | else |
|
150 | 150 | time_stat = "Time used: n/a sec." |
|
151 | 151 | end |
|
152 | - return "#{run_stat}#{time_stat}" | |
|
152 | + return "#{run_stat}\n#{time_stat}" | |
|
153 | 153 | end |
|
154 | 154 | |
|
155 | 155 | def save_result(test_request,result) |
|
156 | 156 | if result[:output_file_name]!=nil |
|
157 | 157 | test_request.output_file_name = link_output_file(test_request, |
|
158 | 158 | result[:output_file_name]) |
|
159 | 159 | end |
|
160 | 160 | test_request.graded_at = Time.now |
|
161 | 161 | test_request.compiler_message = (result[:cmp_msg] or '') |
|
162 | 162 | test_request.grader_comment = (result[:comment] or '') |
|
163 | 163 | test_request.running_stat = (result[:running_stat] or '') |
|
164 | 164 | test_request.save |
|
165 | 165 | end |
|
166 | 166 | |
|
167 | 167 | protected |
|
168 | 168 | def link_output_file(test_request, fname) |
|
169 | 169 | target_file_name = random_output_file_name(test_request.user, |
|
170 | 170 | test_request.problem) |
|
171 | 171 | FileUtils.mkdir_p(File.dirname(target_file_name)) |
|
172 | 172 | cmd = "ln -s #{fname} #{target_file_name}" |
|
173 | 173 | if !system(cmd) |
|
174 | 174 | raise "TestRequestReporter: cannot move output file" |
|
175 | 175 | end |
|
176 | 176 | return target_file_name |
|
177 | 177 | end |
|
178 | 178 | |
|
179 | 179 | def random_output_file_name(user,problem) |
|
180 | 180 | problem_name = TestRequest.name_of(problem) |
|
181 | 181 | begin |
|
182 | 182 | tmpname = "#{@config.test_request_output_base_dir}" + |
|
183 | 183 | "/#{user.login}/#{problem_name}/#{rand(10000)}" |
|
184 | 184 | end while File.exists?(tmpname) |
|
185 | 185 | tmpname |
|
186 | 186 | end |
|
187 | 187 | |
|
188 | 188 | end |
|
189 | 189 | |
|
190 | 190 | end |
You need to be logged in to leave comments.
Login now