Description:
contest ends after user is dead, added status xml for visualization
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
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 | 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 | 15 |
|
|
17 | 16 |
|
|
18 | - end | |
|
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 |
@@ -57,54 +57,62 | |||
|
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 | + 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 | 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 |
|
86 | 93 | end |
|
94 | + end | |
|
87 | 95 | if !user.contest_started? |
|
88 | 96 | time_left = " " + (t 'title_bar.contest_not_started') |
|
89 | 97 | else |
|
90 | 98 | time_left = " " + (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"> |
@@ -188,49 +188,55 | |||
|
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 |
- |
|
|
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 |
You need to be logged in to leave comments.
Login now