Description:
fixed single contest bug, reported by K. Siththa
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r292:35efcd905ebb - - 1 file changed: 1 inserted, 1 deleted
@@ -107,193 +107,193 | |||||
|
107 |
|
107 | ||
|
108 | def submission |
|
108 | def submission |
|
109 | @user = User.find(session[:user_id]) |
|
109 | @user = User.find(session[:user_id]) |
|
110 | @problems = @user.available_problems |
|
110 | @problems = @user.available_problems |
|
111 | if params[:id]==nil |
|
111 | if params[:id]==nil |
|
112 | @problem = nil |
|
112 | @problem = nil |
|
113 | @submissions = nil |
|
113 | @submissions = nil |
|
114 | else |
|
114 | else |
|
115 | @problem = Problem.find_by_name(params[:id]) |
|
115 | @problem = Problem.find_by_name(params[:id]) |
|
116 | if not @problem.available |
|
116 | if not @problem.available |
|
117 | redirect_to :action => 'list' |
|
117 | redirect_to :action => 'list' |
|
118 | flash[:notice] = 'Error: submissions for that problem are not viewable.' |
|
118 | flash[:notice] = 'Error: submissions for that problem are not viewable.' |
|
119 | return |
|
119 | return |
|
120 | end |
|
120 | end |
|
121 | @submissions = Submission.find_all_by_user_problem(@user.id, @problem.id) |
|
121 | @submissions = Submission.find_all_by_user_problem(@user.id, @problem.id) |
|
122 | end |
|
122 | end |
|
123 | end |
|
123 | end |
|
124 |
|
124 | ||
|
125 | def result |
|
125 | def result |
|
126 | if !Configuration.show_grading_result |
|
126 | if !Configuration.show_grading_result |
|
127 | redirect_to :action => 'list' and return |
|
127 | redirect_to :action => 'list' and return |
|
128 | end |
|
128 | end |
|
129 | @user = User.find(session[:user_id]) |
|
129 | @user = User.find(session[:user_id]) |
|
130 | @submission = Submission.find(params[:id]) |
|
130 | @submission = Submission.find(params[:id]) |
|
131 | if @submission.user!=@user |
|
131 | if @submission.user!=@user |
|
132 | flash[:notice] = 'You are not allowed to view result of other users.' |
|
132 | flash[:notice] = 'You are not allowed to view result of other users.' |
|
133 | redirect_to :action => 'list' and return |
|
133 | redirect_to :action => 'list' and return |
|
134 | end |
|
134 | end |
|
135 | prepare_grading_result(@submission) |
|
135 | prepare_grading_result(@submission) |
|
136 | end |
|
136 | end |
|
137 |
|
137 | ||
|
138 | def load_output |
|
138 | def load_output |
|
139 | if !Configuration.show_grading_result or params[:num]==nil |
|
139 | if !Configuration.show_grading_result or params[:num]==nil |
|
140 | redirect_to :action => 'list' and return |
|
140 | redirect_to :action => 'list' and return |
|
141 | end |
|
141 | end |
|
142 | @user = User.find(session[:user_id]) |
|
142 | @user = User.find(session[:user_id]) |
|
143 | @submission = Submission.find(params[:id]) |
|
143 | @submission = Submission.find(params[:id]) |
|
144 | if @submission.user!=@user |
|
144 | if @submission.user!=@user |
|
145 | flash[:notice] = 'You are not allowed to view result of other users.' |
|
145 | flash[:notice] = 'You are not allowed to view result of other users.' |
|
146 | redirect_to :action => 'list' and return |
|
146 | redirect_to :action => 'list' and return |
|
147 | end |
|
147 | end |
|
148 | case_num = params[:num].to_i |
|
148 | case_num = params[:num].to_i |
|
149 | out_filename = output_filename(@user.login, |
|
149 | out_filename = output_filename(@user.login, |
|
150 | @submission.problem.name, |
|
150 | @submission.problem.name, |
|
151 | @submission.id, |
|
151 | @submission.id, |
|
152 | case_num) |
|
152 | case_num) |
|
153 | if !FileTest.exists?(out_filename) |
|
153 | if !FileTest.exists?(out_filename) |
|
154 | flash[:notice] = 'Output not found.' |
|
154 | flash[:notice] = 'Output not found.' |
|
155 | redirect_to :action => 'list' and return |
|
155 | redirect_to :action => 'list' and return |
|
156 | end |
|
156 | end |
|
157 |
|
157 | ||
|
158 | if defined?(USE_APACHE_XSENDFILE) and USE_APACHE_XSENDFILE |
|
158 | if defined?(USE_APACHE_XSENDFILE) and USE_APACHE_XSENDFILE |
|
159 | response.headers['Content-Type'] = "application/force-download" |
|
159 | response.headers['Content-Type'] = "application/force-download" |
|
160 | response.headers['Content-Disposition'] = "attachment; filename=\"output-#{case_num}.txt\"" |
|
160 | response.headers['Content-Disposition'] = "attachment; filename=\"output-#{case_num}.txt\"" |
|
161 | response.headers["X-Sendfile"] = out_filename |
|
161 | response.headers["X-Sendfile"] = out_filename |
|
162 | response.headers['Content-length'] = File.size(out_filename) |
|
162 | response.headers['Content-length'] = File.size(out_filename) |
|
163 | render :nothing => true |
|
163 | render :nothing => true |
|
164 | else |
|
164 | else |
|
165 | send_file out_filename, :stream => false, :filename => "output-#{case_num}.txt", :type => "text/plain" |
|
165 | send_file out_filename, :stream => false, :filename => "output-#{case_num}.txt", :type => "text/plain" |
|
166 | end |
|
166 | end |
|
167 | end |
|
167 | end |
|
168 |
|
168 | ||
|
169 | def error |
|
169 | def error |
|
170 | @user = User.find(session[:user_id]) |
|
170 | @user = User.find(session[:user_id]) |
|
171 | end |
|
171 | end |
|
172 |
|
172 | ||
|
173 | # announcement refreshing and hiding methods |
|
173 | # announcement refreshing and hiding methods |
|
174 |
|
174 | ||
|
175 | def announcements |
|
175 | def announcements |
|
176 | if params.has_key? 'recent' |
|
176 | if params.has_key? 'recent' |
|
177 | prepare_announcements(params[:recent]) |
|
177 | prepare_announcements(params[:recent]) |
|
178 | else |
|
178 | else |
|
179 | prepare_announcements |
|
179 | prepare_announcements |
|
180 | end |
|
180 | end |
|
181 | render(:partial => 'announcement', |
|
181 | render(:partial => 'announcement', |
|
182 | :collection => @announcements, |
|
182 | :collection => @announcements, |
|
183 | :locals => {:announcement_effect => true}) |
|
183 | :locals => {:announcement_effect => true}) |
|
184 | end |
|
184 | end |
|
185 |
|
185 | ||
|
186 | protected |
|
186 | protected |
|
187 |
|
187 | ||
|
188 | def prepare_announcements(recent=nil) |
|
188 | def prepare_announcements(recent=nil) |
|
189 | if Configuration.show_tasks_to?(@user) |
|
189 | if Configuration.show_tasks_to?(@user) |
|
190 | @announcements = Announcement.find_published(true) |
|
190 | @announcements = Announcement.find_published(true) |
|
191 | else |
|
191 | else |
|
192 | @announcements = Announcement.find_published |
|
192 | @announcements = Announcement.find_published |
|
193 | end |
|
193 | end |
|
194 | if recent!=nil |
|
194 | if recent!=nil |
|
195 | recent_id = recent.to_i |
|
195 | recent_id = recent.to_i |
|
196 | @announcements = @announcements.find_all { |a| a.id > recent_id } |
|
196 | @announcements = @announcements.find_all { |a| a.id > recent_id } |
|
197 | end |
|
197 | end |
|
198 | end |
|
198 | end |
|
199 |
|
199 | ||
|
200 | def prepare_list_information |
|
200 | def prepare_list_information |
|
201 | @user = User.find(session[:user_id]) |
|
201 | @user = User.find(session[:user_id]) |
|
202 | if not Configuration.multicontests? |
|
202 | if not Configuration.multicontests? |
|
203 | - @problems = problem_list_for_user(@user) |
|
203 | + @problems = @user.available_problems |
|
204 | else |
|
204 | else |
|
205 | @contest_problems = @user.available_problems_group_by_contests |
|
205 | @contest_problems = @user.available_problems_group_by_contests |
|
206 | @problems = @user.available_problems |
|
206 | @problems = @user.available_problems |
|
207 | end |
|
207 | end |
|
208 | @prob_submissions = {} |
|
208 | @prob_submissions = {} |
|
209 | @problems.each do |p| |
|
209 | @problems.each do |p| |
|
210 | sub = Submission.find_last_by_user_and_problem(@user.id,p.id) |
|
210 | sub = Submission.find_last_by_user_and_problem(@user.id,p.id) |
|
211 | if sub!=nil |
|
211 | if sub!=nil |
|
212 | @prob_submissions[p.id] = { :count => sub.number, :submission => sub } |
|
212 | @prob_submissions[p.id] = { :count => sub.number, :submission => sub } |
|
213 | else |
|
213 | else |
|
214 | @prob_submissions[p.id] = { :count => 0, :submission => nil } |
|
214 | @prob_submissions[p.id] = { :count => 0, :submission => nil } |
|
215 | end |
|
215 | end |
|
216 | end |
|
216 | end |
|
217 | prepare_announcements |
|
217 | prepare_announcements |
|
218 | end |
|
218 | end |
|
219 |
|
219 | ||
|
220 | def check_viewability |
|
220 | def check_viewability |
|
221 | @user = User.find(session[:user_id]) |
|
221 | @user = User.find(session[:user_id]) |
|
222 | if (!Configuration.show_tasks_to?(@user)) and |
|
222 | if (!Configuration.show_tasks_to?(@user)) and |
|
223 | ((action_name=='submission') or (action_name=='submit')) |
|
223 | ((action_name=='submission') or (action_name=='submit')) |
|
224 | redirect_to :action => 'list' and return |
|
224 | redirect_to :action => 'list' and return |
|
225 | end |
|
225 | end |
|
226 | end |
|
226 | end |
|
227 |
|
227 | ||
|
228 | def prepare_grading_result(submission) |
|
228 | def prepare_grading_result(submission) |
|
229 | if Configuration.task_grading_info.has_key? submission.problem.name |
|
229 | if Configuration.task_grading_info.has_key? submission.problem.name |
|
230 | grading_info = Configuration.task_grading_info[submission.problem.name] |
|
230 | grading_info = Configuration.task_grading_info[submission.problem.name] |
|
231 | else |
|
231 | else |
|
232 | # guess task info from problem.full_score |
|
232 | # guess task info from problem.full_score |
|
233 | cases = submission.problem.full_score / 10 |
|
233 | cases = submission.problem.full_score / 10 |
|
234 | grading_info = { |
|
234 | grading_info = { |
|
235 | 'testruns' => cases, |
|
235 | 'testruns' => cases, |
|
236 | 'testcases' => cases |
|
236 | 'testcases' => cases |
|
237 | } |
|
237 | } |
|
238 | end |
|
238 | end |
|
239 | @test_runs = [] |
|
239 | @test_runs = [] |
|
240 | if grading_info['testruns'].is_a? Integer |
|
240 | if grading_info['testruns'].is_a? Integer |
|
241 | trun_count = grading_info['testruns'] |
|
241 | trun_count = grading_info['testruns'] |
|
242 | trun_count.times do |i| |
|
242 | trun_count.times do |i| |
|
243 | @test_runs << [ read_grading_result(@user.login, |
|
243 | @test_runs << [ read_grading_result(@user.login, |
|
244 | submission.problem.name, |
|
244 | submission.problem.name, |
|
245 | submission.id, |
|
245 | submission.id, |
|
246 | i+1) ] |
|
246 | i+1) ] |
|
247 | end |
|
247 | end |
|
248 | else |
|
248 | else |
|
249 | grading_info['testruns'].keys.sort.each do |num| |
|
249 | grading_info['testruns'].keys.sort.each do |num| |
|
250 | run = [] |
|
250 | run = [] |
|
251 | testrun = grading_info['testruns'][num] |
|
251 | testrun = grading_info['testruns'][num] |
|
252 | testrun.each do |c| |
|
252 | testrun.each do |c| |
|
253 | run << read_grading_result(@user.login, |
|
253 | run << read_grading_result(@user.login, |
|
254 | submission.problem.name, |
|
254 | submission.problem.name, |
|
255 | submission.id, |
|
255 | submission.id, |
|
256 | c) |
|
256 | c) |
|
257 | end |
|
257 | end |
|
258 | @test_runs << run |
|
258 | @test_runs << run |
|
259 | end |
|
259 | end |
|
260 | end |
|
260 | end |
|
261 | end |
|
261 | end |
|
262 |
|
262 | ||
|
263 | def grading_result_dir(user_name, problem_name, submission_id, case_num) |
|
263 | def grading_result_dir(user_name, problem_name, submission_id, case_num) |
|
264 | return "#{GRADING_RESULT_DIR}/#{user_name}/#{problem_name}/#{submission_id}/test-result/#{case_num}" |
|
264 | return "#{GRADING_RESULT_DIR}/#{user_name}/#{problem_name}/#{submission_id}/test-result/#{case_num}" |
|
265 | end |
|
265 | end |
|
266 |
|
266 | ||
|
267 | def output_filename(user_name, problem_name, submission_id, case_num) |
|
267 | def output_filename(user_name, problem_name, submission_id, case_num) |
|
268 | dir = grading_result_dir(user_name,problem_name, submission_id, case_num) |
|
268 | dir = grading_result_dir(user_name,problem_name, submission_id, case_num) |
|
269 | return "#{dir}/output.txt" |
|
269 | return "#{dir}/output.txt" |
|
270 | end |
|
270 | end |
|
271 |
|
271 | ||
|
272 | def read_grading_result(user_name, problem_name, submission_id, case_num) |
|
272 | def read_grading_result(user_name, problem_name, submission_id, case_num) |
|
273 | dir = grading_result_dir(user_name,problem_name, submission_id, case_num) |
|
273 | dir = grading_result_dir(user_name,problem_name, submission_id, case_num) |
|
274 | result_file_name = "#{dir}/result" |
|
274 | result_file_name = "#{dir}/result" |
|
275 | if !FileTest.exists?(result_file_name) |
|
275 | if !FileTest.exists?(result_file_name) |
|
276 | return {:num => case_num, :msg => 'program did not run'} |
|
276 | return {:num => case_num, :msg => 'program did not run'} |
|
277 | else |
|
277 | else |
|
278 | results = File.open(result_file_name).readlines |
|
278 | results = File.open(result_file_name).readlines |
|
279 | run_stat = extract_running_stat(results) |
|
279 | run_stat = extract_running_stat(results) |
|
280 | output_filename = "#{dir}/output.txt" |
|
280 | output_filename = "#{dir}/output.txt" |
|
281 | if FileTest.exists?(output_filename) |
|
281 | if FileTest.exists?(output_filename) |
|
282 | output_file = true |
|
282 | output_file = true |
|
283 | output_size = File.size(output_filename) |
|
283 | output_size = File.size(output_filename) |
|
284 | else |
|
284 | else |
|
285 | output_file = false |
|
285 | output_file = false |
|
286 | output_size = 0 |
|
286 | output_size = 0 |
|
287 | end |
|
287 | end |
|
288 |
|
288 | ||
|
289 | return { |
|
289 | return { |
|
290 | :num => case_num, |
|
290 | :num => case_num, |
|
291 | :msg => results[0], |
|
291 | :msg => results[0], |
|
292 | :run_stat => run_stat, |
|
292 | :run_stat => run_stat, |
|
293 | :output => output_file, |
|
293 | :output => output_file, |
|
294 | :output_size => output_size |
|
294 | :output_size => output_size |
|
295 | } |
|
295 | } |
|
296 | end |
|
296 | end |
|
297 | end |
|
297 | end |
|
298 |
|
298 | ||
|
299 | # copied from grader/script/lib/test_request_helper.rb |
|
299 | # copied from grader/script/lib/test_request_helper.rb |
You need to be logged in to leave comments.
Login now