Description:
shows contest start confirmation for indv contest
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r302:77a5c6e76df3 - - 4 files changed: 45 inserted, 4 deleted
@@ -0,0 +1,12 | |||
|
1 | + = user_title_bar(@user) | |
|
2 | + | |
|
3 | + %center | |
|
4 | + You will participate in contest: | |
|
5 | + - @contests.each do |contest| | |
|
6 | + = contest.title | |
|
7 | + %br | |
|
8 | + | |
|
9 | + The timer will start after you click the start button. | |
|
10 | + | |
|
11 | + - form_tag :action => 'confirm_contest_start', :method => 'post' do | |
|
12 | + = submit_tag 'Start!', :confirm => 'Are you sure?' |
@@ -1,58 +1,62 | |||
|
1 | 1 | class MainController < ApplicationController |
|
2 | 2 | |
|
3 | 3 | before_filter :authenticate, :except => [:index, :login] |
|
4 | 4 | before_filter :check_viewability, :except => [:index, :login] |
|
5 | 5 | |
|
6 |
- append_before_filter :update |
|
|
6 | + append_before_filter :confirm_and_update_start_time, | |
|
7 | + :except => [:index, | |
|
8 | + :login, | |
|
9 | + :confirm_contest_start] | |
|
7 | 10 | |
|
8 | 11 | # to prevent log in box to be shown when user logged out of the |
|
9 | 12 | # system only in some tab |
|
10 |
- prepend_before_filter :reject_announcement_refresh_when_logged_out, |
|
|
13 | + prepend_before_filter :reject_announcement_refresh_when_logged_out, | |
|
14 | + :only => [:announcements] | |
|
11 | 15 | |
|
12 | 16 | # COMMENTED OUT: filter in each action instead |
|
13 | 17 | # before_filter :verify_time_limit, :only => [:submit] |
|
14 | 18 | |
|
15 | 19 | verify :method => :post, :only => [:submit], |
|
16 | 20 | :redirect_to => { :action => :index } |
|
17 | 21 | |
|
18 | 22 | # COMMENT OUT: only need when having high load |
|
19 | 23 | # caches_action :index, :login |
|
20 | 24 | |
|
21 | 25 | # NOTE: This method is not actually needed, 'config/routes.rb' has |
|
22 | 26 | # assigned action login as a default action. |
|
23 | 27 | def index |
|
24 | 28 | redirect_to :action => 'login' |
|
25 | 29 | end |
|
26 | 30 | |
|
27 | 31 | def login |
|
28 | 32 | saved_notice = flash[:notice] |
|
29 | 33 | reset_session |
|
30 | 34 | flash.now[:notice] = saved_notice |
|
31 | 35 | |
|
32 | 36 | # EXPERIMENT: |
|
33 | 37 | # Hide login if in single user mode and the url does not |
|
34 | 38 | # explicitly specify /login |
|
35 | 39 | # |
|
36 | 40 | # logger.info "PATH: #{request.path}" |
|
37 | 41 | # if Configuration['system.single_user_mode'] and |
|
38 | 42 | # request.path!='/main/login' |
|
39 | 43 | # @hidelogin = true |
|
40 | 44 | # end |
|
41 | 45 | |
|
42 | 46 | @announcements = Announcement.find_for_frontpage |
|
43 | 47 | render :action => 'login', :layout => 'empty' |
|
44 | 48 | end |
|
45 | 49 | |
|
46 | 50 | def list |
|
47 | 51 | prepare_list_information |
|
48 | 52 | end |
|
49 | 53 | |
|
50 | 54 | def help |
|
51 | 55 | @user = User.find(session[:user_id]) |
|
52 | 56 | end |
|
53 | 57 | |
|
54 | 58 | def submit |
|
55 | 59 | user = User.find(session[:user_id]) |
|
56 | 60 | |
|
57 | 61 | @submission = Submission.new(params[:submission]) |
|
58 | 62 | @submission.user = user |
@@ -138,96 +142,107 | |||
|
138 | 142 | def load_output |
|
139 | 143 | if !Configuration.show_grading_result or params[:num]==nil |
|
140 | 144 | redirect_to :action => 'list' and return |
|
141 | 145 | end |
|
142 | 146 | @user = User.find(session[:user_id]) |
|
143 | 147 | @submission = Submission.find(params[:id]) |
|
144 | 148 | if @submission.user!=@user |
|
145 | 149 | flash[:notice] = 'You are not allowed to view result of other users.' |
|
146 | 150 | redirect_to :action => 'list' and return |
|
147 | 151 | end |
|
148 | 152 | case_num = params[:num].to_i |
|
149 | 153 | out_filename = output_filename(@user.login, |
|
150 | 154 | @submission.problem.name, |
|
151 | 155 | @submission.id, |
|
152 | 156 | case_num) |
|
153 | 157 | if !FileTest.exists?(out_filename) |
|
154 | 158 | flash[:notice] = 'Output not found.' |
|
155 | 159 | redirect_to :action => 'list' and return |
|
156 | 160 | end |
|
157 | 161 | |
|
158 | 162 | if defined?(USE_APACHE_XSENDFILE) and USE_APACHE_XSENDFILE |
|
159 | 163 | response.headers['Content-Type'] = "application/force-download" |
|
160 | 164 | response.headers['Content-Disposition'] = "attachment; filename=\"output-#{case_num}.txt\"" |
|
161 | 165 | response.headers["X-Sendfile"] = out_filename |
|
162 | 166 | response.headers['Content-length'] = File.size(out_filename) |
|
163 | 167 | render :nothing => true |
|
164 | 168 | else |
|
165 | 169 | send_file out_filename, :stream => false, :filename => "output-#{case_num}.txt", :type => "text/plain" |
|
166 | 170 | end |
|
167 | 171 | end |
|
168 | 172 | |
|
169 | 173 | def error |
|
170 | 174 | @user = User.find(session[:user_id]) |
|
171 | 175 | end |
|
172 | 176 | |
|
173 | 177 | # announcement refreshing and hiding methods |
|
174 | 178 | |
|
175 | 179 | def announcements |
|
176 | 180 | if params.has_key? 'recent' |
|
177 | 181 | prepare_announcements(params[:recent]) |
|
178 | 182 | else |
|
179 | 183 | prepare_announcements |
|
180 | 184 | end |
|
181 | 185 | render(:partial => 'announcement', |
|
182 | 186 | :collection => @announcements, |
|
183 | 187 | :locals => {:announcement_effect => true}) |
|
184 | 188 | end |
|
185 | 189 | |
|
190 | + def confirm_contest_start | |
|
191 | + user = User.find(session[:user_id]) | |
|
192 | + if request.method == :post | |
|
193 | + user.update_start_time | |
|
194 | + redirect_to :action => 'list' | |
|
195 | + else | |
|
196 | + @contests = user.contests | |
|
197 | + @user = user | |
|
198 | + end | |
|
199 | + end | |
|
200 | + | |
|
186 | 201 | protected |
|
187 | 202 | |
|
188 | 203 | def prepare_announcements(recent=nil) |
|
189 | 204 | if Configuration.show_tasks_to?(@user) |
|
190 | 205 | @announcements = Announcement.find_published(true) |
|
191 | 206 | else |
|
192 | 207 | @announcements = Announcement.find_published |
|
193 | 208 | end |
|
194 | 209 | if recent!=nil |
|
195 | 210 | recent_id = recent.to_i |
|
196 | 211 | @announcements = @announcements.find_all { |a| a.id > recent_id } |
|
197 | 212 | end |
|
198 | 213 | end |
|
199 | 214 | |
|
200 | 215 | def prepare_list_information |
|
201 | 216 | @user = User.find(session[:user_id]) |
|
202 | 217 | if not Configuration.multicontests? |
|
203 | 218 | @problems = @user.available_problems |
|
204 | 219 | else |
|
205 | 220 | @contest_problems = @user.available_problems_group_by_contests |
|
206 | 221 | @problems = @user.available_problems |
|
207 | 222 | end |
|
208 | 223 | @prob_submissions = {} |
|
209 | 224 | @problems.each do |p| |
|
210 | 225 | sub = Submission.find_last_by_user_and_problem(@user.id,p.id) |
|
211 | 226 | if sub!=nil |
|
212 | 227 | @prob_submissions[p.id] = { :count => sub.number, :submission => sub } |
|
213 | 228 | else |
|
214 | 229 | @prob_submissions[p.id] = { :count => 0, :submission => nil } |
|
215 | 230 | end |
|
216 | 231 | end |
|
217 | 232 | prepare_announcements |
|
218 | 233 | end |
|
219 | 234 | |
|
220 | 235 | def check_viewability |
|
221 | 236 | @user = User.find(session[:user_id]) |
|
222 | 237 | if (!Configuration.show_tasks_to?(@user)) and |
|
223 | 238 | ((action_name=='submission') or (action_name=='submit')) |
|
224 | 239 | redirect_to :action => 'list' and return |
|
225 | 240 | end |
|
226 | 241 | end |
|
227 | 242 | |
|
228 | 243 | def prepare_grading_result(submission) |
|
229 | 244 | if Configuration.task_grading_info.has_key? submission.problem.name |
|
230 | 245 | grading_info = Configuration.task_grading_info[submission.problem.name] |
|
231 | 246 | else |
|
232 | 247 | # guess task info from problem.full_score |
|
233 | 248 | cases = submission.problem.full_score / 10 |
@@ -289,68 +304,73 | |||
|
289 | 304 | return { |
|
290 | 305 | :num => case_num, |
|
291 | 306 | :msg => results[0], |
|
292 | 307 | :run_stat => run_stat, |
|
293 | 308 | :output => output_file, |
|
294 | 309 | :output_size => output_size |
|
295 | 310 | } |
|
296 | 311 | end |
|
297 | 312 | end |
|
298 | 313 | |
|
299 | 314 | # copied from grader/script/lib/test_request_helper.rb |
|
300 | 315 | def extract_running_stat(results) |
|
301 | 316 | running_stat_line = results[-1] |
|
302 | 317 | |
|
303 | 318 | # extract exit status line |
|
304 | 319 | run_stat = "" |
|
305 | 320 | if !(/[Cc]orrect/.match(results[0])) |
|
306 | 321 | run_stat = results[0].chomp |
|
307 | 322 | else |
|
308 | 323 | run_stat = 'Program exited normally' |
|
309 | 324 | end |
|
310 | 325 | |
|
311 | 326 | logger.info "Stat line: #{running_stat_line}" |
|
312 | 327 | |
|
313 | 328 | # extract running time |
|
314 | 329 | if res = /r(.*)u(.*)s/.match(running_stat_line) |
|
315 | 330 | seconds = (res[1].to_f + res[2].to_f) |
|
316 | 331 | time_stat = "Time used: #{seconds} sec." |
|
317 | 332 | else |
|
318 | 333 | seconds = nil |
|
319 | 334 | time_stat = "Time used: n/a sec." |
|
320 | 335 | end |
|
321 | 336 | |
|
322 | 337 | # extract memory usage |
|
323 | 338 | if res = /s(.*)m/.match(running_stat_line) |
|
324 | 339 | memory_used = res[1].to_i |
|
325 | 340 | else |
|
326 | 341 | memory_used = -1 |
|
327 | 342 | end |
|
328 | 343 | |
|
329 | 344 | return { |
|
330 | 345 | :msg => "#{run_stat}\n#{time_stat}", |
|
331 | 346 | :running_time => seconds, |
|
332 | 347 | :exit_status => run_stat, |
|
333 | 348 | :memory_usage => memory_used |
|
334 | 349 | } |
|
335 | 350 | end |
|
336 | 351 | |
|
337 |
- def update |
|
|
352 | + def confirm_and_update_start_time | |
|
338 | 353 | user = User.find(session[:user_id]) |
|
354 | + if (Configuration.indv_contest_mode? and | |
|
355 | + Configuration['contest.confirm_indv_contest_start'] and | |
|
356 | + !user.contest_started?) | |
|
357 | + redirect_to :action => 'confirm_contest_start' and return | |
|
358 | + end | |
|
339 | 359 | user.update_start_time |
|
340 | 360 | end |
|
341 | 361 | |
|
342 | 362 | def reject_announcement_refresh_when_logged_out |
|
343 | 363 | if not session[:user_id] |
|
344 | 364 | render :text => 'Access forbidden', :status => 403 |
|
345 | 365 | end |
|
346 | 366 | |
|
347 | 367 | if Configuration.multicontests? |
|
348 | 368 | user = User.find(session[:user_id]) |
|
349 | 369 | if user.contest_stat.forced_logout |
|
350 | 370 | render :text => 'Access forbidden', :status => 403 |
|
351 | 371 | end |
|
352 | 372 | end |
|
353 | 373 | end |
|
354 | 374 | |
|
355 | 375 | end |
|
356 | 376 |
@@ -127,97 +127,100 | |||
|
127 | 127 | end |
|
128 | 128 | |
|
129 | 129 | # Contest information |
|
130 | 130 | |
|
131 | 131 | def self.find_users_with_no_contest() |
|
132 | 132 | users = User.find(:all) |
|
133 | 133 | return users.find_all { |u| u.contests.length == 0 } |
|
134 | 134 | end |
|
135 | 135 | |
|
136 | 136 | |
|
137 | 137 | def contest_time_left |
|
138 | 138 | if Configuration.contest_mode? |
|
139 | 139 | return nil if site==nil |
|
140 | 140 | return site.time_left |
|
141 | 141 | elsif Configuration.indv_contest_mode? |
|
142 | 142 | time_limit = Configuration.contest_time_limit |
|
143 | 143 | if time_limit == nil |
|
144 | 144 | return nil |
|
145 | 145 | end |
|
146 | 146 | if contest_stat==nil or contest_stat.started_at==nil |
|
147 | 147 | return (Time.now.gmtime + time_limit) - Time.now.gmtime |
|
148 | 148 | else |
|
149 | 149 | finish_time = contest_stat.started_at + time_limit |
|
150 | 150 | current_time = Time.now.gmtime |
|
151 | 151 | if current_time > finish_time |
|
152 | 152 | return 0 |
|
153 | 153 | else |
|
154 | 154 | return finish_time - current_time |
|
155 | 155 | end |
|
156 | 156 | end |
|
157 | 157 | else |
|
158 | 158 | return nil |
|
159 | 159 | end |
|
160 | 160 | end |
|
161 | 161 | |
|
162 | 162 | def contest_finished? |
|
163 | 163 | if Configuration.contest_mode? |
|
164 | 164 | return false if site==nil |
|
165 | 165 | return site.finished? |
|
166 | 166 | elsif Configuration.indv_contest_mode? |
|
167 | 167 | return false if self.contest_stat(true)==nil |
|
168 | 168 | return contest_time_left == 0 |
|
169 | 169 | else |
|
170 | 170 | return false |
|
171 | 171 | end |
|
172 | 172 | end |
|
173 | 173 | |
|
174 | 174 | def contest_started? |
|
175 | - if Configuration.contest_mode? | |
|
175 | + if Configuration.indv_contest_mode? | |
|
176 | + stat = self.contest_stat | |
|
177 | + return ((stat != nil) and (stat.started_at != nil)) | |
|
178 | + elsif Configuration.contest_mode? | |
|
176 | 179 | return true if site==nil |
|
177 | 180 | return site.started |
|
178 | 181 | else |
|
179 | 182 | return true |
|
180 | 183 | end |
|
181 | 184 | end |
|
182 | 185 | |
|
183 | 186 | def update_start_time |
|
184 | 187 | stat = self.contest_stat |
|
185 | 188 | if stat == nil or stat.started_at == nil |
|
186 | 189 | stat ||= UserContestStat.new(:user => self) |
|
187 | 190 | stat.started_at = Time.now.gmtime |
|
188 | 191 | stat.save |
|
189 | 192 | end |
|
190 | 193 | end |
|
191 | 194 | |
|
192 | 195 | def problem_in_user_contests?(problem) |
|
193 | 196 | problem_contests = problem.contests.all |
|
194 | 197 | |
|
195 | 198 | if problem_contests.length == 0 # this is public contest |
|
196 | 199 | return true |
|
197 | 200 | end |
|
198 | 201 | |
|
199 | 202 | contests.each do |contest| |
|
200 | 203 | if problem_contests.find {|c| c.id == contest.id } |
|
201 | 204 | return true |
|
202 | 205 | end |
|
203 | 206 | end |
|
204 | 207 | return false |
|
205 | 208 | end |
|
206 | 209 | |
|
207 | 210 | def available_problems_group_by_contests |
|
208 | 211 | contest_problems = [] |
|
209 | 212 | pin = {} |
|
210 | 213 | contests.enabled.each do |contest| |
|
211 | 214 | available_problems = contest.problems.available |
|
212 | 215 | contest_problems << { |
|
213 | 216 | :contest => contest, |
|
214 | 217 | :problems => available_problems |
|
215 | 218 | } |
|
216 | 219 | available_problems.each {|p| pin[p.id] = true} |
|
217 | 220 | end |
|
218 | 221 | other_avaiable_problems = Problem.available.find_all {|p| pin[p.id]==nil and p.contests.length==0} |
|
219 | 222 | contest_problems << { |
|
220 | 223 | :contest => nil, |
|
221 | 224 | :problems => other_avaiable_problems |
|
222 | 225 | } |
|
223 | 226 | return contest_problems |
@@ -56,96 +56,102 | |||
|
56 | 56 | { |
|
57 | 57 | :key => 'system.online_registration', |
|
58 | 58 | :value_type => 'boolean', |
|
59 | 59 | :default_value => 'false', |
|
60 | 60 | :description => 'This option enables online registration.' |
|
61 | 61 | }, |
|
62 | 62 | |
|
63 | 63 | # If Configuration['system.online_registration'] is true, the |
|
64 | 64 | # system allows online registration, and will use these |
|
65 | 65 | # information for sending confirmation emails. |
|
66 | 66 | { |
|
67 | 67 | :key => 'system.online_registration.smtp', |
|
68 | 68 | :value_type => 'string', |
|
69 | 69 | :default_value => 'smtp.somehost.com' |
|
70 | 70 | }, |
|
71 | 71 | |
|
72 | 72 | { |
|
73 | 73 | :key => 'system.online_registration.from', |
|
74 | 74 | :value_type => 'string', |
|
75 | 75 | :default_value => 'your.email@address' |
|
76 | 76 | }, |
|
77 | 77 | |
|
78 | 78 | { |
|
79 | 79 | :key => 'system.admin_email', |
|
80 | 80 | :value_type => 'string', |
|
81 | 81 | :default_value => 'admin@admin.email' |
|
82 | 82 | }, |
|
83 | 83 | |
|
84 | 84 | { |
|
85 | 85 | :key => 'system.user_setting_enabled', |
|
86 | 86 | :value_type => 'boolean', |
|
87 | 87 | :default_value => 'true', |
|
88 | 88 | :description => 'If this option is true, users can change their settings' |
|
89 | 89 | }, |
|
90 | 90 | |
|
91 | 91 | # If Configuration['contest.test_request.early_timeout'] is true |
|
92 | 92 | # the user will not be able to use test request at 30 minutes |
|
93 | 93 | # before the contest ends. |
|
94 | 94 | { |
|
95 | 95 | :key => 'contest.test_request.early_timeout', |
|
96 | 96 | :value_type => 'boolean', |
|
97 | 97 | :default_value => 'false' |
|
98 | 98 | }, |
|
99 | 99 | |
|
100 | 100 | { |
|
101 | 101 | :key => 'system.multicontests', |
|
102 | 102 | :value_type => 'boolean', |
|
103 | 103 | :default_value => 'false' |
|
104 | + }, | |
|
105 | + | |
|
106 | + { | |
|
107 | + :key => 'contest.confirm_indv_contest_start', | |
|
108 | + :value_type => 'boolean', | |
|
109 | + :default_value => 'false' | |
|
104 | 110 | } |
|
105 | 111 | ] |
|
106 | 112 | |
|
107 | 113 | |
|
108 | 114 | def create_configuration_key(key, |
|
109 | 115 | value_type, |
|
110 | 116 | default_value, |
|
111 | 117 | description='') |
|
112 | 118 | conf = (Configuration.find_by_key(key) || |
|
113 | 119 | Configuration.new(:key => key, |
|
114 | 120 | :value_type => value_type, |
|
115 | 121 | :value => default_value)) |
|
116 | 122 | conf.description = description |
|
117 | 123 | conf.save |
|
118 | 124 | end |
|
119 | 125 | |
|
120 | 126 | def seed_config |
|
121 | 127 | CONFIGURATIONS.each do |conf| |
|
122 | 128 | if conf.has_key? :description |
|
123 | 129 | desc = conf[:description] |
|
124 | 130 | else |
|
125 | 131 | desc = '' |
|
126 | 132 | end |
|
127 | 133 | create_configuration_key(conf[:key], |
|
128 | 134 | conf[:value_type], |
|
129 | 135 | conf[:default_value], |
|
130 | 136 | desc) |
|
131 | 137 | end |
|
132 | 138 | end |
|
133 | 139 | |
|
134 | 140 | def seed_roles |
|
135 | 141 | return if Role.find_by_name('admin') |
|
136 | 142 | |
|
137 | 143 | role = Role.create(:name => 'admin') |
|
138 | 144 | user_admin_right = Right.create(:name => 'user_admin', |
|
139 | 145 | :controller => 'user_admin', |
|
140 | 146 | :action => 'all') |
|
141 | 147 | problem_admin_right = Right.create(:name=> 'problem_admin', |
|
142 | 148 | :controller => 'problems', |
|
143 | 149 | :action => 'all') |
|
144 | 150 | |
|
145 | 151 | graders_right = Right.create(:name => 'graders_admin', |
|
146 | 152 | :controller => 'graders', |
|
147 | 153 | :action => 'all') |
|
148 | 154 | |
|
149 | 155 | role.rights << user_admin_right; |
|
150 | 156 | role.rights << problem_admin_right; |
|
151 | 157 | role.rights << graders_right; |
You need to be logged in to leave comments.
Login now