Description:
fixed problem description refresh bug
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r259:fd4ff20f8070 - - 3 files changed: 22 inserted, 8 deleted
@@ -0,0 +1,17 | |||||
|
|
1 | + <div class="problem-bar" id="problem-bar-<%= problem.id %>"> | ||
|
|
2 | + <% if @page_reload_when_view_problem %> | ||
|
|
3 | + <a href="<%= url_for :action => 'list', :id => problem.id %>"> | ||
|
|
4 | + <% else %> | ||
|
|
5 | + <a href="#" | ||
|
|
6 | + onclick="$$('.problem-panel').each(function(elt) {elt.hide();}); $('problem-panel-<%= problem.id %>').show(); $('problem-panel-filler').hide(); return false;"> | ||
|
|
7 | + <% end %> | ||
|
|
8 | + <span class="problem-title"> | ||
|
|
9 | + <%= problem.full_name %> | ||
|
|
10 | + <% if @prob_submissions[problem_title_counter][:count] > 0 %> | ||
|
|
11 | + [<%= @prob_submissions[problem_title_counter][:count] %> trials(s)] | ||
|
|
12 | + <% else %> | ||
|
|
13 | + [No trials] | ||
|
|
14 | + <% end %> | ||
|
|
15 | + </span> | ||
|
|
16 | + </a> | ||
|
|
17 | + </div> |
@@ -89,397 +89,402 | |||||
|
89 | send_data(submission.source, |
|
89 | send_data(submission.source, |
|
90 | {:filename => submission.download_filename, |
|
90 | {:filename => submission.download_filename, |
|
91 | :type => 'text/plain'}) |
|
91 | :type => 'text/plain'}) |
|
92 | else |
|
92 | else |
|
93 | flash[:notice] = 'Error viewing source' |
|
93 | flash[:notice] = 'Error viewing source' |
|
94 | redirect_to :action => 'list' |
|
94 | redirect_to :action => 'list' |
|
95 | end |
|
95 | end |
|
96 | end |
|
96 | end |
|
97 |
|
97 | ||
|
98 | def compiler_msg |
|
98 | def compiler_msg |
|
99 | @submission = Submission.find(params[:id]) |
|
99 | @submission = Submission.find(params[:id]) |
|
100 | if @submission.user_id == session[:user_id] |
|
100 | if @submission.user_id == session[:user_id] |
|
101 | render :action => 'compiler_msg', :layout => 'empty' |
|
101 | render :action => 'compiler_msg', :layout => 'empty' |
|
102 | else |
|
102 | else |
|
103 | flash[:notice] = 'Error viewing source' |
|
103 | flash[:notice] = 'Error viewing source' |
|
104 | redirect_to :action => 'list' |
|
104 | redirect_to :action => 'list' |
|
105 | end |
|
105 | end |
|
106 | end |
|
106 | end |
|
107 |
|
107 | ||
|
108 | def submission |
|
108 | def submission |
|
109 | # protect the action for Code Jom |
|
109 | # protect the action for Code Jom |
|
110 | redirect_to :action => 'list' |
|
110 | redirect_to :action => 'list' |
|
111 |
|
111 | ||
|
112 | @user = User.find(session[:user_id]) |
|
112 | @user = User.find(session[:user_id]) |
|
113 | @problems = Problem.find_available_problems |
|
113 | @problems = Problem.find_available_problems |
|
114 | if params[:id]==nil |
|
114 | if params[:id]==nil |
|
115 | @problem = nil |
|
115 | @problem = nil |
|
116 | @submissions = nil |
|
116 | @submissions = nil |
|
117 | else |
|
117 | else |
|
118 | @problem = Problem.find_by_name(params[:id]) |
|
118 | @problem = Problem.find_by_name(params[:id]) |
|
119 | if not @problem.available |
|
119 | if not @problem.available |
|
120 | redirect_to :action => 'list' |
|
120 | redirect_to :action => 'list' |
|
121 | flash[:notice] = 'Error: submissions for that problem are not viewable.' |
|
121 | flash[:notice] = 'Error: submissions for that problem are not viewable.' |
|
122 | return |
|
122 | return |
|
123 | end |
|
123 | end |
|
124 | @submissions = Submission.find_all_by_user_problem(@user.id, @problem.id) |
|
124 | @submissions = Submission.find_all_by_user_problem(@user.id, @problem.id) |
|
125 | end |
|
125 | end |
|
126 | end |
|
126 | end |
|
127 |
|
127 | ||
|
128 | def result |
|
128 | def result |
|
129 | if !Configuration.show_grading_result |
|
129 | if !Configuration.show_grading_result |
|
130 | redirect_to :action => 'list' and return |
|
130 | redirect_to :action => 'list' and return |
|
131 | end |
|
131 | end |
|
132 | @user = User.find(session[:user_id]) |
|
132 | @user = User.find(session[:user_id]) |
|
133 | @submission = Submission.find(params[:id]) |
|
133 | @submission = Submission.find(params[:id]) |
|
134 | if @submission.user!=@user |
|
134 | if @submission.user!=@user |
|
135 | flash[:notice] = 'You are not allowed to view result of other users.' |
|
135 | flash[:notice] = 'You are not allowed to view result of other users.' |
|
136 | redirect_to :action => 'list' and return |
|
136 | redirect_to :action => 'list' and return |
|
137 | end |
|
137 | end |
|
138 | prepare_grading_result(@submission) |
|
138 | prepare_grading_result(@submission) |
|
139 | end |
|
139 | end |
|
140 |
|
140 | ||
|
141 | def load_output |
|
141 | def load_output |
|
142 | if !Configuration.show_grading_result or params[:num]==nil |
|
142 | if !Configuration.show_grading_result or params[:num]==nil |
|
143 | redirect_to :action => 'list' and return |
|
143 | redirect_to :action => 'list' and return |
|
144 | end |
|
144 | end |
|
145 | @user = User.find(session[:user_id]) |
|
145 | @user = User.find(session[:user_id]) |
|
146 | @submission = Submission.find(params[:id]) |
|
146 | @submission = Submission.find(params[:id]) |
|
147 | if @submission.user!=@user |
|
147 | if @submission.user!=@user |
|
148 | flash[:notice] = 'You are not allowed to view result of other users.' |
|
148 | flash[:notice] = 'You are not allowed to view result of other users.' |
|
149 | redirect_to :action => 'list' and return |
|
149 | redirect_to :action => 'list' and return |
|
150 | end |
|
150 | end |
|
151 | case_num = params[:num].to_i |
|
151 | case_num = params[:num].to_i |
|
152 | out_filename = output_filename(@user.login, |
|
152 | out_filename = output_filename(@user.login, |
|
153 | @submission.problem.name, |
|
153 | @submission.problem.name, |
|
154 | @submission.id, |
|
154 | @submission.id, |
|
155 | case_num) |
|
155 | case_num) |
|
156 | if !FileTest.exists?(out_filename) |
|
156 | if !FileTest.exists?(out_filename) |
|
157 | flash[:notice] = 'Output not found.' |
|
157 | flash[:notice] = 'Output not found.' |
|
158 | redirect_to :action => 'list' and return |
|
158 | redirect_to :action => 'list' and return |
|
159 | end |
|
159 | end |
|
160 |
|
160 | ||
|
161 | response.headers['Content-Type'] = "application/force-download" |
|
161 | response.headers['Content-Type'] = "application/force-download" |
|
162 | response.headers['Content-Disposition'] = "attachment; filename=\"output-#{case_num}.txt\"" |
|
162 | response.headers['Content-Disposition'] = "attachment; filename=\"output-#{case_num}.txt\"" |
|
163 | response.headers["X-Sendfile"] = out_filename |
|
163 | response.headers["X-Sendfile"] = out_filename |
|
164 | response.headers['Content-length'] = File.size(out_filename) |
|
164 | response.headers['Content-length'] = File.size(out_filename) |
|
165 | render :nothing => true |
|
165 | render :nothing => true |
|
166 | end |
|
166 | end |
|
167 |
|
167 | ||
|
168 | def error |
|
168 | def error |
|
169 | @user = User.find(session[:user_id]) |
|
169 | @user = User.find(session[:user_id]) |
|
170 | end |
|
170 | end |
|
171 |
|
171 | ||
|
172 | # announcement refreshing and hiding methods |
|
172 | # announcement refreshing and hiding methods |
|
173 |
|
173 | ||
|
174 | def announcements |
|
174 | def announcements |
|
175 | if params.has_key? 'recent' |
|
175 | if params.has_key? 'recent' |
|
176 | prepare_announcements(params[:recent]) |
|
176 | prepare_announcements(params[:recent]) |
|
177 | else |
|
177 | else |
|
178 | prepare_announcements |
|
178 | prepare_announcements |
|
179 | end |
|
179 | end |
|
180 | render(:partial => 'announcement', |
|
180 | render(:partial => 'announcement', |
|
181 | :collection => @announcements, |
|
181 | :collection => @announcements, |
|
182 | :locals => {:announcement_effect => true}) |
|
182 | :locals => {:announcement_effect => true}) |
|
183 | end |
|
183 | end |
|
184 |
|
184 | ||
|
185 | # |
|
185 | # |
|
186 | # actions for Code Jom |
|
186 | # actions for Code Jom |
|
187 | # |
|
187 | # |
|
188 | def download_input |
|
188 | def download_input |
|
189 | user = User.find(session[:user_id]) |
|
189 | user = User.find(session[:user_id]) |
|
190 |
|
190 | ||
|
191 | if Configuration.time_limit_mode? and user.contest_finished? |
|
191 | if Configuration.time_limit_mode? and user.contest_finished? |
|
192 | redirect_to :action => 'list' and return |
|
192 | redirect_to :action => 'list' and return |
|
193 | end |
|
193 | end |
|
194 |
|
194 | ||
|
195 | problem = Problem.find(params[:id]) |
|
195 | problem = Problem.find(params[:id]) |
|
196 | if user.can_request_new_test_pair_for? problem |
|
196 | if user.can_request_new_test_pair_for? problem |
|
197 | assignment = user.get_new_test_pair_assignment_for problem |
|
197 | assignment = user.get_new_test_pair_assignment_for problem |
|
198 | assignment.save |
|
198 | assignment.save |
|
199 |
|
199 | ||
|
200 | send_data(assignment.test_pair.input, |
|
200 | send_data(assignment.test_pair.input, |
|
201 | { :filename => "#{problem.name}-#{assignment.request_number}.in", |
|
201 | { :filename => "#{problem.name}-#{assignment.request_number}.in", |
|
202 | :type => 'text/plain' }) |
|
202 | :type => 'text/plain' }) |
|
203 | else |
|
203 | else |
|
204 | recent_assignment = user.get_recent_test_pair_assignment_for problem |
|
204 | recent_assignment = user.get_recent_test_pair_assignment_for problem |
|
205 | send_data(recent_assignment.test_pair.input, |
|
205 | send_data(recent_assignment.test_pair.input, |
|
206 | { :filename => "#{problem.name}-#{recent_assignment.request_number}.in", |
|
206 | { :filename => "#{problem.name}-#{recent_assignment.request_number}.in", |
|
207 | :type => 'text/plain' }) |
|
207 | :type => 'text/plain' }) |
|
208 | end |
|
208 | end |
|
209 | end |
|
209 | end |
|
210 |
|
210 | ||
|
211 | def submit_solution |
|
211 | def submit_solution |
|
212 | problem = Problem.find(params[:id]) |
|
212 | problem = Problem.find(params[:id]) |
|
213 | user = User.find(session[:user_id]) |
|
213 | user = User.find(session[:user_id]) |
|
214 | recent_assignment = user.get_recent_test_pair_assignment_for problem |
|
214 | recent_assignment = user.get_recent_test_pair_assignment_for problem |
|
215 |
|
215 | ||
|
216 | if Configuration.time_limit_mode? and user.contest_finished? |
|
216 | if Configuration.time_limit_mode? and user.contest_finished? |
|
217 | redirect_to :action => 'list' and return |
|
217 | redirect_to :action => 'list' and return |
|
218 | end |
|
218 | end |
|
219 |
|
219 | ||
|
220 | if recent_assignment == nil |
|
220 | if recent_assignment == nil |
|
221 | flash[:notice] = 'You have not requested for any input data for this problem. Please download an input first.' |
|
221 | flash[:notice] = 'You have not requested for any input data for this problem. Please download an input first.' |
|
222 | session[:current_problem_id] = problem.id |
|
222 | session[:current_problem_id] = problem.id |
|
223 | redirect_to :action => 'list' and return |
|
223 | redirect_to :action => 'list' and return |
|
224 | end |
|
224 | end |
|
225 |
|
225 | ||
|
226 | if recent_assignment.expired? |
|
226 | if recent_assignment.expired? |
|
227 | flash[:notice] = 'The current input is expired. Please download a new input data.' |
|
227 | flash[:notice] = 'The current input is expired. Please download a new input data.' |
|
228 | session[:current_problem_id] = problem.id |
|
228 | session[:current_problem_id] = problem.id |
|
229 | redirect_to :action => 'list' and return |
|
229 | redirect_to :action => 'list' and return |
|
230 | end |
|
230 | end |
|
231 |
|
231 | ||
|
232 | if recent_assignment.submitted |
|
232 | if recent_assignment.submitted |
|
233 | flash[:notice] = 'You have already submitted an incorrect solution for this input. Please download a new input data.' |
|
233 | flash[:notice] = 'You have already submitted an incorrect solution for this input. Please download a new input data.' |
|
234 | session[:current_problem_id] = problem.id |
|
234 | session[:current_problem_id] = problem.id |
|
235 | redirect_to :action => 'list' and return |
|
235 | redirect_to :action => 'list' and return |
|
236 | end |
|
236 | end |
|
237 |
|
237 | ||
|
238 | if params[:file] == nil |
|
238 | if params[:file] == nil |
|
239 | flash[:notice] = 'You have not submitted any output.' |
|
239 | flash[:notice] = 'You have not submitted any output.' |
|
240 | session[:current_problem_id] = problem.id |
|
240 | session[:current_problem_id] = problem.id |
|
241 | redirect_to :action => 'list' and return |
|
241 | redirect_to :action => 'list' and return |
|
242 | end |
|
242 | end |
|
243 |
|
243 | ||
|
244 | submitted_solution = params[:file].read |
|
244 | submitted_solution = params[:file].read |
|
245 | test_pair = recent_assignment.test_pair |
|
245 | test_pair = recent_assignment.test_pair |
|
246 | passed = test_pair.grade(submitted_solution) |
|
246 | passed = test_pair.grade(submitted_solution) |
|
247 | points = passed ? 100 : 0 |
|
247 | points = passed ? 100 : 0 |
|
248 | submission = Submission.new(:user => user, |
|
248 | submission = Submission.new(:user => user, |
|
249 | :problem => problem, |
|
249 | :problem => problem, |
|
250 | :source => submitted_solution, |
|
250 | :source => submitted_solution, |
|
251 | :source_filename => params['file'].original_filename, |
|
251 | :source_filename => params['file'].original_filename, |
|
252 | :language_id => 0, |
|
252 | :language_id => 0, |
|
253 | :submitted_at => Time.new.gmtime, |
|
253 | :submitted_at => Time.new.gmtime, |
|
254 | :graded_at => Time.new.gmtime, |
|
254 | :graded_at => Time.new.gmtime, |
|
255 | :points => points) |
|
255 | :points => points) |
|
256 | submission.save |
|
256 | submission.save |
|
257 | recent_assignment.submitted = true |
|
257 | recent_assignment.submitted = true |
|
258 | recent_assignment.save |
|
258 | recent_assignment.save |
|
259 |
|
259 | ||
|
260 | status = user.get_submission_status_for(problem) |
|
260 | status = user.get_submission_status_for(problem) |
|
261 | if status == nil |
|
261 | if status == nil |
|
262 | status = SubmissionStatus.new :user => user, :problem => problem, :submission_count => 0 |
|
262 | status = SubmissionStatus.new :user => user, :problem => problem, :submission_count => 0 |
|
263 | end |
|
263 | end |
|
264 |
|
264 | ||
|
265 | status.submission_count += 1 |
|
265 | status.submission_count += 1 |
|
266 | status.passed = passed |
|
266 | status.passed = passed |
|
267 | status.save |
|
267 | status.save |
|
268 |
|
268 | ||
|
269 | if passed |
|
269 | if passed |
|
270 | flash[:notice] = 'Correct solution.' |
|
270 | flash[:notice] = 'Correct solution.' |
|
271 | user.update_codejom_status |
|
271 | user.update_codejom_status |
|
272 | else |
|
272 | else |
|
273 | session[:current_problem_id] = problem.id |
|
273 | session[:current_problem_id] = problem.id |
|
274 | flash[:notice] = 'Incorrect solution.' |
|
274 | flash[:notice] = 'Incorrect solution.' |
|
275 | end |
|
275 | end |
|
276 | redirect_to :action => 'list' |
|
276 | redirect_to :action => 'list' |
|
277 | end |
|
277 | end |
|
278 |
|
278 | ||
|
279 | def problems |
|
279 | def problems |
|
280 | prepare_list_information |
|
280 | prepare_list_information |
|
|
281 | + @page_reload_when_view_problem = true | ||
|
281 | render :partial => 'problem_title', :collection => @problems, :as => :problem |
|
282 | render :partial => 'problem_title', :collection => @problems, :as => :problem |
|
282 | end |
|
283 | end |
|
283 |
|
284 | ||
|
284 | def splash |
|
285 | def splash |
|
285 | render :text => '<div class="notice">Most recent task:</span>' |
|
286 | render :text => '<div class="notice">Most recent task:</span>' |
|
286 | end |
|
287 | end |
|
287 |
|
288 | ||
|
288 | protected |
|
289 | protected |
|
289 |
|
290 | ||
|
290 | def prepare_announcements(recent=nil) |
|
291 | def prepare_announcements(recent=nil) |
|
291 | if Configuration.show_tasks_to?(@user) |
|
292 | if Configuration.show_tasks_to?(@user) |
|
292 | @announcements = Announcement.find_published(true) |
|
293 | @announcements = Announcement.find_published(true) |
|
293 | else |
|
294 | else |
|
294 | @announcements = Announcement.find_published |
|
295 | @announcements = Announcement.find_published |
|
295 | end |
|
296 | end |
|
296 | if recent!=nil |
|
297 | if recent!=nil |
|
297 | recent_id = recent.to_i |
|
298 | recent_id = recent.to_i |
|
298 | @announcements = @announcements.find_all { |a| a.id > recent_id } |
|
299 | @announcements = @announcements.find_all { |a| a.id > recent_id } |
|
299 | end |
|
300 | end |
|
300 | end |
|
301 | end |
|
301 |
|
302 | ||
|
302 | def prepare_timeout_information(problems) |
|
303 | def prepare_timeout_information(problems) |
|
303 | @submission_timeouts = {} |
|
304 | @submission_timeouts = {} |
|
304 | problems.each do |problem| |
|
305 | problems.each do |problem| |
|
305 | assignment = @user.get_recent_test_pair_assignment_for(problem) |
|
306 | assignment = @user.get_recent_test_pair_assignment_for(problem) |
|
306 | if assignment == nil |
|
307 | if assignment == nil |
|
307 | timeout = nil |
|
308 | timeout = nil |
|
308 | else |
|
309 | else |
|
309 | if (assignment.expired?) or (assignment.submitted) |
|
310 | if (assignment.expired?) or (assignment.submitted) |
|
310 | timeout = 0 |
|
311 | timeout = 0 |
|
311 | else |
|
312 | else |
|
312 | timeout = assignment.created_at + TEST_ASSIGNMENT_EXPIRATION_DURATION - Time.new.gmtime |
|
313 | timeout = assignment.created_at + TEST_ASSIGNMENT_EXPIRATION_DURATION - Time.new.gmtime |
|
313 | end |
|
314 | end |
|
314 | end |
|
315 | end |
|
315 | @submission_timeouts[problem.id] = timeout |
|
316 | @submission_timeouts[problem.id] = timeout |
|
316 | end |
|
317 | end |
|
317 | @submission_timeouts.each_pair {|k,v| puts "#{k} => #{v}"} |
|
318 | @submission_timeouts.each_pair {|k,v| puts "#{k} => #{v}"} |
|
318 | end |
|
319 | end |
|
319 |
|
320 | ||
|
320 | def prepare_list_information |
|
321 | def prepare_list_information |
|
321 | @user = User.find(session[:user_id]) |
|
322 | @user = User.find(session[:user_id]) |
|
322 |
|
323 | ||
|
323 | all_problems = Problem.find_available_problems |
|
324 | all_problems = Problem.find_available_problems |
|
324 |
|
325 | ||
|
325 | passed = {} |
|
326 | passed = {} |
|
326 | sub_count = {} |
|
327 | sub_count = {} |
|
327 | @user.submission_statuses.each do |status| |
|
328 | @user.submission_statuses.each do |status| |
|
328 | if status.passed |
|
329 | if status.passed |
|
329 | passed[status.problem_id] = true |
|
330 | passed[status.problem_id] = true |
|
330 | end |
|
331 | end |
|
331 | sub_count[status.problem_id] = status.submission_count |
|
332 | sub_count[status.problem_id] = status.submission_count |
|
332 | end |
|
333 | end |
|
333 |
|
334 | ||
|
334 | if session.has_key? :current_problem_id |
|
335 | if session.has_key? :current_problem_id |
|
335 | @current_problem_id = session[:current_problem_id] |
|
336 | @current_problem_id = session[:current_problem_id] |
|
336 | session.delete(:current_problem_id) |
|
337 | session.delete(:current_problem_id) |
|
337 | else |
|
338 | else |
|
|
339 | + if params.has_key? :id | ||
|
|
340 | + @current_problem_id = params[:id].to_i | ||
|
|
341 | + else | ||
|
338 | @current_problem_id = nil |
|
342 | @current_problem_id = nil |
|
339 | end |
|
343 | end |
|
|
344 | + end | ||
|
340 |
|
345 | ||
|
341 | @problems = all_problems.reject { |problem| passed.has_key? problem.id } |
|
346 | @problems = all_problems.reject { |problem| passed.has_key? problem.id } |
|
342 |
|
347 | ||
|
343 | prepare_timeout_information(@problems) |
|
348 | prepare_timeout_information(@problems) |
|
344 |
|
349 | ||
|
345 | @prob_submissions = Array.new |
|
350 | @prob_submissions = Array.new |
|
346 | @problems.each do |p| |
|
351 | @problems.each do |p| |
|
347 | if sub_count.has_key? p.id |
|
352 | if sub_count.has_key? p.id |
|
348 | @prob_submissions << { :count => sub_count[p.id] } |
|
353 | @prob_submissions << { :count => sub_count[p.id] } |
|
349 | else |
|
354 | else |
|
350 | @prob_submissions << { :count => 0 } |
|
355 | @prob_submissions << { :count => 0 } |
|
351 | end |
|
356 | end |
|
352 | end |
|
357 | end |
|
353 | prepare_announcements |
|
358 | prepare_announcements |
|
354 | end |
|
359 | end |
|
355 |
|
360 | ||
|
356 | def check_viewability |
|
361 | def check_viewability |
|
357 | @user = User.find(session[:user_id]) |
|
362 | @user = User.find(session[:user_id]) |
|
358 | if (!Configuration.show_tasks_to?(@user)) and |
|
363 | if (!Configuration.show_tasks_to?(@user)) and |
|
359 | ((action_name=='submission') or (action_name=='submit')) |
|
364 | ((action_name=='submission') or (action_name=='submit')) |
|
360 | redirect_to :action => 'list' and return |
|
365 | redirect_to :action => 'list' and return |
|
361 | end |
|
366 | end |
|
362 | end |
|
367 | end |
|
363 |
|
368 | ||
|
364 | def prepare_grading_result(submission) |
|
369 | def prepare_grading_result(submission) |
|
365 | if Configuration.task_grading_info.has_key? submission.problem.name |
|
370 | if Configuration.task_grading_info.has_key? submission.problem.name |
|
366 | grading_info = Configuration.task_grading_info[submission.problem.name] |
|
371 | grading_info = Configuration.task_grading_info[submission.problem.name] |
|
367 | else |
|
372 | else |
|
368 | # guess task info from problem.full_score |
|
373 | # guess task info from problem.full_score |
|
369 | cases = submission.problem.full_score / 10 |
|
374 | cases = submission.problem.full_score / 10 |
|
370 | grading_info = { |
|
375 | grading_info = { |
|
371 | 'testruns' => cases, |
|
376 | 'testruns' => cases, |
|
372 | 'testcases' => cases |
|
377 | 'testcases' => cases |
|
373 | } |
|
378 | } |
|
374 | end |
|
379 | end |
|
375 | @test_runs = [] |
|
380 | @test_runs = [] |
|
376 | if grading_info['testruns'].is_a? Integer |
|
381 | if grading_info['testruns'].is_a? Integer |
|
377 | trun_count = grading_info['testruns'] |
|
382 | trun_count = grading_info['testruns'] |
|
378 | trun_count.times do |i| |
|
383 | trun_count.times do |i| |
|
379 | @test_runs << [ read_grading_result(@user.login, |
|
384 | @test_runs << [ read_grading_result(@user.login, |
|
380 | submission.problem.name, |
|
385 | submission.problem.name, |
|
381 | submission.id, |
|
386 | submission.id, |
|
382 | i+1) ] |
|
387 | i+1) ] |
|
383 | end |
|
388 | end |
|
384 | else |
|
389 | else |
|
385 | grading_info['testruns'].keys.sort.each do |num| |
|
390 | grading_info['testruns'].keys.sort.each do |num| |
|
386 | run = [] |
|
391 | run = [] |
|
387 | testrun = grading_info['testruns'][num] |
|
392 | testrun = grading_info['testruns'][num] |
|
388 | testrun.each do |c| |
|
393 | testrun.each do |c| |
|
389 | run << read_grading_result(@user.login, |
|
394 | run << read_grading_result(@user.login, |
|
390 | submission.problem.name, |
|
395 | submission.problem.name, |
|
391 | submission.id, |
|
396 | submission.id, |
|
392 | c) |
|
397 | c) |
|
393 | end |
|
398 | end |
|
394 | @test_runs << run |
|
399 | @test_runs << run |
|
395 | end |
|
400 | end |
|
396 | end |
|
401 | end |
|
397 | end |
|
402 | end |
|
398 |
|
403 | ||
|
399 | def grading_result_dir(user_name, problem_name, submission_id, case_num) |
|
404 | def grading_result_dir(user_name, problem_name, submission_id, case_num) |
|
400 | return "#{GRADING_RESULT_DIR}/#{user_name}/#{problem_name}/#{submission_id}/test-result/#{case_num}" |
|
405 | return "#{GRADING_RESULT_DIR}/#{user_name}/#{problem_name}/#{submission_id}/test-result/#{case_num}" |
|
401 | end |
|
406 | end |
|
402 |
|
407 | ||
|
403 | def output_filename(user_name, problem_name, submission_id, case_num) |
|
408 | def output_filename(user_name, problem_name, submission_id, case_num) |
|
404 | dir = grading_result_dir(user_name,problem_name, submission_id, case_num) |
|
409 | dir = grading_result_dir(user_name,problem_name, submission_id, case_num) |
|
405 | return "#{dir}/output.txt" |
|
410 | return "#{dir}/output.txt" |
|
406 | end |
|
411 | end |
|
407 |
|
412 | ||
|
408 | def read_grading_result(user_name, problem_name, submission_id, case_num) |
|
413 | def read_grading_result(user_name, problem_name, submission_id, case_num) |
|
409 | dir = grading_result_dir(user_name,problem_name, submission_id, case_num) |
|
414 | dir = grading_result_dir(user_name,problem_name, submission_id, case_num) |
|
410 | result_file_name = "#{dir}/result" |
|
415 | result_file_name = "#{dir}/result" |
|
411 | if !FileTest.exists?(result_file_name) |
|
416 | if !FileTest.exists?(result_file_name) |
|
412 | return {:num => case_num, :msg => 'program did not run'} |
|
417 | return {:num => case_num, :msg => 'program did not run'} |
|
413 | else |
|
418 | else |
|
414 | results = File.open(result_file_name).readlines |
|
419 | results = File.open(result_file_name).readlines |
|
415 | run_stat = extract_running_stat(results) |
|
420 | run_stat = extract_running_stat(results) |
|
416 | output_filename = "#{dir}/output.txt" |
|
421 | output_filename = "#{dir}/output.txt" |
|
417 | if FileTest.exists?(output_filename) |
|
422 | if FileTest.exists?(output_filename) |
|
418 | output_file = true |
|
423 | output_file = true |
|
419 | output_size = File.size(output_filename) |
|
424 | output_size = File.size(output_filename) |
|
420 | else |
|
425 | else |
|
421 | output_file = false |
|
426 | output_file = false |
|
422 | output_size = 0 |
|
427 | output_size = 0 |
|
423 | end |
|
428 | end |
|
424 |
|
429 | ||
|
425 | return { |
|
430 | return { |
|
426 | :num => case_num, |
|
431 | :num => case_num, |
|
427 | :msg => results[0], |
|
432 | :msg => results[0], |
|
428 | :run_stat => run_stat, |
|
433 | :run_stat => run_stat, |
|
429 | :output => output_file, |
|
434 | :output => output_file, |
|
430 | :output_size => output_size |
|
435 | :output_size => output_size |
|
431 | } |
|
436 | } |
|
432 | end |
|
437 | end |
|
433 | end |
|
438 | end |
|
434 |
|
439 | ||
|
435 | # copied from grader/script/lib/test_request_helper.rb |
|
440 | # copied from grader/script/lib/test_request_helper.rb |
|
436 | def extract_running_stat(results) |
|
441 | def extract_running_stat(results) |
|
437 | running_stat_line = results[-1] |
|
442 | running_stat_line = results[-1] |
|
438 |
|
443 | ||
|
439 | # extract exit status line |
|
444 | # extract exit status line |
|
440 | run_stat = "" |
|
445 | run_stat = "" |
|
441 | if !(/[Cc]orrect/.match(results[0])) |
|
446 | if !(/[Cc]orrect/.match(results[0])) |
|
442 | run_stat = results[0].chomp |
|
447 | run_stat = results[0].chomp |
|
443 | else |
|
448 | else |
|
444 | run_stat = 'Program exited normally' |
|
449 | run_stat = 'Program exited normally' |
|
445 | end |
|
450 | end |
|
446 |
|
451 | ||
|
447 | logger.info "Stat line: #{running_stat_line}" |
|
452 | logger.info "Stat line: #{running_stat_line}" |
|
448 |
|
453 | ||
|
449 | # extract running time |
|
454 | # extract running time |
|
450 | if res = /r(.*)u(.*)s/.match(running_stat_line) |
|
455 | if res = /r(.*)u(.*)s/.match(running_stat_line) |
|
451 | seconds = (res[1].to_f + res[2].to_f) |
|
456 | seconds = (res[1].to_f + res[2].to_f) |
|
452 | time_stat = "Time used: #{seconds} sec." |
|
457 | time_stat = "Time used: #{seconds} sec." |
|
453 | else |
|
458 | else |
|
454 | seconds = nil |
|
459 | seconds = nil |
|
455 | time_stat = "Time used: n/a sec." |
|
460 | time_stat = "Time used: n/a sec." |
|
456 | end |
|
461 | end |
|
457 |
|
462 | ||
|
458 | # extract memory usage |
|
463 | # extract memory usage |
|
459 | if res = /s(.*)m/.match(running_stat_line) |
|
464 | if res = /s(.*)m/.match(running_stat_line) |
|
460 | memory_used = res[1].to_i |
|
465 | memory_used = res[1].to_i |
|
461 | else |
|
466 | else |
|
462 | memory_used = -1 |
|
467 | memory_used = -1 |
|
463 | end |
|
468 | end |
|
464 |
|
469 | ||
|
465 | return { |
|
470 | return { |
|
466 | :msg => "#{run_stat}\n#{time_stat}", |
|
471 | :msg => "#{run_stat}\n#{time_stat}", |
|
467 | :running_time => seconds, |
|
472 | :running_time => seconds, |
|
468 | :exit_status => run_stat, |
|
473 | :exit_status => run_stat, |
|
469 | :memory_usage => memory_used |
|
474 | :memory_usage => memory_used |
|
470 | } |
|
475 | } |
|
471 | end |
|
476 | end |
|
472 |
|
477 | ||
|
473 | def update_user_start_time |
|
478 | def update_user_start_time |
|
474 | user = User.find(session[:user_id]) |
|
479 | user = User.find(session[:user_id]) |
|
475 | UserContestStat.update_user_start_time(user) |
|
480 | UserContestStat.update_user_start_time(user) |
|
476 | end |
|
481 | end |
|
477 |
|
482 | ||
|
478 | def reject_announcement_refresh_when_logged_out |
|
483 | def reject_announcement_refresh_when_logged_out |
|
479 | if not session[:user_id] |
|
484 | if not session[:user_id] |
|
480 | render :text => 'Access forbidden', :status => 403 |
|
485 | render :text => 'Access forbidden', :status => 403 |
|
481 | end |
|
486 | end |
|
482 | end |
|
487 | end |
|
483 |
|
488 | ||
|
484 | end |
|
489 | end |
|
485 |
|
490 |
deleted file |
You need to be logged in to leave comments.
Login now