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