Description:
added options not to hide passed problems
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r260:a6455c18d017 - - 2 files changed: 6 inserted, 2 deleted

@@ -222,221 +222,224
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 @page_reload_when_view_problem = true
282 render :partial => 'problem_title', :collection => @problems, :as => :problem
282 render :partial => 'problem_title', :collection => @problems, :as => :problem
283 end
283 end
284
284
285 def splash
285 def splash
286 render :text => '<div class="notice">Most recent task:</span>'
286 render :text => '<div class="notice">Most recent task:</span>'
287 end
287 end
288
288
289 protected
289 protected
290
290
291 def prepare_announcements(recent=nil)
291 def prepare_announcements(recent=nil)
292 if Configuration.show_tasks_to?(@user)
292 if Configuration.show_tasks_to?(@user)
293 @announcements = Announcement.find_published(true)
293 @announcements = Announcement.find_published(true)
294 else
294 else
295 @announcements = Announcement.find_published
295 @announcements = Announcement.find_published
296 end
296 end
297 if recent!=nil
297 if recent!=nil
298 recent_id = recent.to_i
298 recent_id = recent.to_i
299 @announcements = @announcements.find_all { |a| a.id > recent_id }
299 @announcements = @announcements.find_all { |a| a.id > recent_id }
300 end
300 end
301 end
301 end
302
302
303 def prepare_timeout_information(problems)
303 def prepare_timeout_information(problems)
304 @submission_timeouts = {}
304 @submission_timeouts = {}
305 problems.each do |problem|
305 problems.each do |problem|
306 assignment = @user.get_recent_test_pair_assignment_for(problem)
306 assignment = @user.get_recent_test_pair_assignment_for(problem)
307 if assignment == nil
307 if assignment == nil
308 timeout = nil
308 timeout = nil
309 else
309 else
310 if (assignment.expired?) or (assignment.submitted)
310 if (assignment.expired?) or (assignment.submitted)
311 timeout = 0
311 timeout = 0
312 else
312 else
313 timeout = assignment.created_at + TEST_ASSIGNMENT_EXPIRATION_DURATION - Time.new.gmtime
313 timeout = assignment.created_at + TEST_ASSIGNMENT_EXPIRATION_DURATION - Time.new.gmtime
314 end
314 end
315 end
315 end
316 @submission_timeouts[problem.id] = timeout
316 @submission_timeouts[problem.id] = timeout
317 end
317 end
318 - @submission_timeouts.each_pair {|k,v| puts "#{k} => #{v}"}
319 end
318 end
320
319
321 def prepare_list_information
320 def prepare_list_information
322 @user = User.find(session[:user_id])
321 @user = User.find(session[:user_id])
323
322
324 all_problems = Problem.find_available_problems
323 all_problems = Problem.find_available_problems
325
324
326 passed = {}
325 passed = {}
327 sub_count = {}
326 sub_count = {}
328 @user.submission_statuses.each do |status|
327 @user.submission_statuses.each do |status|
329 if status.passed
328 if status.passed
330 passed[status.problem_id] = true
329 passed[status.problem_id] = true
331 end
330 end
332 sub_count[status.problem_id] = status.submission_count
331 sub_count[status.problem_id] = status.submission_count
333 end
332 end
334
333
335 if session.has_key? :current_problem_id
334 if session.has_key? :current_problem_id
336 @current_problem_id = session[:current_problem_id]
335 @current_problem_id = session[:current_problem_id]
337 session.delete(:current_problem_id)
336 session.delete(:current_problem_id)
338 else
337 else
339 if params.has_key? :id
338 if params.has_key? :id
340 @current_problem_id = params[:id].to_i
339 @current_problem_id = params[:id].to_i
341 else
340 else
342 @current_problem_id = nil
341 @current_problem_id = nil
343 end
342 end
344 end
343 end
345
344
346 - @problems = all_problems.reject { |problem| passed.has_key? problem.id }
345 + if (not defined? HIDE_PASSED_TASKS) or HIDE_PASSED_TASKS
346 + @problems = all_problems.reject { |problem| passed.has_key? problem.id }
347 + else
348 + @problems = all_problems
349 + end
347
350
348 prepare_timeout_information(@problems)
351 prepare_timeout_information(@problems)
349
352
350 @prob_submissions = Array.new
353 @prob_submissions = Array.new
351 @problems.each do |p|
354 @problems.each do |p|
352 if sub_count.has_key? p.id
355 if sub_count.has_key? p.id
353 @prob_submissions << { :count => sub_count[p.id] }
356 @prob_submissions << { :count => sub_count[p.id] }
354 else
357 else
355 @prob_submissions << { :count => 0 }
358 @prob_submissions << { :count => 0 }
356 end
359 end
357 end
360 end
358 prepare_announcements
361 prepare_announcements
359 end
362 end
360
363
361 def check_viewability
364 def check_viewability
362 @user = User.find(session[:user_id])
365 @user = User.find(session[:user_id])
363 if (!Configuration.show_tasks_to?(@user)) and
366 if (!Configuration.show_tasks_to?(@user)) and
364 ((action_name=='submission') or (action_name=='submit'))
367 ((action_name=='submission') or (action_name=='submit'))
365 redirect_to :action => 'list' and return
368 redirect_to :action => 'list' and return
366 end
369 end
367 end
370 end
368
371
369 def prepare_grading_result(submission)
372 def prepare_grading_result(submission)
370 if Configuration.task_grading_info.has_key? submission.problem.name
373 if Configuration.task_grading_info.has_key? submission.problem.name
371 grading_info = Configuration.task_grading_info[submission.problem.name]
374 grading_info = Configuration.task_grading_info[submission.problem.name]
372 else
375 else
373 # guess task info from problem.full_score
376 # guess task info from problem.full_score
374 cases = submission.problem.full_score / 10
377 cases = submission.problem.full_score / 10
375 grading_info = {
378 grading_info = {
376 'testruns' => cases,
379 'testruns' => cases,
377 'testcases' => cases
380 'testcases' => cases
378 }
381 }
379 end
382 end
380 @test_runs = []
383 @test_runs = []
381 if grading_info['testruns'].is_a? Integer
384 if grading_info['testruns'].is_a? Integer
382 trun_count = grading_info['testruns']
385 trun_count = grading_info['testruns']
383 trun_count.times do |i|
386 trun_count.times do |i|
384 @test_runs << [ read_grading_result(@user.login,
387 @test_runs << [ read_grading_result(@user.login,
385 submission.problem.name,
388 submission.problem.name,
386 submission.id,
389 submission.id,
387 i+1) ]
390 i+1) ]
388 end
391 end
389 else
392 else
390 grading_info['testruns'].keys.sort.each do |num|
393 grading_info['testruns'].keys.sort.each do |num|
391 run = []
394 run = []
392 testrun = grading_info['testruns'][num]
395 testrun = grading_info['testruns'][num]
393 testrun.each do |c|
396 testrun.each do |c|
394 run << read_grading_result(@user.login,
397 run << read_grading_result(@user.login,
395 submission.problem.name,
398 submission.problem.name,
396 submission.id,
399 submission.id,
397 c)
400 c)
398 end
401 end
399 @test_runs << run
402 @test_runs << run
400 end
403 end
401 end
404 end
402 end
405 end
403
406
404 def grading_result_dir(user_name, problem_name, submission_id, case_num)
407 def grading_result_dir(user_name, problem_name, submission_id, case_num)
405 return "#{GRADING_RESULT_DIR}/#{user_name}/#{problem_name}/#{submission_id}/test-result/#{case_num}"
408 return "#{GRADING_RESULT_DIR}/#{user_name}/#{problem_name}/#{submission_id}/test-result/#{case_num}"
406 end
409 end
407
410
408 def output_filename(user_name, problem_name, submission_id, case_num)
411 def output_filename(user_name, problem_name, submission_id, case_num)
409 dir = grading_result_dir(user_name,problem_name, submission_id, case_num)
412 dir = grading_result_dir(user_name,problem_name, submission_id, case_num)
410 return "#{dir}/output.txt"
413 return "#{dir}/output.txt"
411 end
414 end
412
415
413 def read_grading_result(user_name, problem_name, submission_id, case_num)
416 def read_grading_result(user_name, problem_name, submission_id, case_num)
414 dir = grading_result_dir(user_name,problem_name, submission_id, case_num)
417 dir = grading_result_dir(user_name,problem_name, submission_id, case_num)
415 result_file_name = "#{dir}/result"
418 result_file_name = "#{dir}/result"
416 if !FileTest.exists?(result_file_name)
419 if !FileTest.exists?(result_file_name)
417 return {:num => case_num, :msg => 'program did not run'}
420 return {:num => case_num, :msg => 'program did not run'}
418 else
421 else
419 results = File.open(result_file_name).readlines
422 results = File.open(result_file_name).readlines
420 run_stat = extract_running_stat(results)
423 run_stat = extract_running_stat(results)
421 output_filename = "#{dir}/output.txt"
424 output_filename = "#{dir}/output.txt"
422 if FileTest.exists?(output_filename)
425 if FileTest.exists?(output_filename)
423 output_file = true
426 output_file = true
424 output_size = File.size(output_filename)
427 output_size = File.size(output_filename)
425 else
428 else
426 output_file = false
429 output_file = false
427 output_size = 0
430 output_size = 0
428 end
431 end
429
432
430 return {
433 return {
431 :num => case_num,
434 :num => case_num,
432 :msg => results[0],
435 :msg => results[0],
433 :run_stat => run_stat,
436 :run_stat => run_stat,
434 :output => output_file,
437 :output => output_file,
435 :output_size => output_size
438 :output_size => output_size
436 }
439 }
437 end
440 end
438 end
441 end
439
442
440 # copied from grader/script/lib/test_request_helper.rb
443 # copied from grader/script/lib/test_request_helper.rb
441 def extract_running_stat(results)
444 def extract_running_stat(results)
442 running_stat_line = results[-1]
445 running_stat_line = results[-1]
@@ -16,96 +16,97
16 # Skip frameworks you're not going to use (only works if using vendor/rails)
16 # Skip frameworks you're not going to use (only works if using vendor/rails)
17 # config.frameworks -= [ :action_web_service, :action_mailer ]
17 # config.frameworks -= [ :action_web_service, :action_mailer ]
18
18
19 # Only load the plugins named here, by default all plugins in vendor/plugins are loaded
19 # Only load the plugins named here, by default all plugins in vendor/plugins are loaded
20 # config.plugins = %W( exception_notification ssl_requirement )
20 # config.plugins = %W( exception_notification ssl_requirement )
21
21
22 # Add additional load paths for your own custom dirs
22 # Add additional load paths for your own custom dirs
23 # config.load_paths += %W( #{RAILS_ROOT}/extras )
23 # config.load_paths += %W( #{RAILS_ROOT}/extras )
24
24
25 # Force all environments to use the same logger level
25 # Force all environments to use the same logger level
26 # (by default production uses :info, the others :debug)
26 # (by default production uses :info, the others :debug)
27 # config.log_level = :debug
27 # config.log_level = :debug
28
28
29 # Use the database for sessions instead of the file system
29 # Use the database for sessions instead of the file system
30 # (create the session table with 'rake db:sessions:create')
30 # (create the session table with 'rake db:sessions:create')
31 config.action_controller.session_store = :active_record_store
31 config.action_controller.session_store = :active_record_store
32
32
33 # Use SQL instead of Active Record's schema dumper when creating the test database.
33 # Use SQL instead of Active Record's schema dumper when creating the test database.
34 # This is necessary if your schema can't be completely dumped by the schema dumper,
34 # This is necessary if your schema can't be completely dumped by the schema dumper,
35 # like if you have constraints or database-specific column types
35 # like if you have constraints or database-specific column types
36 # config.active_record.schema_format = :sql
36 # config.active_record.schema_format = :sql
37
37
38 # Activate observers that should always be running
38 # Activate observers that should always be running
39 # config.active_record.observers = :cacher, :garbage_collector
39 # config.active_record.observers = :cacher, :garbage_collector
40
40
41 # Make Active Record use UTC-base instead of local time
41 # Make Active Record use UTC-base instead of local time
42 config.time_zone = 'UTC'
42 config.time_zone = 'UTC'
43
43
44 # Setting locales
44 # Setting locales
45 config.i18n.default_locale = 'en'
45 config.i18n.default_locale = 'en'
46
46
47 # See Rails::Configuration for more options
47 # See Rails::Configuration for more options
48
48
49 # -------------
49 # -------------
50 # Required gems
50 # Required gems
51 # -------------
51 # -------------
52 config.gem "haml"
52 config.gem "haml"
53 config.gem "tmail"
53 config.gem "tmail"
54 config.gem "rdiscount", :lib => "rdiscount"
54 config.gem "rdiscount", :lib => "rdiscount"
55
55
56 # NOTES on rspec: if you wan to test with rspec, you have to install
56 # NOTES on rspec: if you wan to test with rspec, you have to install
57 # rspec yourself, just call: [sudo] gem install rspec-rails
57 # rspec yourself, just call: [sudo] gem install rspec-rails
58
58
59 end
59 end
60
60
61 # Add new inflection rules using the following format
61 # Add new inflection rules using the following format
62 # (all these examples are active by default):
62 # (all these examples are active by default):
63 # Inflector.inflections do |inflect|
63 # Inflector.inflections do |inflect|
64 # inflect.plural /^(ox)$/i, '\1en'
64 # inflect.plural /^(ox)$/i, '\1en'
65 # inflect.singular /^(ox)en/i, '\1'
65 # inflect.singular /^(ox)en/i, '\1'
66 # inflect.irregular 'person', 'people'
66 # inflect.irregular 'person', 'people'
67 # inflect.uncountable %w( fish sheep )
67 # inflect.uncountable %w( fish sheep )
68 # end
68 # end
69
69
70 # Add new mime types for use in respond_to blocks:
70 # Add new mime types for use in respond_to blocks:
71 # Mime::Type.register "text/richtext", :rtf
71 # Mime::Type.register "text/richtext", :rtf
72 # Mime::Type.register "application/x-mobile", :mobile
72 # Mime::Type.register "application/x-mobile", :mobile
73
73
74 # Include your application configuration below
74 # Include your application configuration below
75
75
76 # If you want to manage graders through web interface, set the path to
76 # If you want to manage graders through web interface, set the path to
77 # the grader directory below. This dir is where raw, ev, ev-exam,
77 # the grader directory below. This dir is where raw, ev, ev-exam,
78 # scripts reside. All grader scripts will be in
78 # scripts reside. All grader scripts will be in
79 # #{GRADER_ROOT_DIR}/scripts.
79 # #{GRADER_ROOT_DIR}/scripts.
80 GRADER_ROOT_DIR = ''
80 GRADER_ROOT_DIR = ''
81
81
82 # These are where inputs and outputs of test requests are stored
82 # These are where inputs and outputs of test requests are stored
83 TEST_REQUEST_INPUT_FILE_DIR = RAILS_ROOT + '/data/test_request/input'
83 TEST_REQUEST_INPUT_FILE_DIR = RAILS_ROOT + '/data/test_request/input'
84 TEST_REQUEST_OUTPUT_FILE_DIR = RAILS_ROOT + '/data/test_request/output'
84 TEST_REQUEST_OUTPUT_FILE_DIR = RAILS_ROOT + '/data/test_request/output'
85
85
86 # To use ANALYSIS MODE, provide the testcases/testruns breakdown,
86 # To use ANALYSIS MODE, provide the testcases/testruns breakdown,
87 # and the directory of the grading result (usually in judge's dir).
87 # and the directory of the grading result (usually in judge's dir).
88 TASK_GRADING_INFO_FILENAME = RAILS_ROOT + '/config/tasks.yml'
88 TASK_GRADING_INFO_FILENAME = RAILS_ROOT + '/config/tasks.yml'
89
89
90 # TODO: change this to where results are kept.
90 # TODO: change this to where results are kept.
91 GRADING_RESULT_DIR = 'RESULT-DIR'
91 GRADING_RESULT_DIR = 'RESULT-DIR'
92
92
93 # Change this to allow importing testdata into database as test-pairs.
93 # Change this to allow importing testdata into database as test-pairs.
94 # This is mainly for Code Jom contest.
94 # This is mainly for Code Jom contest.
95 ALLOW_TEST_PAIR_IMPORT = false
95 ALLOW_TEST_PAIR_IMPORT = false
96
96
97 # Uncomment so that the system validates user e-mails
97 # Uncomment so that the system validates user e-mails
98 # VALIDATE_USER_EMAILS = true
98 # VALIDATE_USER_EMAILS = true
99
99
100 # Uncomment so that Apache X-Sendfile is used when delivering files
100 # Uncomment so that Apache X-Sendfile is used when delivering files
101 # (e.g., in /tasks/view).
101 # (e.g., in /tasks/view).
102 # USE_APACHE_XSENDFILE = true
102 # USE_APACHE_XSENDFILE = true
103
103
104 # Uncomment so that configuration is read only once when the server is loaded
104 # Uncomment so that configuration is read only once when the server is loaded
105 # Configuration.enable_caching
105 # Configuration.enable_caching
106
106
107 # OPTIONS FOR CODE JOM
107 # OPTIONS FOR CODE JOM
108 # --------------------
108 # --------------------
109 CODEJOM_MAX_ALIVE_LEVEL = 10
109 CODEJOM_MAX_ALIVE_LEVEL = 10
110 TEST_ASSIGNMENT_EXPIRATION_DURATION = 5.minute
110 TEST_ASSIGNMENT_EXPIRATION_DURATION = 5.minute
111 SHOW_CONTEST_STATUS = false
111 SHOW_CONTEST_STATUS = false
112 + HIDE_PASSED_TASKS = true No newline at end of file
You need to be logged in to leave comments. Login now