Description:
fixed timing stat bug when used with single user mode
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r245:4658efe40e96 - - 2 files changed: 7 inserted, 1 deleted

@@ -1,40 +1,39
1 class LoginController < ApplicationController
1 class LoginController < ApplicationController
2
2
3 def index
3 def index
4 # show login screen
4 # show login screen
5 reset_session
5 reset_session
6 redirect_to :controller => 'main', :action => 'login'
6 redirect_to :controller => 'main', :action => 'login'
7 end
7 end
8
8
9 def login
9 def login
10 if user = User.authenticate(params[:login], params[:password])
10 if user = User.authenticate(params[:login], params[:password])
11 session[:user_id] = user.id
11 session[:user_id] = user.id
12 session[:admin] = user.admin?
12 session[:admin] = user.admin?
13 - UserContestStat.update_user_start_time(user)
14 redirect_to :controller => 'main', :action => 'list'
13 redirect_to :controller => 'main', :action => 'list'
15 else
14 else
16 flash[:notice] = 'Wrong password'
15 flash[:notice] = 'Wrong password'
17 redirect_to :controller => 'main', :action => 'login'
16 redirect_to :controller => 'main', :action => 'login'
18 end
17 end
19 end
18 end
20
19
21 def site_login
20 def site_login
22 begin
21 begin
23 site = Site.find(params[:login][:site_id])
22 site = Site.find(params[:login][:site_id])
24 rescue ActiveRecord::RecordNotFound
23 rescue ActiveRecord::RecordNotFound
25 site = nil
24 site = nil
26 end
25 end
27 if site==nil
26 if site==nil
28 flash[:notice] = 'Wrong site'
27 flash[:notice] = 'Wrong site'
29 redirect_to :controller => 'main', :action => 'login' and return
28 redirect_to :controller => 'main', :action => 'login' and return
30 end
29 end
31 if (site.password) and (site.password == params[:login][:password])
30 if (site.password) and (site.password == params[:login][:password])
32 session[:site_id] = site.id
31 session[:site_id] = site.id
33 redirect_to :controller => 'site', :action => 'index'
32 redirect_to :controller => 'site', :action => 'index'
34 else
33 else
35 flash[:notice] = 'Wrong site password'
34 flash[:notice] = 'Wrong site password'
36 redirect_to :controller => 'site', :action => 'login'
35 redirect_to :controller => 'site', :action => 'login'
37 end
36 end
38 end
37 end
39
38
40 end
39 end
@@ -1,53 +1,55
1 class MainController < ApplicationController
1 class MainController < ApplicationController
2
2
3 before_filter :authenticate, :except => [:index, :login]
3 before_filter :authenticate, :except => [:index, :login]
4 before_filter :check_viewability, :except => [:index, :login]
4 before_filter :check_viewability, :except => [:index, :login]
5
5
6 + append_before_filter :update_user_start_time, :except => [:index, :login]
7 +
6 # COMMENTED OUT: filter in each action instead
8 # COMMENTED OUT: filter in each action instead
7 # before_filter :verify_time_limit, :only => [:submit]
9 # before_filter :verify_time_limit, :only => [:submit]
8
10
9 verify :method => :post, :only => [:submit, :download_input, :submit_solution],
11 verify :method => :post, :only => [:submit, :download_input, :submit_solution],
10 :redirect_to => { :action => :index }
12 :redirect_to => { :action => :index }
11
13
12 # COMMENT OUT: only need when having high load
14 # COMMENT OUT: only need when having high load
13 # caches_action :index, :login
15 # caches_action :index, :login
14
16
15 # NOTE: This method is not actually needed, 'config/routes.rb' has
17 # NOTE: This method is not actually needed, 'config/routes.rb' has
16 # assigned action login as a default action.
18 # assigned action login as a default action.
17 def index
19 def index
18 redirect_to :action => 'login'
20 redirect_to :action => 'login'
19 end
21 end
20
22
21 def login
23 def login
22 saved_notice = flash[:notice]
24 saved_notice = flash[:notice]
23 reset_session
25 reset_session
24 flash.now[:notice] = saved_notice
26 flash.now[:notice] = saved_notice
25
27
26 # EXPERIMENT:
28 # EXPERIMENT:
27 # Hide login if in single user mode and the url does not
29 # Hide login if in single user mode and the url does not
28 # explicitly specify /login
30 # explicitly specify /login
29 #
31 #
30 # logger.info "PATH: #{request.path}"
32 # logger.info "PATH: #{request.path}"
31 # if Configuration['system.single_user_mode'] and
33 # if Configuration['system.single_user_mode'] and
32 # request.path!='/main/login'
34 # request.path!='/main/login'
33 # @hidelogin = true
35 # @hidelogin = true
34 # end
36 # end
35
37
36 @announcements = Announcement.find_for_frontpage
38 @announcements = Announcement.find_for_frontpage
37 render :action => 'login', :layout => 'empty'
39 render :action => 'login', :layout => 'empty'
38 end
40 end
39
41
40 def list
42 def list
41 prepare_list_information
43 prepare_list_information
42 end
44 end
43
45
44 def help
46 def help
45 @user = User.find(session[:user_id])
47 @user = User.find(session[:user_id])
46 end
48 end
47
49
48 def submit
50 def submit
49 user = User.find(session[:user_id])
51 user = User.find(session[:user_id])
50
52
51 @submission = Submission.new(params[:submission])
53 @submission = Submission.new(params[:submission])
52 @submission.user = user
54 @submission.user = user
53 @submission.language_id = 0
55 @submission.language_id = 0
@@ -410,50 +412,55
410 return {
412 return {
411 :num => case_num,
413 :num => case_num,
412 :msg => results[0],
414 :msg => results[0],
413 :run_stat => run_stat,
415 :run_stat => run_stat,
414 :output => output_file,
416 :output => output_file,
415 :output_size => output_size
417 :output_size => output_size
416 }
418 }
417 end
419 end
418 end
420 end
419
421
420 # copied from grader/script/lib/test_request_helper.rb
422 # copied from grader/script/lib/test_request_helper.rb
421 def extract_running_stat(results)
423 def extract_running_stat(results)
422 running_stat_line = results[-1]
424 running_stat_line = results[-1]
423
425
424 # extract exit status line
426 # extract exit status line
425 run_stat = ""
427 run_stat = ""
426 if !(/[Cc]orrect/.match(results[0]))
428 if !(/[Cc]orrect/.match(results[0]))
427 run_stat = results[0].chomp
429 run_stat = results[0].chomp
428 else
430 else
429 run_stat = 'Program exited normally'
431 run_stat = 'Program exited normally'
430 end
432 end
431
433
432 logger.info "Stat line: #{running_stat_line}"
434 logger.info "Stat line: #{running_stat_line}"
433
435
434 # extract running time
436 # extract running time
435 if res = /r(.*)u(.*)s/.match(running_stat_line)
437 if res = /r(.*)u(.*)s/.match(running_stat_line)
436 seconds = (res[1].to_f + res[2].to_f)
438 seconds = (res[1].to_f + res[2].to_f)
437 time_stat = "Time used: #{seconds} sec."
439 time_stat = "Time used: #{seconds} sec."
438 else
440 else
439 seconds = nil
441 seconds = nil
440 time_stat = "Time used: n/a sec."
442 time_stat = "Time used: n/a sec."
441 end
443 end
442
444
443 # extract memory usage
445 # extract memory usage
444 if res = /s(.*)m/.match(running_stat_line)
446 if res = /s(.*)m/.match(running_stat_line)
445 memory_used = res[1].to_i
447 memory_used = res[1].to_i
446 else
448 else
447 memory_used = -1
449 memory_used = -1
448 end
450 end
449
451
450 return {
452 return {
451 :msg => "#{run_stat}\n#{time_stat}",
453 :msg => "#{run_stat}\n#{time_stat}",
452 :running_time => seconds,
454 :running_time => seconds,
453 :exit_status => run_stat,
455 :exit_status => run_stat,
454 :memory_usage => memory_used
456 :memory_usage => memory_used
455 }
457 }
456 end
458 end
457
459
460 + def update_user_start_time
461 + user = User.find(session[:user_id])
462 + UserContestStat.update_user_start_time(user)
463 + end
464 +
458 end
465 end
459
466
You need to be logged in to leave comments. Login now