Description:
fixed indv contest timing bug (same as in codejom), added user contest stat reset
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r247:bdb708ab847b - - 4 files changed: 16 inserted, 2 deleted
@@ -8,23 +8,31 | |||||
|
8 | def user_stat |
|
8 | def user_stat |
|
9 | if not Configuration.indv_contest_mode? |
|
9 | if not Configuration.indv_contest_mode? |
|
10 | redirect_to :action => 'index' and return |
|
10 | redirect_to :action => 'index' and return |
|
11 | end |
|
11 | end |
|
12 |
|
12 | ||
|
13 | @users = User.find(:all) |
|
13 | @users = User.find(:all) |
|
14 | @start_times = {} |
|
14 | @start_times = {} |
|
15 | UserContestStat.find(:all).each do |stat| |
|
15 | UserContestStat.find(:all).each do |stat| |
|
16 | @start_times[stat.user_id] = stat.started_at |
|
16 | @start_times[stat.user_id] = stat.started_at |
|
17 | end |
|
17 | end |
|
18 | end |
|
18 | end |
|
19 |
|
19 | ||
|
|
20 | + def clear_stat | ||
|
|
21 | + user = User.find(params[:id]) | ||
|
|
22 | + if user.contest_stat!=nil | ||
|
|
23 | + user.contest_stat.destroy | ||
|
|
24 | + end | ||
|
|
25 | + redirect_to :action => 'user_stat' | ||
|
|
26 | + end | ||
|
|
27 | + | ||
|
20 | def clear_all_stat |
|
28 | def clear_all_stat |
|
21 | if not Configuration.indv_contest_mode? |
|
29 | if not Configuration.indv_contest_mode? |
|
22 | redirect_to :action => 'index' and return |
|
30 | redirect_to :action => 'index' and return |
|
23 | end |
|
31 | end |
|
24 |
|
32 | ||
|
25 | UserContestStat.delete_all() |
|
33 | UserContestStat.delete_all() |
|
26 | flash[:notice] = 'All start time statistic cleared.' |
|
34 | flash[:notice] = 'All start time statistic cleared.' |
|
27 | redirect_to :action => 'index' |
|
35 | redirect_to :action => 'index' |
|
28 | end |
|
36 | end |
|
29 |
|
37 | ||
|
30 | end |
|
38 | end |
@@ -1,25 +1,24 | |||||
|
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 |
@@ -1,17 +1,19 | |||||
|
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], |
|
11 | verify :method => :post, :only => [:submit], |
|
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 |
@@ -310,14 +312,19 | |||||
|
310 | else |
|
312 | else |
|
311 | memory_used = -1 |
|
313 | memory_used = -1 |
|
312 | end |
|
314 | end |
|
313 |
|
315 | ||
|
314 | return { |
|
316 | return { |
|
315 | :msg => "#{run_stat}\n#{time_stat}", |
|
317 | :msg => "#{run_stat}\n#{time_stat}", |
|
316 | :running_time => seconds, |
|
318 | :running_time => seconds, |
|
317 | :exit_status => run_stat, |
|
319 | :exit_status => run_stat, |
|
318 | :memory_usage => memory_used |
|
320 | :memory_usage => memory_used |
|
319 | } |
|
321 | } |
|
320 | end |
|
322 | end |
|
321 |
|
323 | ||
|
|
324 | + def update_user_start_time | ||
|
|
325 | + user = User.find(session[:user_id]) | ||
|
|
326 | + UserContestStat.update_user_start_time(user) | ||
|
|
327 | + end | ||
|
|
328 | + | ||
|
322 | end |
|
329 | end |
|
323 |
|
330 |
@@ -7,25 +7,25 | |||||
|
7 | has_many :test_requests, :order => "submitted_at DESC" |
|
7 | has_many :test_requests, :order => "submitted_at DESC" |
|
8 |
|
8 | ||
|
9 | has_many :messages, |
|
9 | has_many :messages, |
|
10 | :class_name => "Message", |
|
10 | :class_name => "Message", |
|
11 | :foreign_key => "sender_id", |
|
11 | :foreign_key => "sender_id", |
|
12 | :order => 'created_at DESC' |
|
12 | :order => 'created_at DESC' |
|
13 |
|
13 | ||
|
14 | has_many :replied_messages, |
|
14 | has_many :replied_messages, |
|
15 | :class_name => "Message", |
|
15 | :class_name => "Message", |
|
16 | :foreign_key => "receiver_id", |
|
16 | :foreign_key => "receiver_id", |
|
17 | :order => 'created_at DESC' |
|
17 | :order => 'created_at DESC' |
|
18 |
|
18 | ||
|
19 | - has_one :contest_stat, :class_name => "UserContestStat" |
|
19 | + has_one :contest_stat, :class_name => "UserContestStat", :dependent => :destroy |
|
20 |
|
20 | ||
|
21 | belongs_to :site |
|
21 | belongs_to :site |
|
22 | belongs_to :country |
|
22 | belongs_to :country |
|
23 |
|
23 | ||
|
24 | named_scope :activated_users, :conditions => {:activated => true} |
|
24 | named_scope :activated_users, :conditions => {:activated => true} |
|
25 |
|
25 | ||
|
26 | validates_presence_of :login |
|
26 | validates_presence_of :login |
|
27 | validates_uniqueness_of :login |
|
27 | validates_uniqueness_of :login |
|
28 | validates_format_of :login, :with => /^[\_A-Za-z0-9]+$/ |
|
28 | validates_format_of :login, :with => /^[\_A-Za-z0-9]+$/ |
|
29 | validates_length_of :login, :within => 3..30 |
|
29 | validates_length_of :login, :within => 3..30 |
|
30 |
|
30 | ||
|
31 | validates_presence_of :full_name |
|
31 | validates_presence_of :full_name |
You need to be logged in to leave comments.
Login now