Description:
shows recent problem after wrong submissions
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r223:1586858ff9d5 - - 4 files changed: 32 inserted, 12 deleted
@@ -105,274 +105,287 | |||||
|
105 | if params[:id]==nil |
|
105 | if params[:id]==nil |
|
106 | @problem = nil |
|
106 | @problem = nil |
|
107 | @submissions = nil |
|
107 | @submissions = nil |
|
108 | else |
|
108 | else |
|
109 | @problem = Problem.find_by_name(params[:id]) |
|
109 | @problem = Problem.find_by_name(params[:id]) |
|
110 | if not @problem.available |
|
110 | if not @problem.available |
|
111 | redirect_to :action => 'list' |
|
111 | redirect_to :action => 'list' |
|
112 | flash[:notice] = 'Error: submissions for that problem are not viewable.' |
|
112 | flash[:notice] = 'Error: submissions for that problem are not viewable.' |
|
113 | return |
|
113 | return |
|
114 | end |
|
114 | end |
|
115 | @submissions = Submission.find_all_by_user_problem(@user.id, @problem.id) |
|
115 | @submissions = Submission.find_all_by_user_problem(@user.id, @problem.id) |
|
116 | end |
|
116 | end |
|
117 | end |
|
117 | end |
|
118 |
|
118 | ||
|
119 | def result |
|
119 | def result |
|
120 | if !Configuration.show_grading_result |
|
120 | if !Configuration.show_grading_result |
|
121 | redirect_to :action => 'list' and return |
|
121 | redirect_to :action => 'list' and return |
|
122 | end |
|
122 | end |
|
123 | @user = User.find(session[:user_id]) |
|
123 | @user = User.find(session[:user_id]) |
|
124 | @submission = Submission.find(params[:id]) |
|
124 | @submission = Submission.find(params[:id]) |
|
125 | if @submission.user!=@user |
|
125 | if @submission.user!=@user |
|
126 | flash[:notice] = 'You are not allowed to view result of other users.' |
|
126 | flash[:notice] = 'You are not allowed to view result of other users.' |
|
127 | redirect_to :action => 'list' and return |
|
127 | redirect_to :action => 'list' and return |
|
128 | end |
|
128 | end |
|
129 | prepare_grading_result(@submission) |
|
129 | prepare_grading_result(@submission) |
|
130 | end |
|
130 | end |
|
131 |
|
131 | ||
|
132 | def load_output |
|
132 | def load_output |
|
133 | if !Configuration.show_grading_result or params[:num]==nil |
|
133 | if !Configuration.show_grading_result or params[:num]==nil |
|
134 | redirect_to :action => 'list' and return |
|
134 | redirect_to :action => 'list' and return |
|
135 | end |
|
135 | end |
|
136 | @user = User.find(session[:user_id]) |
|
136 | @user = User.find(session[:user_id]) |
|
137 | @submission = Submission.find(params[:id]) |
|
137 | @submission = Submission.find(params[:id]) |
|
138 | if @submission.user!=@user |
|
138 | if @submission.user!=@user |
|
139 | flash[:notice] = 'You are not allowed to view result of other users.' |
|
139 | flash[:notice] = 'You are not allowed to view result of other users.' |
|
140 | redirect_to :action => 'list' and return |
|
140 | redirect_to :action => 'list' and return |
|
141 | end |
|
141 | end |
|
142 | case_num = params[:num].to_i |
|
142 | case_num = params[:num].to_i |
|
143 | out_filename = output_filename(@user.login, |
|
143 | out_filename = output_filename(@user.login, |
|
144 | @submission.problem.name, |
|
144 | @submission.problem.name, |
|
145 | @submission.id, |
|
145 | @submission.id, |
|
146 | case_num) |
|
146 | case_num) |
|
147 | if !FileTest.exists?(out_filename) |
|
147 | if !FileTest.exists?(out_filename) |
|
148 | flash[:notice] = 'Output not found.' |
|
148 | flash[:notice] = 'Output not found.' |
|
149 | redirect_to :action => 'list' and return |
|
149 | redirect_to :action => 'list' and return |
|
150 | end |
|
150 | end |
|
151 |
|
151 | ||
|
152 | response.headers['Content-Type'] = "application/force-download" |
|
152 | response.headers['Content-Type'] = "application/force-download" |
|
153 | response.headers['Content-Disposition'] = "attachment; filename=\"output-#{case_num}.txt\"" |
|
153 | response.headers['Content-Disposition'] = "attachment; filename=\"output-#{case_num}.txt\"" |
|
154 | response.headers["X-Sendfile"] = out_filename |
|
154 | response.headers["X-Sendfile"] = out_filename |
|
155 | response.headers['Content-length'] = File.size(out_filename) |
|
155 | response.headers['Content-length'] = File.size(out_filename) |
|
156 | render :nothing => true |
|
156 | render :nothing => true |
|
157 | end |
|
157 | end |
|
158 |
|
158 | ||
|
159 | def error |
|
159 | def error |
|
160 | @user = User.find(session[:user_id]) |
|
160 | @user = User.find(session[:user_id]) |
|
161 | end |
|
161 | end |
|
162 |
|
162 | ||
|
163 | # announcement refreshing and hiding methods |
|
163 | # announcement refreshing and hiding methods |
|
164 |
|
164 | ||
|
165 | def announcements |
|
165 | def announcements |
|
166 | if params.has_key? 'recent' |
|
166 | if params.has_key? 'recent' |
|
167 | prepare_announcements(params[:recent]) |
|
167 | prepare_announcements(params[:recent]) |
|
168 | else |
|
168 | else |
|
169 | prepare_announcements |
|
169 | prepare_announcements |
|
170 | end |
|
170 | end |
|
171 | render(:partial => 'announcement', |
|
171 | render(:partial => 'announcement', |
|
172 | :collection => @announcements, |
|
172 | :collection => @announcements, |
|
173 | :locals => {:announcement_effect => true}) |
|
173 | :locals => {:announcement_effect => true}) |
|
174 | end |
|
174 | end |
|
175 |
|
175 | ||
|
176 | # |
|
176 | # |
|
177 | # actions for Code Jom |
|
177 | # actions for Code Jom |
|
178 | # |
|
178 | # |
|
179 | def download_input |
|
179 | def download_input |
|
180 | problem = Problem.find(params[:id]) |
|
180 | problem = Problem.find(params[:id]) |
|
181 | user = User.find(session[:user_id]) |
|
181 | user = User.find(session[:user_id]) |
|
182 | if user.can_request_new_test_pair_for? problem |
|
182 | if user.can_request_new_test_pair_for? problem |
|
183 | assignment = user.get_new_test_pair_assignment_for problem |
|
183 | assignment = user.get_new_test_pair_assignment_for problem |
|
184 | assignment.save |
|
184 | assignment.save |
|
185 |
|
185 | ||
|
186 | send_data(assignment.test_pair.input, |
|
186 | send_data(assignment.test_pair.input, |
|
187 | { :filename => "#{problem.name}-#{assignment.request_number}.in", |
|
187 | { :filename => "#{problem.name}-#{assignment.request_number}.in", |
|
188 | :type => 'text/plain' }) |
|
188 | :type => 'text/plain' }) |
|
189 | else |
|
189 | else |
|
190 | recent_assignment = user.get_recent_test_pair_assignment_for problem |
|
190 | recent_assignment = user.get_recent_test_pair_assignment_for problem |
|
191 | send_data(recent_assignment.test_pair.input, |
|
191 | send_data(recent_assignment.test_pair.input, |
|
192 | { :filename => "#{problem.name}-#{recent_assignment.request_number}.in", |
|
192 | { :filename => "#{problem.name}-#{recent_assignment.request_number}.in", |
|
193 | :type => 'text/plain' }) |
|
193 | :type => 'text/plain' }) |
|
194 | end |
|
194 | end |
|
195 | end |
|
195 | end |
|
196 |
|
196 | ||
|
197 | def submit_solution |
|
197 | def submit_solution |
|
198 | problem = Problem.find(params[:id]) |
|
198 | problem = Problem.find(params[:id]) |
|
199 | user = User.find(session[:user_id]) |
|
199 | user = User.find(session[:user_id]) |
|
200 | recent_assignment = user.get_recent_test_pair_assignment_for problem |
|
200 | recent_assignment = user.get_recent_test_pair_assignment_for problem |
|
|
201 | + | ||
|
201 | if recent_assignment == nil |
|
202 | if recent_assignment == nil |
|
202 | flash[:notice] = 'You have not requested for any input data for this problem. Please download an input first.' |
|
203 | flash[:notice] = 'You have not requested for any input data for this problem. Please download an input first.' |
|
|
204 | + session[:current_problem_id] = problem.id | ||
|
203 | redirect_to :action => 'list' and return |
|
205 | redirect_to :action => 'list' and return |
|
204 | end |
|
206 | end |
|
205 |
|
207 | ||
|
206 | if recent_assignment.expired? |
|
208 | if recent_assignment.expired? |
|
207 | flash[:notice] = 'The current input is expired. Please download a new input data.' |
|
209 | flash[:notice] = 'The current input is expired. Please download a new input data.' |
|
|
210 | + session[:current_problem_id] = problem.id | ||
|
208 | redirect_to :action => 'list' and return |
|
211 | redirect_to :action => 'list' and return |
|
209 | end |
|
212 | end |
|
210 |
|
213 | ||
|
211 | if recent_assignment.submitted |
|
214 | if recent_assignment.submitted |
|
212 | flash[:notice] = 'You have already submitted an incorrect solution for this input. Please download a new input data.' |
|
215 | flash[:notice] = 'You have already submitted an incorrect solution for this input. Please download a new input data.' |
|
|
216 | + session[:current_problem_id] = problem.id | ||
|
213 | redirect_to :action => 'list' and return |
|
217 | redirect_to :action => 'list' and return |
|
214 | end |
|
218 | end |
|
215 |
|
219 | ||
|
216 | if params[:file] == nil |
|
220 | if params[:file] == nil |
|
217 | flash[:notice] = 'You have not submitted any output.' |
|
221 | flash[:notice] = 'You have not submitted any output.' |
|
|
222 | + session[:current_problem_id] = problem.id | ||
|
218 | redirect_to :action => 'list' and return |
|
223 | redirect_to :action => 'list' and return |
|
219 | end |
|
224 | end |
|
220 |
|
225 | ||
|
221 | submitted_solution = params[:file].read |
|
226 | submitted_solution = params[:file].read |
|
222 | test_pair = recent_assignment.test_pair |
|
227 | test_pair = recent_assignment.test_pair |
|
223 | passed = test_pair.grade(submitted_solution) |
|
228 | passed = test_pair.grade(submitted_solution) |
|
224 | points = passed ? 100 : 0 |
|
229 | points = passed ? 100 : 0 |
|
225 | submission = Submission.new(:user => user, |
|
230 | submission = Submission.new(:user => user, |
|
226 | :problem => problem, |
|
231 | :problem => problem, |
|
227 | :source => submitted_solution, |
|
232 | :source => submitted_solution, |
|
228 | :source_filename => params['file'].original_filename, |
|
233 | :source_filename => params['file'].original_filename, |
|
229 | :language_id => 0, |
|
234 | :language_id => 0, |
|
230 | :submitted_at => Time.new.gmtime, |
|
235 | :submitted_at => Time.new.gmtime, |
|
231 | :graded_at => Time.new.gmtime, |
|
236 | :graded_at => Time.new.gmtime, |
|
232 | :points => points) |
|
237 | :points => points) |
|
233 | submission.save |
|
238 | submission.save |
|
234 | recent_assignment.submitted = true |
|
239 | recent_assignment.submitted = true |
|
235 | recent_assignment.save |
|
240 | recent_assignment.save |
|
236 |
|
241 | ||
|
237 | status = user.get_submission_status_for(problem) |
|
242 | status = user.get_submission_status_for(problem) |
|
238 | if status == nil |
|
243 | if status == nil |
|
239 | status = SubmissionStatus.new :user => user, :problem => problem, :submission_count => 0 |
|
244 | status = SubmissionStatus.new :user => user, :problem => problem, :submission_count => 0 |
|
240 | end |
|
245 | end |
|
241 |
|
246 | ||
|
242 | status.submission_count += 1 |
|
247 | status.submission_count += 1 |
|
243 | status.passed = passed |
|
248 | status.passed = passed |
|
244 | status.save |
|
249 | status.save |
|
245 |
|
250 | ||
|
246 | if passed |
|
251 | if passed |
|
247 | flash[:notice] = 'Correct solution.' |
|
252 | flash[:notice] = 'Correct solution.' |
|
248 | user.update_codejom_status |
|
253 | user.update_codejom_status |
|
249 | else |
|
254 | else |
|
|
255 | + session[:current_problem_id] = problem.id | ||
|
250 | flash[:notice] = 'Incorrect solution.' |
|
256 | flash[:notice] = 'Incorrect solution.' |
|
251 | end |
|
257 | end |
|
252 | redirect_to :action => 'list' |
|
258 | redirect_to :action => 'list' |
|
253 | end |
|
259 | end |
|
254 |
|
260 | ||
|
255 | protected |
|
261 | protected |
|
256 |
|
262 | ||
|
257 | def prepare_announcements(recent=nil) |
|
263 | def prepare_announcements(recent=nil) |
|
258 | if Configuration.show_tasks_to?(@user) |
|
264 | if Configuration.show_tasks_to?(@user) |
|
259 | @announcements = Announcement.find_published(true) |
|
265 | @announcements = Announcement.find_published(true) |
|
260 | else |
|
266 | else |
|
261 | @announcements = Announcement.find_published |
|
267 | @announcements = Announcement.find_published |
|
262 | end |
|
268 | end |
|
263 | if recent!=nil |
|
269 | if recent!=nil |
|
264 | recent_id = recent.to_i |
|
270 | recent_id = recent.to_i |
|
265 | @announcements = @announcements.find_all { |a| a.id > recent_id } |
|
271 | @announcements = @announcements.find_all { |a| a.id > recent_id } |
|
266 | end |
|
272 | end |
|
267 | end |
|
273 | end |
|
268 |
|
274 | ||
|
269 | def prepare_list_information |
|
275 | def prepare_list_information |
|
270 | @user = User.find(session[:user_id]) |
|
276 | @user = User.find(session[:user_id]) |
|
271 |
|
277 | ||
|
272 | all_problems = Problem.find_available_problems |
|
278 | all_problems = Problem.find_available_problems |
|
273 |
|
279 | ||
|
274 | passed = {} |
|
280 | passed = {} |
|
275 | sub_count = {} |
|
281 | sub_count = {} |
|
276 | @user.submission_statuses.each do |status| |
|
282 | @user.submission_statuses.each do |status| |
|
277 | if status.passed |
|
283 | if status.passed |
|
278 | passed[status.problem_id] = true |
|
284 | passed[status.problem_id] = true |
|
279 | end |
|
285 | end |
|
280 | sub_count[status.problem_id] = status.submission_count |
|
286 | sub_count[status.problem_id] = status.submission_count |
|
281 | end |
|
287 | end |
|
282 |
|
288 | ||
|
|
289 | + if session.has_key? :current_problem_id | ||
|
|
290 | + @current_problem_id = session[:current_problem_id] | ||
|
|
291 | + session.delete(:current_problem_id) | ||
|
|
292 | + else | ||
|
|
293 | + @current_problem_id = nil | ||
|
|
294 | + end | ||
|
|
295 | + | ||
|
283 | @problems = all_problems.reject { |problem| passed.has_key? problem.id } |
|
296 | @problems = all_problems.reject { |problem| passed.has_key? problem.id } |
|
284 |
|
297 | ||
|
285 | @prob_submissions = Array.new |
|
298 | @prob_submissions = Array.new |
|
286 | @problems.each do |p| |
|
299 | @problems.each do |p| |
|
287 | if sub_count.has_key? p.id |
|
300 | if sub_count.has_key? p.id |
|
288 | @prob_submissions << { :count => sub_count[p.id] } |
|
301 | @prob_submissions << { :count => sub_count[p.id] } |
|
289 | else |
|
302 | else |
|
290 | @prob_submissions << { :count => 0 } |
|
303 | @prob_submissions << { :count => 0 } |
|
291 | end |
|
304 | end |
|
292 | end |
|
305 | end |
|
293 | prepare_announcements |
|
306 | prepare_announcements |
|
294 | end |
|
307 | end |
|
295 |
|
308 | ||
|
296 | def check_viewability |
|
309 | def check_viewability |
|
297 | @user = User.find(session[:user_id]) |
|
310 | @user = User.find(session[:user_id]) |
|
298 | if (!Configuration.show_tasks_to?(@user)) and |
|
311 | if (!Configuration.show_tasks_to?(@user)) and |
|
299 | ((action_name=='submission') or (action_name=='submit')) |
|
312 | ((action_name=='submission') or (action_name=='submit')) |
|
300 | redirect_to :action => 'list' and return |
|
313 | redirect_to :action => 'list' and return |
|
301 | end |
|
314 | end |
|
302 | end |
|
315 | end |
|
303 |
|
316 | ||
|
304 | def prepare_grading_result(submission) |
|
317 | def prepare_grading_result(submission) |
|
305 | if Configuration.task_grading_info.has_key? submission.problem.name |
|
318 | if Configuration.task_grading_info.has_key? submission.problem.name |
|
306 | grading_info = Configuration.task_grading_info[submission.problem.name] |
|
319 | grading_info = Configuration.task_grading_info[submission.problem.name] |
|
307 | else |
|
320 | else |
|
308 | # guess task info from problem.full_score |
|
321 | # guess task info from problem.full_score |
|
309 | cases = submission.problem.full_score / 10 |
|
322 | cases = submission.problem.full_score / 10 |
|
310 | grading_info = { |
|
323 | grading_info = { |
|
311 | 'testruns' => cases, |
|
324 | 'testruns' => cases, |
|
312 | 'testcases' => cases |
|
325 | 'testcases' => cases |
|
313 | } |
|
326 | } |
|
314 | end |
|
327 | end |
|
315 | @test_runs = [] |
|
328 | @test_runs = [] |
|
316 | if grading_info['testruns'].is_a? Integer |
|
329 | if grading_info['testruns'].is_a? Integer |
|
317 | trun_count = grading_info['testruns'] |
|
330 | trun_count = grading_info['testruns'] |
|
318 | trun_count.times do |i| |
|
331 | trun_count.times do |i| |
|
319 | @test_runs << [ read_grading_result(@user.login, |
|
332 | @test_runs << [ read_grading_result(@user.login, |
|
320 | submission.problem.name, |
|
333 | submission.problem.name, |
|
321 | submission.id, |
|
334 | submission.id, |
|
322 | i+1) ] |
|
335 | i+1) ] |
|
323 | end |
|
336 | end |
|
324 | else |
|
337 | else |
|
325 | grading_info['testruns'].keys.sort.each do |num| |
|
338 | grading_info['testruns'].keys.sort.each do |num| |
|
326 | run = [] |
|
339 | run = [] |
|
327 | testrun = grading_info['testruns'][num] |
|
340 | testrun = grading_info['testruns'][num] |
|
328 | testrun.each do |c| |
|
341 | testrun.each do |c| |
|
329 | run << read_grading_result(@user.login, |
|
342 | run << read_grading_result(@user.login, |
|
330 | submission.problem.name, |
|
343 | submission.problem.name, |
|
331 | submission.id, |
|
344 | submission.id, |
|
332 | c) |
|
345 | c) |
|
333 | end |
|
346 | end |
|
334 | @test_runs << run |
|
347 | @test_runs << run |
|
335 | end |
|
348 | end |
|
336 | end |
|
349 | end |
|
337 | end |
|
350 | end |
|
338 |
|
351 | ||
|
339 | def grading_result_dir(user_name, problem_name, submission_id, case_num) |
|
352 | def grading_result_dir(user_name, problem_name, submission_id, case_num) |
|
340 | return "#{GRADING_RESULT_DIR}/#{user_name}/#{problem_name}/#{submission_id}/test-result/#{case_num}" |
|
353 | return "#{GRADING_RESULT_DIR}/#{user_name}/#{problem_name}/#{submission_id}/test-result/#{case_num}" |
|
341 | end |
|
354 | end |
|
342 |
|
355 | ||
|
343 | def output_filename(user_name, problem_name, submission_id, case_num) |
|
356 | def output_filename(user_name, problem_name, submission_id, case_num) |
|
344 | dir = grading_result_dir(user_name,problem_name, submission_id, case_num) |
|
357 | dir = grading_result_dir(user_name,problem_name, submission_id, case_num) |
|
345 | return "#{dir}/output.txt" |
|
358 | return "#{dir}/output.txt" |
|
346 | end |
|
359 | end |
|
347 |
|
360 | ||
|
348 | def read_grading_result(user_name, problem_name, submission_id, case_num) |
|
361 | def read_grading_result(user_name, problem_name, submission_id, case_num) |
|
349 | dir = grading_result_dir(user_name,problem_name, submission_id, case_num) |
|
362 | dir = grading_result_dir(user_name,problem_name, submission_id, case_num) |
|
350 | result_file_name = "#{dir}/result" |
|
363 | result_file_name = "#{dir}/result" |
|
351 | if !FileTest.exists?(result_file_name) |
|
364 | if !FileTest.exists?(result_file_name) |
|
352 | return {:num => case_num, :msg => 'program did not run'} |
|
365 | return {:num => case_num, :msg => 'program did not run'} |
|
353 | else |
|
366 | else |
|
354 | results = File.open(result_file_name).readlines |
|
367 | results = File.open(result_file_name).readlines |
|
355 | run_stat = extract_running_stat(results) |
|
368 | run_stat = extract_running_stat(results) |
|
356 | output_filename = "#{dir}/output.txt" |
|
369 | output_filename = "#{dir}/output.txt" |
|
357 | if FileTest.exists?(output_filename) |
|
370 | if FileTest.exists?(output_filename) |
|
358 | output_file = true |
|
371 | output_file = true |
|
359 | output_size = File.size(output_filename) |
|
372 | output_size = File.size(output_filename) |
|
360 | else |
|
373 | else |
|
361 | output_file = false |
|
374 | output_file = false |
|
362 | output_size = 0 |
|
375 | output_size = 0 |
|
363 | end |
|
376 | end |
|
364 |
|
377 | ||
|
365 | return { |
|
378 | return { |
|
366 | :num => case_num, |
|
379 | :num => case_num, |
|
367 | :msg => results[0], |
|
380 | :msg => results[0], |
|
368 | :run_stat => run_stat, |
|
381 | :run_stat => run_stat, |
|
369 | :output => output_file, |
|
382 | :output => output_file, |
|
370 | :output_size => output_size |
|
383 | :output_size => output_size |
|
371 | } |
|
384 | } |
|
372 | end |
|
385 | end |
|
373 | end |
|
386 | end |
|
374 |
|
387 | ||
|
375 | # copied from grader/script/lib/test_request_helper.rb |
|
388 | # copied from grader/script/lib/test_request_helper.rb |
|
376 | def extract_running_stat(results) |
|
389 | def extract_running_stat(results) |
|
377 | running_stat_line = results[-1] |
|
390 | running_stat_line = results[-1] |
|
378 |
|
391 |
@@ -1,120 +1,124 | |||||
|
1 | class Problem < ActiveRecord::Base |
|
1 | class Problem < ActiveRecord::Base |
|
2 |
|
2 | ||
|
3 | belongs_to :description |
|
3 | belongs_to :description |
|
4 | has_many :test_pairs, :dependent => :delete_all |
|
4 | has_many :test_pairs, :dependent => :delete_all |
|
5 |
|
5 | ||
|
6 | validates_presence_of :name |
|
6 | validates_presence_of :name |
|
7 | validates_format_of :name, :with => /^\w+$/ |
|
7 | validates_format_of :name, :with => /^\w+$/ |
|
8 | validates_presence_of :full_name |
|
8 | validates_presence_of :full_name |
|
9 |
|
9 | ||
|
10 | DEFAULT_TIME_LIMIT = 1 |
|
10 | DEFAULT_TIME_LIMIT = 1 |
|
11 | DEFAULT_MEMORY_LIMIT = 32 |
|
11 | DEFAULT_MEMORY_LIMIT = 32 |
|
12 |
|
12 | ||
|
13 | def test_pair_count |
|
13 | def test_pair_count |
|
14 | @test_pair_count ||= test_pairs.size |
|
14 | @test_pair_count ||= test_pairs.size |
|
15 | end |
|
15 | end |
|
16 |
|
16 | ||
|
17 | def uses_random_test_pair? |
|
17 | def uses_random_test_pair? |
|
18 | test_pair_count != 0 |
|
18 | test_pair_count != 0 |
|
19 | end |
|
19 | end |
|
20 |
|
20 | ||
|
21 | def random_test_pair(forbidden_numbers=nil) |
|
21 | def random_test_pair(forbidden_numbers=nil) |
|
22 | - begin |
|
22 | + if forbidden_numbers.length < test_pair_count |
|
|
23 | + begin | ||
|
|
24 | + test_num = 1 + rand(test_pair_count) | ||
|
|
25 | + end while forbidden_numbers!=nil and forbidden_numbers.include? test_num | ||
|
|
26 | + else | ||
|
23 | test_num = 1 + rand(test_pair_count) |
|
27 | test_num = 1 + rand(test_pair_count) |
|
24 | - end while forbidden_numbers!=nil and forbidden_numbers.include? test_num |
|
28 | + end |
|
25 | test_pairs.find_by_number test_num |
|
29 | test_pairs.find_by_number test_num |
|
26 | end |
|
30 | end |
|
27 |
|
31 | ||
|
28 | def self.find_available_problems |
|
32 | def self.find_available_problems |
|
29 | find(:all, :conditions => {:available => true}, :order => "date_added DESC") |
|
33 | find(:all, :conditions => {:available => true}, :order => "date_added DESC") |
|
30 | end |
|
34 | end |
|
31 |
|
35 | ||
|
32 | # TODO: may try to optimize this using cache |
|
36 | # TODO: may try to optimize this using cache |
|
33 | def self.available_problem_count |
|
37 | def self.available_problem_count |
|
34 | return Problem.find_available_problems.length |
|
38 | return Problem.find_available_problems.length |
|
35 | end |
|
39 | end |
|
36 |
|
40 | ||
|
37 | def self.create_from_import_form_params(params, old_problem=nil) |
|
41 | def self.create_from_import_form_params(params, old_problem=nil) |
|
38 | problem = old_problem || Problem.new |
|
42 | problem = old_problem || Problem.new |
|
39 | import_params = Problem.extract_params_and_check(params, problem) |
|
43 | import_params = Problem.extract_params_and_check(params, problem) |
|
40 |
|
44 | ||
|
41 | if not problem.valid? |
|
45 | if not problem.valid? |
|
42 | return problem, 'Error importing' |
|
46 | return problem, 'Error importing' |
|
43 | end |
|
47 | end |
|
44 |
|
48 | ||
|
45 | problem.full_score = 100 |
|
49 | problem.full_score = 100 |
|
46 | problem.date_added = Time.new |
|
50 | problem.date_added = Time.new |
|
47 | problem.test_allowed = true |
|
51 | problem.test_allowed = true |
|
48 | problem.output_only = false |
|
52 | problem.output_only = false |
|
49 | problem.available = false |
|
53 | problem.available = false |
|
50 |
|
54 | ||
|
51 | if not problem.save |
|
55 | if not problem.save |
|
52 | return problem, 'Error importing' |
|
56 | return problem, 'Error importing' |
|
53 | end |
|
57 | end |
|
54 |
|
58 | ||
|
55 | import_to_db = params.has_key? :import_to_db |
|
59 | import_to_db = params.has_key? :import_to_db |
|
56 |
|
60 | ||
|
57 | importer = TestdataImporter.new(problem) |
|
61 | importer = TestdataImporter.new(problem) |
|
58 |
|
62 | ||
|
59 | if not importer.import_from_file(import_params[:file], |
|
63 | if not importer.import_from_file(import_params[:file], |
|
60 | import_params[:time_limit], |
|
64 | import_params[:time_limit], |
|
61 | import_params[:memory_limit], |
|
65 | import_params[:memory_limit], |
|
62 | import_to_db) |
|
66 | import_to_db) |
|
63 | problem.errors.add_to_base('Import error.') |
|
67 | problem.errors.add_to_base('Import error.') |
|
64 | end |
|
68 | end |
|
65 |
|
69 | ||
|
66 | return problem, importer.log_msg |
|
70 | return problem, importer.log_msg |
|
67 | end |
|
71 | end |
|
68 |
|
72 | ||
|
69 | protected |
|
73 | protected |
|
70 |
|
74 | ||
|
71 | def self.to_i_or_default(st, default) |
|
75 | def self.to_i_or_default(st, default) |
|
72 | if st!='' |
|
76 | if st!='' |
|
73 | st.to_i |
|
77 | st.to_i |
|
74 | else |
|
78 | else |
|
75 | default |
|
79 | default |
|
76 | end |
|
80 | end |
|
77 | end |
|
81 | end |
|
78 |
|
82 | ||
|
79 | def self.extract_params_and_check(params, problem) |
|
83 | def self.extract_params_and_check(params, problem) |
|
80 | time_limit = Problem.to_i_or_default(params[:time_limit], |
|
84 | time_limit = Problem.to_i_or_default(params[:time_limit], |
|
81 | DEFAULT_TIME_LIMIT) |
|
85 | DEFAULT_TIME_LIMIT) |
|
82 | memory_limit = Problem.to_i_or_default(params[:memory_limit], |
|
86 | memory_limit = Problem.to_i_or_default(params[:memory_limit], |
|
83 | DEFAULT_MEMORY_LIMIT) |
|
87 | DEFAULT_MEMORY_LIMIT) |
|
84 |
|
88 | ||
|
85 | if time_limit==0 and time_limit_s!='0' |
|
89 | if time_limit==0 and time_limit_s!='0' |
|
86 | problem.errors.add_to_base('Time limit format errors.') |
|
90 | problem.errors.add_to_base('Time limit format errors.') |
|
87 | elsif time_limit<=0 or time_limit >60 |
|
91 | elsif time_limit<=0 or time_limit >60 |
|
88 | problem.errors.add_to_base('Time limit out of range.') |
|
92 | problem.errors.add_to_base('Time limit out of range.') |
|
89 | end |
|
93 | end |
|
90 |
|
94 | ||
|
91 | if memory_limit==0 and memory_limit_s!='0' |
|
95 | if memory_limit==0 and memory_limit_s!='0' |
|
92 | problem.errors.add_to_base('Memory limit format errors.') |
|
96 | problem.errors.add_to_base('Memory limit format errors.') |
|
93 | elsif memory_limit<=0 or memory_limit >512 |
|
97 | elsif memory_limit<=0 or memory_limit >512 |
|
94 | problem.errors.add_to_base('Memory limit out of range.') |
|
98 | problem.errors.add_to_base('Memory limit out of range.') |
|
95 | end |
|
99 | end |
|
96 |
|
100 | ||
|
97 | if params[:file]==nil or params[:file]=='' |
|
101 | if params[:file]==nil or params[:file]=='' |
|
98 | problem.errors.add_to_base('No testdata file.') |
|
102 | problem.errors.add_to_base('No testdata file.') |
|
99 | end |
|
103 | end |
|
100 |
|
104 | ||
|
101 | file = params[:file] |
|
105 | file = params[:file] |
|
102 |
|
106 | ||
|
103 | if problem.errors.length!=0 |
|
107 | if problem.errors.length!=0 |
|
104 | return problem |
|
108 | return problem |
|
105 | end |
|
109 | end |
|
106 |
|
110 | ||
|
107 | problem.name = params[:name] |
|
111 | problem.name = params[:name] |
|
108 | if params[:full_name]!='' |
|
112 | if params[:full_name]!='' |
|
109 | problem.full_name = params[:full_name] |
|
113 | problem.full_name = params[:full_name] |
|
110 | else |
|
114 | else |
|
111 | problem.full_name = params[:name] |
|
115 | problem.full_name = params[:name] |
|
112 | end |
|
116 | end |
|
113 |
|
117 | ||
|
114 | return { |
|
118 | return { |
|
115 | :time_limit => time_limit, |
|
119 | :time_limit => time_limit, |
|
116 | :memory_limit => memory_limit, |
|
120 | :memory_limit => memory_limit, |
|
117 | :file => file |
|
121 | :file => file |
|
118 | } |
|
122 | } |
|
119 | end |
|
123 | end |
|
120 |
|
124 |
@@ -1,19 +1,21 | |||||
|
1 | - .problem-panel{:id => "problem-panel-#{problem.id}", :style => "display:none"} |
|
1 | + .problem-panel{:id => "problem-panel-#{problem.id}", :style => "#{(problem.id != @current_problem_id) ? "display:none" : ""}"} |
|
2 | .problem-form{:id => "problem-form-#{problem.id}"} |
|
2 | .problem-form{:id => "problem-form-#{problem.id}"} |
|
3 | - form_tag({ :action => 'download_input', :id => problem.id }, :method => :post) do |
|
3 | - form_tag({ :action => 'download_input', :id => problem.id }, :method => :post) do |
|
4 | %b Input: |
|
4 | %b Input: |
|
5 | %input{:type => "submit", :value => "Download input"} |
|
5 | %input{:type => "submit", :value => "Download input"} |
|
6 | - = "After downloading, you have #{TEST_ASSIGNMENT_EXPIRATION_DURATION/60} minutes to submit." |
|
6 | + %span{:id => "problem-timing-message-#{problem.id}"} |
|
7 | - - form_tag({ :action => 'submit_solution', :id => problem.id }, :method => :post, :multipart => true) do |
|
7 | + = "After downloading, you have #{TEST_ASSIGNMENT_EXPIRATION_DURATION/60} minutes to submit." |
|
8 | - %b Submit output: |
|
8 | + %div{:id => "problem-submission-form-#{problem.id}"} |
|
9 | - %input{:type => "file", :name => "file"} |
|
9 | + - form_tag({ :action => 'submit_solution', :id => problem.id }, :method => :post, :multipart => true) do |
|
10 | - %input{:type => "submit", :value => "Submit solution"} |
|
10 | + %b Submit output: |
|
|
11 | + %input{:type => "file", :name => "file"} | ||
|
|
12 | + %input{:type => "submit", :value => "Submit solution"} | ||
|
11 |
|
13 | ||
|
12 | .problem-description |
|
14 | .problem-description |
|
13 | - if problem.description!=nil |
|
15 | - if problem.description!=nil |
|
14 | - if problem.description.markdowned |
|
16 | - if problem.description.markdowned |
|
15 | = markdown(problem.description.body) |
|
17 | = markdown(problem.description.body) |
|
16 | - else |
|
18 | - else |
|
17 | = problem.description.body |
|
19 | = problem.description.body |
|
18 | - else |
|
20 | - else |
|
19 | (not available) |
|
21 | (not available) |
@@ -1,34 +1,35 | |||||
|
1 | - content_for :head do |
|
1 | - content_for :head do |
|
2 | = javascript_include_tag :defaults |
|
2 | = javascript_include_tag :defaults |
|
3 | %script{:type => 'text/javascript', :src => '/javascripts/announcement_refresh.js'} |
|
3 | %script{:type => 'text/javascript', :src => '/javascripts/announcement_refresh.js'} |
|
4 |
|
4 | ||
|
5 | = user_title_bar(@user) |
|
5 | = user_title_bar(@user) |
|
6 |
|
6 | ||
|
7 | - if @announcements.length!=0 |
|
7 | - if @announcements.length!=0 |
|
8 | .announcementbox |
|
8 | .announcementbox |
|
9 | %span{:class => 'title'} |
|
9 | %span{:class => 'title'} |
|
10 | Announcements |
|
10 | Announcements |
|
11 | #announcementbox-body |
|
11 | #announcementbox-body |
|
12 | = render :partial => 'announcement', :collection => @announcements |
|
12 | = render :partial => 'announcement', :collection => @announcements |
|
13 |
|
13 | ||
|
14 | %hr/ |
|
14 | %hr/ |
|
15 |
|
15 | ||
|
16 | - if (Configuration.contest_mode?) and (@user.site!=nil) and (@user.site.started!=true) |
|
16 | - if (Configuration.contest_mode?) and (@user.site!=nil) and (@user.site.started!=true) |
|
17 | %p=t 'main.start_soon' |
|
17 | %p=t 'main.start_soon' |
|
18 |
|
18 | ||
|
19 | - if Configuration.show_tasks_to?(@user) |
|
19 | - if Configuration.show_tasks_to?(@user) |
|
20 | .problem-list |
|
20 | .problem-list |
|
21 | = render :partial => 'problem_title', :collection => @problems, :as => :problem |
|
21 | = render :partial => 'problem_title', :collection => @problems, :as => :problem |
|
22 | .problem-content |
|
22 | .problem-content |
|
23 | - %span{:id => "problem-panel-filler"} |
|
23 | + - if @current_problem_id==nil |
|
24 | - %b Welcome to Code Jom |
|
24 | + %span{:id => "problem-panel-filler"} |
|
25 | - %br/ |
|
25 | + %b Welcome to Code Jom |
|
26 | - Choose problems from the list on the right. |
|
26 | + %br/ |
|
|
27 | + Choose problems from the list on the right. | ||
|
27 | = render :partial => 'problem', :collection => @problems |
|
28 | = render :partial => 'problem', :collection => @problems |
|
28 |
|
29 | ||
|
29 | %br{:clear=>'both'}/ |
|
30 | %br{:clear=>'both'}/ |
|
30 | %hr/ |
|
31 | %hr/ |
|
31 |
|
32 | ||
|
32 | :javascript |
|
33 | :javascript |
|
33 | Announcement.registerRefreshEventTimer(); |
|
34 | Announcement.registerRefreshEventTimer(); |
|
34 |
|
35 |
You need to be logged in to leave comments.
Login now