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
@@ -33,95 +33,103
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
@@ -164,97 +164,103
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
You need to be logged in to leave comments. Login now