Description:
fixed codejom stutus update to ignore disabled problems
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r246:180b30450ef3 - - 1 file changed: 2 inserted, 2 deleted
@@ -1,49 +1,49 | |||||
|
1 |
- # -*- coding: u |
|
1 | + # -*- coding: utf-8 -*- |
|
2 | require 'digest/sha1' |
|
2 | require 'digest/sha1' |
|
3 |
|
3 | ||
|
4 | class User < ActiveRecord::Base |
|
4 | class User < ActiveRecord::Base |
|
5 |
|
5 | ||
|
6 | has_and_belongs_to_many :roles |
|
6 | has_and_belongs_to_many :roles |
|
7 |
|
7 | ||
|
8 | has_many :test_requests, :order => "submitted_at DESC" |
|
8 | has_many :test_requests, :order => "submitted_at DESC" |
|
9 |
|
9 | ||
|
10 | has_many :messages, |
|
10 | has_many :messages, |
|
11 | :class_name => "Message", |
|
11 | :class_name => "Message", |
|
12 | :foreign_key => "sender_id", |
|
12 | :foreign_key => "sender_id", |
|
13 | :order => 'created_at DESC' |
|
13 | :order => 'created_at DESC' |
|
14 |
|
14 | ||
|
15 | has_many :replied_messages, |
|
15 | has_many :replied_messages, |
|
16 | :class_name => "Message", |
|
16 | :class_name => "Message", |
|
17 | :foreign_key => "receiver_id", |
|
17 | :foreign_key => "receiver_id", |
|
18 | :order => 'created_at DESC' |
|
18 | :order => 'created_at DESC' |
|
19 |
|
19 | ||
|
20 | has_many :test_pair_assignments, :dependent => :delete_all |
|
20 | has_many :test_pair_assignments, :dependent => :delete_all |
|
21 | has_many :submission_statuses |
|
21 | has_many :submission_statuses |
|
22 |
|
22 | ||
|
23 | has_one :contest_stat, :class_name => "UserContestStat" |
|
23 | has_one :contest_stat, :class_name => "UserContestStat" |
|
24 |
|
24 | ||
|
25 | belongs_to :site |
|
25 | belongs_to :site |
|
26 | belongs_to :country |
|
26 | belongs_to :country |
|
27 |
|
27 | ||
|
28 | # For Code Jom |
|
28 | # For Code Jom |
|
29 | has_one :codejom_status |
|
29 | has_one :codejom_status |
|
30 |
|
30 | ||
|
31 | named_scope :activated_users, :conditions => {:activated => true} |
|
31 | named_scope :activated_users, :conditions => {:activated => true} |
|
32 |
|
32 | ||
|
33 | validates_presence_of :login |
|
33 | validates_presence_of :login |
|
34 | validates_uniqueness_of :login |
|
34 | validates_uniqueness_of :login |
|
35 | validates_format_of :login, :with => /^[\_A-Za-z0-9]+$/ |
|
35 | validates_format_of :login, :with => /^[\_A-Za-z0-9]+$/ |
|
36 | validates_length_of :login, :within => 3..20 |
|
36 | validates_length_of :login, :within => 3..20 |
|
37 |
|
37 | ||
|
38 | validates_presence_of :full_name |
|
38 | validates_presence_of :full_name |
|
39 | validates_length_of :full_name, :minimum => 1 |
|
39 | validates_length_of :full_name, :minimum => 1 |
|
40 |
|
40 | ||
|
41 | validates_presence_of :member1_full_name |
|
41 | validates_presence_of :member1_full_name |
|
42 | validates_length_of :member1_full_name, :minimum => 1 |
|
42 | validates_length_of :member1_full_name, :minimum => 1 |
|
43 |
|
43 | ||
|
44 | validates_presence_of :password, :if => :password_required? |
|
44 | validates_presence_of :password, :if => :password_required? |
|
45 | validates_length_of :password, :within => 4..20, :if => :password_required? |
|
45 | validates_length_of :password, :within => 4..20, :if => :password_required? |
|
46 | validates_confirmation_of :password, :if => :password_required? |
|
46 | validates_confirmation_of :password, :if => :password_required? |
|
47 |
|
47 | ||
|
48 | validates_format_of :email, |
|
48 | validates_format_of :email, |
|
49 | :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, |
|
49 | :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, |
@@ -189,97 +189,97 | |||||
|
189 | return nil if site==nil |
|
189 | return nil if site==nil |
|
190 | return site.time_left |
|
190 | return site.time_left |
|
191 | elsif Configuration.indv_contest_mode? |
|
191 | elsif Configuration.indv_contest_mode? |
|
192 | time_limit = Configuration.contest_time_limit |
|
192 | time_limit = Configuration.contest_time_limit |
|
193 | if contest_stat==nil |
|
193 | if contest_stat==nil |
|
194 | return (Time.now.gmtime + time_limit) - Time.now.gmtime |
|
194 | return (Time.now.gmtime + time_limit) - Time.now.gmtime |
|
195 | else |
|
195 | else |
|
196 | finish_time = contest_stat.started_at + time_limit |
|
196 | finish_time = contest_stat.started_at + time_limit |
|
197 | current_time = Time.now.gmtime |
|
197 | current_time = Time.now.gmtime |
|
198 | if current_time > finish_time |
|
198 | if current_time > finish_time |
|
199 | return 0 |
|
199 | return 0 |
|
200 | else |
|
200 | else |
|
201 | return finish_time - current_time |
|
201 | return finish_time - current_time |
|
202 | end |
|
202 | end |
|
203 | end |
|
203 | end |
|
204 | else |
|
204 | else |
|
205 | return nil |
|
205 | return nil |
|
206 | end |
|
206 | end |
|
207 | end |
|
207 | end |
|
208 |
|
208 | ||
|
209 | def contest_finished? |
|
209 | def contest_finished? |
|
210 | if Configuration.contest_mode? |
|
210 | if Configuration.contest_mode? |
|
211 | return false if site==nil |
|
211 | return false if site==nil |
|
212 | return site.finished? |
|
212 | return site.finished? |
|
213 | elsif Configuration.indv_contest_mode? |
|
213 | elsif Configuration.indv_contest_mode? |
|
214 | time_limit = Configuration.contest_time_limit |
|
214 | time_limit = Configuration.contest_time_limit |
|
215 |
|
215 | ||
|
216 | return false if contest_stat==nil |
|
216 | return false if contest_stat==nil |
|
217 |
|
217 | ||
|
218 | return contest_time_left == 0 |
|
218 | return contest_time_left == 0 |
|
219 | else |
|
219 | else |
|
220 | return false |
|
220 | return false |
|
221 | end |
|
221 | end |
|
222 | end |
|
222 | end |
|
223 |
|
223 | ||
|
224 | def contest_started? |
|
224 | def contest_started? |
|
225 | if Configuration.contest_mode? |
|
225 | if Configuration.contest_mode? |
|
226 | return true if site==nil |
|
226 | return true if site==nil |
|
227 | return site.started |
|
227 | return site.started |
|
228 | else |
|
228 | else |
|
229 | return true |
|
229 | return true |
|
230 | end |
|
230 | end |
|
231 | end |
|
231 | end |
|
232 |
|
232 | ||
|
233 | # For Code Jom |
|
233 | # For Code Jom |
|
234 | def update_codejom_status |
|
234 | def update_codejom_status |
|
235 | status = codejom_status || CodejomStatus.new(:user => self) |
|
235 | status = codejom_status || CodejomStatus.new(:user => self) |
|
236 | problem_count = Problem.available_problem_count |
|
236 | problem_count = Problem.available_problem_count |
|
237 | - status.num_problems_passed = (self.submission_statuses.find_all {|s| s.passed}).length |
|
237 | + status.num_problems_passed = (self.submission_statuses.find_all {|s| s.passed and s.problem.available }).length |
|
238 | status.alive = (problem_count - (status.num_problems_passed)) <= CODEJOM_MAX_ALIVE_LEVEL |
|
238 | status.alive = (problem_count - (status.num_problems_passed)) <= CODEJOM_MAX_ALIVE_LEVEL |
|
239 | status.save |
|
239 | status.save |
|
240 | end |
|
240 | end |
|
241 |
|
241 | ||
|
242 | def codejom_level |
|
242 | def codejom_level |
|
243 | problem_count = Problem.available_problem_count |
|
243 | problem_count = Problem.available_problem_count |
|
244 | if codejom_status!=nil |
|
244 | if codejom_status!=nil |
|
245 | return problem_count - codejom_status.num_problems_passed |
|
245 | return problem_count - codejom_status.num_problems_passed |
|
246 | else |
|
246 | else |
|
247 | return problem_count |
|
247 | return problem_count |
|
248 | end |
|
248 | end |
|
249 | end |
|
249 | end |
|
250 |
|
250 | ||
|
251 | protected |
|
251 | protected |
|
252 | def encrypt_new_password |
|
252 | def encrypt_new_password |
|
253 | return if password.blank? |
|
253 | return if password.blank? |
|
254 | self.salt = (10+rand(90)).to_s |
|
254 | self.salt = (10+rand(90)).to_s |
|
255 | self.hashed_password = User.encrypt(self.password,self.salt) |
|
255 | self.hashed_password = User.encrypt(self.password,self.salt) |
|
256 | end |
|
256 | end |
|
257 |
|
257 | ||
|
258 | def assign_default_site |
|
258 | def assign_default_site |
|
259 | # have to catch error when migrating (because self.site is not available). |
|
259 | # have to catch error when migrating (because self.site is not available). |
|
260 | begin |
|
260 | begin |
|
261 | if self.site==nil |
|
261 | if self.site==nil |
|
262 | self.site = Site.find_by_name('default') |
|
262 | self.site = Site.find_by_name('default') |
|
263 | if self.site==nil |
|
263 | if self.site==nil |
|
264 | self.site = Site.find(1) # when 'default has be renamed' |
|
264 | self.site = Site.find(1) # when 'default has be renamed' |
|
265 | end |
|
265 | end |
|
266 | end |
|
266 | end |
|
267 | rescue |
|
267 | rescue |
|
268 | end |
|
268 | end |
|
269 | end |
|
269 | end |
|
270 |
|
270 | ||
|
271 | def password_required? |
|
271 | def password_required? |
|
272 | self.hashed_password.blank? || !self.password.blank? |
|
272 | self.hashed_password.blank? || !self.password.blank? |
|
273 | end |
|
273 | end |
|
274 |
|
274 | ||
|
275 | def self.encrypt(string,salt) |
|
275 | def self.encrypt(string,salt) |
|
276 | Digest::SHA1.hexdigest(salt + string) |
|
276 | Digest::SHA1.hexdigest(salt + string) |
|
277 | end |
|
277 | end |
|
278 |
|
278 | ||
|
279 | def uniqueness_of_email_from_activated_users |
|
279 | def uniqueness_of_email_from_activated_users |
|
280 | user = User.activated_users.find_by_email(self.email) |
|
280 | user = User.activated_users.find_by_email(self.email) |
|
281 | if user and (user.login != self.login) |
|
281 | if user and (user.login != self.login) |
|
282 | self.errors.add_to_base("Email has already been taken") |
|
282 | self.errors.add_to_base("Email has already been taken") |
|
283 | end |
|
283 | end |
|
284 | end |
|
284 | end |
|
285 |
|
285 |
You need to be logged in to leave comments.
Login now