Description:
contest ends after user is dead, added status xml for visualization
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r262:9f069571bd87 - - 4 files changed: 33 inserted, 7 deleted

@@ -0,0 +1,17
1 + <?xml version="1.0"?>
2 + <codejom>
3 + <% @dead_users.each do |user| %>
4 + <node>
5 + <name><%= user.login %></name>
6 + <depth>100</depth>
7 + </node>
8 + <% end %>
9 + <% @levels.each do |level| %>
10 + <% @level_users[level].each do |user| %>
11 + <node>
12 + <name><%= user.login %></name>
13 + <depth><%= level %></depth>
14 + </node>
15 + <% end %>
16 + <% end %>
17 + </codejom>
@@ -1,38 +1,33
1 class StatusesController < ApplicationController
1 class StatusesController < ApplicationController
2
2
3 def index
3 def index
4 if not SHOW_CONTEST_STATUS
4 if not SHOW_CONTEST_STATUS
5 render :status => 403 and return
5 render :status => 403 and return
6 end
6 end
7
7
8 problem_count = Problem.available_problem_count
8 problem_count = Problem.available_problem_count
9
9
10 @dead_users = []
10 @dead_users = []
11 @level_users = {}
11 @level_users = {}
12 @levels = (0..CODEJOM_MAX_ALIVE_LEVEL)
12 @levels = (0..CODEJOM_MAX_ALIVE_LEVEL)
13 @levels.each { |l| @level_users[l] = [] }
13 @levels.each { |l| @level_users[l] = [] }
14 User.find(:all).find_all{|user| not user.admin? }.each do |user|
14 User.find(:all).find_all{|user| not user.admin? }.each do |user|
15 - if user.codejom_status==nil
16 user.update_codejom_status
15 user.update_codejom_status
17 user.codejom_status(true) # reload
16 user.codejom_status(true) # reload
18 - end
19
17
20 if not user.codejom_status.alive
18 if not user.codejom_status.alive
21 @dead_users << user
19 @dead_users << user
22 else
20 else
23 @level_users[user.codejom_level] << user
21 @level_users[user.codejom_level] << user
24 end
22 end
25 end
23 end
26
24
27 respond_to do |format|
25 respond_to do |format|
28 format.html
26 format.html
29 format.xml do
27 format.xml do
30 - render :xml => {
28 + render :template => 'statuses/index.xml.erb'
31 - :levels => @level_users,
32 - :dead_users => @dead_users
33 - }
34 end
29 end
35 end
30 end
36 end
31 end
37
32
38 end
33 end
@@ -1,127 +1,135
1 # Methods added to this helper will be available to all templates in the application.
1 # Methods added to this helper will be available to all templates in the application.
2 module ApplicationHelper
2 module ApplicationHelper
3
3
4 def user_header
4 def user_header
5 menu_items = ''
5 menu_items = ''
6 user = User.find(session[:user_id])
6 user = User.find(session[:user_id])
7
7
8 if (user!=nil) and (session[:admin])
8 if (user!=nil) and (session[:admin])
9 # admin menu
9 # admin menu
10 menu_items << "<b>Administrative task:</b> "
10 menu_items << "<b>Administrative task:</b> "
11 append_to menu_items, '[Announcements]', 'announcements', 'index'
11 append_to menu_items, '[Announcements]', 'announcements', 'index'
12 append_to menu_items, '[Msg console]', 'messages', 'console'
12 append_to menu_items, '[Msg console]', 'messages', 'console'
13 append_to menu_items, '[Problems]', 'problems', 'index'
13 append_to menu_items, '[Problems]', 'problems', 'index'
14 append_to menu_items, '[Users]', 'user_admin', 'index'
14 append_to menu_items, '[Users]', 'user_admin', 'index'
15 append_to menu_items, '[Results]', 'user_admin', 'user_stat'
15 append_to menu_items, '[Results]', 'user_admin', 'user_stat'
16 append_to menu_items, '[Graders]', 'graders', 'list'
16 append_to menu_items, '[Graders]', 'graders', 'list'
17 append_to menu_items, '[Contests]', 'contests', 'index'
17 append_to menu_items, '[Contests]', 'contests', 'index'
18 append_to menu_items, '[Sites]', 'sites', 'index'
18 append_to menu_items, '[Sites]', 'sites', 'index'
19 append_to menu_items, '[System config]', 'configurations', 'index'
19 append_to menu_items, '[System config]', 'configurations', 'index'
20 menu_items << "<br/>"
20 menu_items << "<br/>"
21 end
21 end
22
22
23 # main page
23 # main page
24 append_to menu_items, "[#{I18n.t 'menu.main'}]", 'main', 'list'
24 append_to menu_items, "[#{I18n.t 'menu.main'}]", 'main', 'list'
25 append_to menu_items, "[#{I18n.t 'menu.messages'}]", 'messages', 'list'
25 append_to menu_items, "[#{I18n.t 'menu.messages'}]", 'messages', 'list'
26
26
27 if (user!=nil) and (Configuration.show_tasks_to?(user))
27 if (user!=nil) and (Configuration.show_tasks_to?(user))
28 append_to menu_items, "[#{I18n.t 'menu.tasks'}]", 'tasks', 'list'
28 append_to menu_items, "[#{I18n.t 'menu.tasks'}]", 'tasks', 'list'
29 #append_to menu_items, "[#{I18n.t 'menu.submissions'}]", 'main', 'submission'
29 #append_to menu_items, "[#{I18n.t 'menu.submissions'}]", 'main', 'submission'
30 #append_to menu_items, "[#{I18n.t 'menu.test'}]", 'test', 'index'
30 #append_to menu_items, "[#{I18n.t 'menu.test'}]", 'test', 'index'
31 end
31 end
32 #append_to menu_items, "[#{I18n.t 'menu.help'}]", 'main', 'help'
32 #append_to menu_items, "[#{I18n.t 'menu.help'}]", 'main', 'help'
33
33
34 if Configuration['system.user_setting_enabled']
34 if Configuration['system.user_setting_enabled']
35 append_to menu_items, "[#{I18n.t 'menu.settings'}]", 'users', 'index'
35 append_to menu_items, "[#{I18n.t 'menu.settings'}]", 'users', 'index'
36 end
36 end
37 append_to menu_items, "[#{I18n.t 'menu.log_out'}]", 'main', 'login'
37 append_to menu_items, "[#{I18n.t 'menu.log_out'}]", 'main', 'login'
38
38
39 menu_items
39 menu_items
40 end
40 end
41
41
42 def append_to(option,label, controller, action)
42 def append_to(option,label, controller, action)
43 option << ' ' if option!=''
43 option << ' ' if option!=''
44 option << link_to_unless_current(label,
44 option << link_to_unless_current(label,
45 :controller => controller,
45 :controller => controller,
46 :action => action)
46 :action => action)
47 end
47 end
48
48
49 def format_short_time(time)
49 def format_short_time(time)
50 now = Time.now.gmtime
50 now = Time.now.gmtime
51 st = ''
51 st = ''
52 if (time.yday != now.yday) or
52 if (time.yday != now.yday) or
53 (time.year != now.year)
53 (time.year != now.year)
54 st = time.strftime("%x ")
54 st = time.strftime("%x ")
55 end
55 end
56 st + time.strftime("%X")
56 st + time.strftime("%X")
57 end
57 end
58
58
59 def format_short_duration(duration)
59 def format_short_duration(duration)
60 return '' if duration==nil
60 return '' if duration==nil
61 d = duration.to_f
61 d = duration.to_f
62 return Time.at(d).gmtime.strftime("%X")
62 return Time.at(d).gmtime.strftime("%X")
63 end
63 end
64
64
65 def read_textfile(fname,max_size=2048)
65 def read_textfile(fname,max_size=2048)
66 begin
66 begin
67 File.open(fname).read(max_size)
67 File.open(fname).read(max_size)
68 rescue
68 rescue
69 nil
69 nil
70 end
70 end
71 end
71 end
72
72
73 def user_title_bar(user)
73 def user_title_bar(user)
74 header = ''
74 header = ''
75 time_left = ''
75 time_left = ''
76
76
77 #
77 #
78 # if the contest is over
78 # if the contest is over
79 if Configuration.time_limit_mode?
79 if Configuration.time_limit_mode?
80 if user.contest_finished?
80 if user.contest_finished?
81 + if (user.codejom_status) and (not user.codejom_status.alive)
82 + header = <<CONTEST_OVER
83 + <tr><td colspan="2" align="center">
84 + <span class="contest-over-msg">BYE-BYE. YOU ARE DEAD</span>
85 + </td></tr>
86 + CONTEST_OVER
87 + else
81 header = <<CONTEST_OVER
88 header = <<CONTEST_OVER
82 <tr><td colspan="2" align="center">
89 <tr><td colspan="2" align="center">
83 <span class="contest-over-msg">THE CONTEST IS OVER</span>
90 <span class="contest-over-msg">THE CONTEST IS OVER</span>
84 </td></tr>
91 </td></tr>
85 CONTEST_OVER
92 CONTEST_OVER
86 end
93 end
94 + end
87 if !user.contest_started?
95 if !user.contest_started?
88 time_left = "&nbsp;&nbsp;" + (t 'title_bar.contest_not_started')
96 time_left = "&nbsp;&nbsp;" + (t 'title_bar.contest_not_started')
89 else
97 else
90 time_left = "&nbsp;&nbsp;" + (t 'title_bar.remaining_time') +
98 time_left = "&nbsp;&nbsp;" + (t 'title_bar.remaining_time') +
91 " #{format_short_duration(user.contest_time_left)}"
99 " #{format_short_duration(user.contest_time_left)}"
92 end
100 end
93 end
101 end
94
102
95 #
103 #
96 # if the contest is in the anaysis mode
104 # if the contest is in the anaysis mode
97 if Configuration.analysis_mode?
105 if Configuration.analysis_mode?
98 header = <<ANALYSISMODE
106 header = <<ANALYSISMODE
99 <tr><td colspan="2" align="center">
107 <tr><td colspan="2" align="center">
100 <span class="contest-over-msg">ANALYSIS MODE</span>
108 <span class="contest-over-msg">ANALYSIS MODE</span>
101 </td></tr>
109 </td></tr>
102 ANALYSISMODE
110 ANALYSISMODE
103 end
111 end
104
112
105 contest_name = Configuration['contest.name']
113 contest_name = Configuration['contest.name']
106
114
107 #
115 #
108 # build real title bar
116 # build real title bar
109 <<TITLEBAR
117 <<TITLEBAR
110 <div class="title">
118 <div class="title">
111 <table>
119 <table>
112 #{header}
120 #{header}
113 <tr>
121 <tr>
114 <td class="left-col">
122 <td class="left-col">
115 #{user.full_name}<br/>
123 #{user.full_name}<br/>
116 #{t 'title_bar.current_time'} #{format_short_time(Time.new)}
124 #{t 'title_bar.current_time'} #{format_short_time(Time.new)}
117 #{time_left}
125 #{time_left}
118 <br/>
126 <br/>
119 </td>
127 </td>
120 <td class="right-col">#{contest_name}</td>
128 <td class="right-col">#{contest_name}</td>
121 </tr>
129 </tr>
122 </table>
130 </table>
123 </div>
131 </div>
124 TITLEBAR
132 TITLEBAR
125 end
133 end
126
134
127 end
135 end
@@ -116,193 +116,199
116 :test_pair_number => test_pair.number,
116 :test_pair_number => test_pair.number,
117 :request_number =>
117 :request_number =>
118 previous_assignment_numbers.length + 1,
118 previous_assignment_numbers.length + 1,
119 :submitted => false)
119 :submitted => false)
120 return assignment
120 return assignment
121 else
121 else
122 return nil
122 return nil
123 end
123 end
124 end
124 end
125
125
126 def get_submission_status_for(problem)
126 def get_submission_status_for(problem)
127 SubmissionStatus.find(:first,
127 SubmissionStatus.find(:first,
128 :conditions => {
128 :conditions => {
129 :user_id => id,
129 :user_id => id,
130 :problem_id => problem.id
130 :problem_id => problem.id
131 })
131 })
132 end
132 end
133
133
134 def email_for_editing
134 def email_for_editing
135 if self.email==nil
135 if self.email==nil
136 "(unknown)"
136 "(unknown)"
137 elsif self.email==''
137 elsif self.email==''
138 "(blank)"
138 "(blank)"
139 else
139 else
140 self.email
140 self.email
141 end
141 end
142 end
142 end
143
143
144 def email_for_editing=(e)
144 def email_for_editing=(e)
145 self.email=e
145 self.email=e
146 end
146 end
147
147
148 def alias_for_editing
148 def alias_for_editing
149 if self.alias==nil
149 if self.alias==nil
150 "(unknown)"
150 "(unknown)"
151 elsif self.alias==''
151 elsif self.alias==''
152 "(blank)"
152 "(blank)"
153 else
153 else
154 self.alias
154 self.alias
155 end
155 end
156 end
156 end
157
157
158 def alias_for_editing=(e)
158 def alias_for_editing=(e)
159 self.alias=e
159 self.alias=e
160 end
160 end
161
161
162 def activation_key
162 def activation_key
163 if self.hashed_password==nil
163 if self.hashed_password==nil
164 encrypt_new_password
164 encrypt_new_password
165 end
165 end
166 Digest::SHA1.hexdigest(self.hashed_password)[0..7]
166 Digest::SHA1.hexdigest(self.hashed_password)[0..7]
167 end
167 end
168
168
169 def verify_activation_key(key)
169 def verify_activation_key(key)
170 key == activation_key
170 key == activation_key
171 end
171 end
172
172
173 def self.random_password(length=5)
173 def self.random_password(length=5)
174 chars = 'abcdefghjkmnopqrstuvwxyz'
174 chars = 'abcdefghjkmnopqrstuvwxyz'
175 password = ''
175 password = ''
176 length.times { password << chars[rand(chars.length - 1)] }
176 length.times { password << chars[rand(chars.length - 1)] }
177 password
177 password
178 end
178 end
179
179
180 def self.find_non_admin_with_prefix(prefix='')
180 def self.find_non_admin_with_prefix(prefix='')
181 users = User.find(:all)
181 users = User.find(:all)
182 return users.find_all { |u| !(u.admin?) and u.login.index(prefix)==0 }
182 return users.find_all { |u| !(u.admin?) and u.login.index(prefix)==0 }
183 end
183 end
184
184
185 # Contest information
185 # Contest information
186
186
187 def contest_time_left
187 def contest_time_left
188 if Configuration.contest_mode?
188 if Configuration.contest_mode?
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 + if site.finished?
213 + return true
214 + elsif codejom_status!=nil
215 + return (not codejom_status.alive)
216 + else
217 + return false
218 + end
213 elsif Configuration.indv_contest_mode?
219 elsif Configuration.indv_contest_mode?
214 time_limit = Configuration.contest_time_limit
220 time_limit = Configuration.contest_time_limit
215
221
216 return false if contest_stat==nil
222 return false if contest_stat==nil
217
223
218 return contest_time_left == 0
224 return contest_time_left == 0
219 else
225 else
220 return false
226 return false
221 end
227 end
222 end
228 end
223
229
224 def contest_started?
230 def contest_started?
225 if Configuration.contest_mode?
231 if Configuration.contest_mode?
226 return true if site==nil
232 return true if site==nil
227 return site.started
233 return site.started
228 else
234 else
229 return true
235 return true
230 end
236 end
231 end
237 end
232
238
233 # For Code Jom
239 # For Code Jom
234 def update_codejom_status
240 def update_codejom_status
235 status = codejom_status || CodejomStatus.new(:user => self)
241 status = codejom_status || CodejomStatus.new(:user => self)
236 problem_count = Problem.available_problem_count
242 problem_count = Problem.available_problem_count
237 status.num_problems_passed = (self.submission_statuses.find_all {|s| s.passed and s.problem.available }).length
243 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
244 status.alive = (problem_count - (status.num_problems_passed)) <= CODEJOM_MAX_ALIVE_LEVEL
239 status.save
245 status.save
240 end
246 end
241
247
242 def codejom_level
248 def codejom_level
243 problem_count = Problem.available_problem_count
249 problem_count = Problem.available_problem_count
244 if codejom_status!=nil
250 if codejom_status!=nil
245 return problem_count - codejom_status.num_problems_passed
251 return problem_count - codejom_status.num_problems_passed
246 else
252 else
247 return problem_count
253 return problem_count
248 end
254 end
249 end
255 end
250
256
251 protected
257 protected
252 def encrypt_new_password
258 def encrypt_new_password
253 return if password.blank?
259 return if password.blank?
254 self.salt = (10+rand(90)).to_s
260 self.salt = (10+rand(90)).to_s
255 self.hashed_password = User.encrypt(self.password,self.salt)
261 self.hashed_password = User.encrypt(self.password,self.salt)
256 end
262 end
257
263
258 def assign_default_site
264 def assign_default_site
259 # have to catch error when migrating (because self.site is not available).
265 # have to catch error when migrating (because self.site is not available).
260 begin
266 begin
261 if self.site==nil
267 if self.site==nil
262 self.site = Site.find_by_name('default')
268 self.site = Site.find_by_name('default')
263 if self.site==nil
269 if self.site==nil
264 self.site = Site.find(1) # when 'default has be renamed'
270 self.site = Site.find(1) # when 'default has be renamed'
265 end
271 end
266 end
272 end
267 rescue
273 rescue
268 end
274 end
269 end
275 end
270
276
271 def password_required?
277 def password_required?
272 self.hashed_password.blank? || !self.password.blank?
278 self.hashed_password.blank? || !self.password.blank?
273 end
279 end
274
280
275 def self.encrypt(string,salt)
281 def self.encrypt(string,salt)
276 Digest::SHA1.hexdigest(salt + string)
282 Digest::SHA1.hexdigest(salt + string)
277 end
283 end
278
284
279 def uniqueness_of_email_from_activated_users
285 def uniqueness_of_email_from_activated_users
280 user = User.activated_users.find_by_email(self.email)
286 user = User.activated_users.find_by_email(self.email)
281 if user and (user.login != self.login)
287 if user and (user.login != self.login)
282 self.errors.add_to_base("Email has already been taken")
288 self.errors.add_to_base("Email has already been taken")
283 end
289 end
284 end
290 end
285
291
286 def enough_time_interval_between_same_email_registrations
292 def enough_time_interval_between_same_email_registrations
287 return if !self.new_record?
293 return if !self.new_record?
288 return if self.activated
294 return if self.activated
289 open_user = User.find_by_email(self.email,
295 open_user = User.find_by_email(self.email,
290 :order => 'created_at DESC')
296 :order => 'created_at DESC')
291 if open_user and open_user.created_at and
297 if open_user and open_user.created_at and
292 (open_user.created_at > Time.now.gmtime - 5.minutes)
298 (open_user.created_at > Time.now.gmtime - 5.minutes)
293 self.errors.add_to_base("There are already unactivated registrations with this e-mail address (please wait for 5 minutes)")
299 self.errors.add_to_base("There are already unactivated registrations with this e-mail address (please wait for 5 minutes)")
294 end
300 end
295 end
301 end
296
302
297 def email_validation?
303 def email_validation?
298 begin
304 begin
299 return VALIDATE_USER_EMAILS
305 return VALIDATE_USER_EMAILS
300 rescue
306 rescue
301 return false
307 return false
302 end
308 end
303 end
309 end
304
310
305
311
306 def school_names_for_high_school_users
312 def school_names_for_high_school_users
307 if self.high_school
313 if self.high_school
308 if (self.member1_school_name=='' or
314 if (self.member1_school_name=='' or
You need to be logged in to leave comments. Login now