Description:
Merge pull request #11 from wytesk133/master Various fixes
Commit status:
[Not Reviewed]
References:
merge default
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r372:0688baeb3e31 - - 5 files changed: 14 inserted, 11 deleted

@@ -1,50 +1,50
1 class ContestManagementController < ApplicationController
1 class ContestManagementController < ApplicationController
2
2
3 before_filter :admin_authorization
3 before_filter :admin_authorization
4
4
5 def index
5 def index
6 @num_contests = Contest.count()
6 @num_contests = Contest.count()
7 end
7 end
8
8
9 def user_stat
9 def user_stat
10 if not GraderConfiguration.indv_contest_mode?
10 if not GraderConfiguration.indv_contest_mode?
11 redirect_to :action => 'index' and return
11 redirect_to :action => 'index' and return
12 end
12 end
13
13
14 @users = User.find(:all)
14 @users = User.find(:all)
15 @start_times = {}
15 @start_times = {}
16 UserContestStat.find(:all).each do |stat|
16 UserContestStat.find(:all).each do |stat|
17 @start_times[stat.user_id] = stat.started_at
17 @start_times[stat.user_id] = stat.started_at
18 end
18 end
19 end
19 end
20
20
21 def clear_stat
21 def clear_stat
22 user = User.find(params[:id])
22 user = User.find(params[:id])
23 if user.contest_stat!=nil
23 if user.contest_stat!=nil
24 user.contest_stat.destroy
24 user.contest_stat.destroy
25 end
25 end
26 redirect_to :action => 'user_stat'
26 redirect_to :action => 'user_stat'
27 end
27 end
28
28
29 def clear_all_stat
29 def clear_all_stat
30 if not GraderConfiguration.indv_contest_mode?
30 if not GraderConfiguration.indv_contest_mode?
31 redirect_to :action => 'index' and return
31 redirect_to :action => 'index' and return
32 end
32 end
33
33
34 UserContestStat.delete_all()
34 UserContestStat.delete_all()
35 flash[:notice] = 'All start time statistic cleared.'
35 flash[:notice] = 'All start time statistic cleared.'
36 redirect_to :action => 'index'
36 redirect_to :action => 'index'
37 end
37 end
38
38
39 def change_contest_mode
39 def change_contest_mode
40 - if ['standard', 'contest', 'indv-contest'].include? params[:id]
40 + if ['standard', 'contest', 'indv-contest', 'analysis'].include? params[:id]
41 config = GraderConfiguration.find_by_key('system.mode')
41 config = GraderConfiguration.find_by_key('system.mode')
42 config.value = params[:id]
42 config.value = params[:id]
43 config.save
43 config.save
44 else
44 else
45 flash[:notice] = 'Wrong contest mode value'
45 flash[:notice] = 'Wrong contest mode value'
46 end
46 end
47 redirect_to :action => 'index'
47 redirect_to :action => 'index'
48 end
48 end
49
49
50 end
50 end
@@ -99,193 +99,193
99 else
99 else
100 flash[:notice] = 'Error viewing source'
100 flash[:notice] = 'Error viewing source'
101 redirect_to :action => 'list'
101 redirect_to :action => 'list'
102 end
102 end
103 end
103 end
104
104
105 def compiler_msg
105 def compiler_msg
106 @submission = Submission.find(params[:id])
106 @submission = Submission.find(params[:id])
107 if @submission.user_id == session[:user_id]
107 if @submission.user_id == session[:user_id]
108 render :action => 'compiler_msg', :layout => 'empty'
108 render :action => 'compiler_msg', :layout => 'empty'
109 else
109 else
110 flash[:notice] = 'Error viewing source'
110 flash[:notice] = 'Error viewing source'
111 redirect_to :action => 'list'
111 redirect_to :action => 'list'
112 end
112 end
113 end
113 end
114
114
115 def submission
115 def submission
116 @user = User.find(session[:user_id])
116 @user = User.find(session[:user_id])
117 @problems = @user.available_problems
117 @problems = @user.available_problems
118 if params[:id]==nil
118 if params[:id]==nil
119 @problem = nil
119 @problem = nil
120 @submissions = nil
120 @submissions = nil
121 else
121 else
122 @problem = Problem.find_by_name(params[:id])
122 @problem = Problem.find_by_name(params[:id])
123 if not @problem.available
123 if not @problem.available
124 redirect_to :action => 'list'
124 redirect_to :action => 'list'
125 flash[:notice] = 'Error: submissions for that problem are not viewable.'
125 flash[:notice] = 'Error: submissions for that problem are not viewable.'
126 return
126 return
127 end
127 end
128 @submissions = Submission.find_all_by_user_problem(@user.id, @problem.id)
128 @submissions = Submission.find_all_by_user_problem(@user.id, @problem.id)
129 end
129 end
130 end
130 end
131
131
132 def result
132 def result
133 if !GraderConfiguration.show_grading_result
133 if !GraderConfiguration.show_grading_result
134 redirect_to :action => 'list' and return
134 redirect_to :action => 'list' and return
135 end
135 end
136 @user = User.find(session[:user_id])
136 @user = User.find(session[:user_id])
137 @submission = Submission.find(params[:id])
137 @submission = Submission.find(params[:id])
138 if @submission.user!=@user
138 if @submission.user!=@user
139 flash[:notice] = 'You are not allowed to view result of other users.'
139 flash[:notice] = 'You are not allowed to view result of other users.'
140 redirect_to :action => 'list' and return
140 redirect_to :action => 'list' and return
141 end
141 end
142 prepare_grading_result(@submission)
142 prepare_grading_result(@submission)
143 end
143 end
144
144
145 def load_output
145 def load_output
146 if !GraderConfiguration.show_grading_result or params[:num]==nil
146 if !GraderConfiguration.show_grading_result or params[:num]==nil
147 redirect_to :action => 'list' and return
147 redirect_to :action => 'list' and return
148 end
148 end
149 @user = User.find(session[:user_id])
149 @user = User.find(session[:user_id])
150 @submission = Submission.find(params[:id])
150 @submission = Submission.find(params[:id])
151 if @submission.user!=@user
151 if @submission.user!=@user
152 flash[:notice] = 'You are not allowed to view result of other users.'
152 flash[:notice] = 'You are not allowed to view result of other users.'
153 redirect_to :action => 'list' and return
153 redirect_to :action => 'list' and return
154 end
154 end
155 case_num = params[:num].to_i
155 case_num = params[:num].to_i
156 out_filename = output_filename(@user.login,
156 out_filename = output_filename(@user.login,
157 @submission.problem.name,
157 @submission.problem.name,
158 @submission.id,
158 @submission.id,
159 case_num)
159 case_num)
160 if !FileTest.exists?(out_filename)
160 if !FileTest.exists?(out_filename)
161 flash[:notice] = 'Output not found.'
161 flash[:notice] = 'Output not found.'
162 redirect_to :action => 'list' and return
162 redirect_to :action => 'list' and return
163 end
163 end
164
164
165 if defined?(USE_APACHE_XSENDFILE) and USE_APACHE_XSENDFILE
165 if defined?(USE_APACHE_XSENDFILE) and USE_APACHE_XSENDFILE
166 response.headers['Content-Type'] = "application/force-download"
166 response.headers['Content-Type'] = "application/force-download"
167 response.headers['Content-Disposition'] = "attachment; filename=\"output-#{case_num}.txt\""
167 response.headers['Content-Disposition'] = "attachment; filename=\"output-#{case_num}.txt\""
168 response.headers["X-Sendfile"] = out_filename
168 response.headers["X-Sendfile"] = out_filename
169 response.headers['Content-length'] = File.size(out_filename)
169 response.headers['Content-length'] = File.size(out_filename)
170 render :nothing => true
170 render :nothing => true
171 else
171 else
172 send_file out_filename, :stream => false, :filename => "output-#{case_num}.txt", :type => "text/plain"
172 send_file out_filename, :stream => false, :filename => "output-#{case_num}.txt", :type => "text/plain"
173 end
173 end
174 end
174 end
175
175
176 def error
176 def error
177 @user = User.find(session[:user_id])
177 @user = User.find(session[:user_id])
178 end
178 end
179
179
180 # announcement refreshing and hiding methods
180 # announcement refreshing and hiding methods
181
181
182 def announcements
182 def announcements
183 if params.has_key? 'recent'
183 if params.has_key? 'recent'
184 prepare_announcements(params[:recent])
184 prepare_announcements(params[:recent])
185 else
185 else
186 prepare_announcements
186 prepare_announcements
187 end
187 end
188 render(:partial => 'announcement',
188 render(:partial => 'announcement',
189 :collection => @announcements,
189 :collection => @announcements,
190 :locals => {:announcement_effect => true})
190 :locals => {:announcement_effect => true})
191 end
191 end
192
192
193 def confirm_contest_start
193 def confirm_contest_start
194 user = User.find(session[:user_id])
194 user = User.find(session[:user_id])
195 - if request.method == :post
195 + if request.method == 'POST'
196 user.update_start_time
196 user.update_start_time
197 redirect_to :action => 'list'
197 redirect_to :action => 'list'
198 else
198 else
199 @contests = user.contests
199 @contests = user.contests
200 @user = user
200 @user = user
201 end
201 end
202 end
202 end
203
203
204 protected
204 protected
205
205
206 def prepare_announcements(recent=nil)
206 def prepare_announcements(recent=nil)
207 if GraderConfiguration.show_tasks_to?(@user)
207 if GraderConfiguration.show_tasks_to?(@user)
208 @announcements = Announcement.find_published(true)
208 @announcements = Announcement.find_published(true)
209 else
209 else
210 @announcements = Announcement.find_published
210 @announcements = Announcement.find_published
211 end
211 end
212 if recent!=nil
212 if recent!=nil
213 recent_id = recent.to_i
213 recent_id = recent.to_i
214 @announcements = @announcements.find_all { |a| a.id > recent_id }
214 @announcements = @announcements.find_all { |a| a.id > recent_id }
215 end
215 end
216 end
216 end
217
217
218 def prepare_list_information
218 def prepare_list_information
219 @user = User.find(session[:user_id])
219 @user = User.find(session[:user_id])
220 if not GraderConfiguration.multicontests?
220 if not GraderConfiguration.multicontests?
221 @problems = @user.available_problems
221 @problems = @user.available_problems
222 else
222 else
223 @contest_problems = @user.available_problems_group_by_contests
223 @contest_problems = @user.available_problems_group_by_contests
224 @problems = @user.available_problems
224 @problems = @user.available_problems
225 end
225 end
226 @prob_submissions = {}
226 @prob_submissions = {}
227 @problems.each do |p|
227 @problems.each do |p|
228 sub = Submission.find_last_by_user_and_problem(@user.id,p.id)
228 sub = Submission.find_last_by_user_and_problem(@user.id,p.id)
229 if sub!=nil
229 if sub!=nil
230 @prob_submissions[p.id] = { :count => sub.number, :submission => sub }
230 @prob_submissions[p.id] = { :count => sub.number, :submission => sub }
231 else
231 else
232 @prob_submissions[p.id] = { :count => 0, :submission => nil }
232 @prob_submissions[p.id] = { :count => 0, :submission => nil }
233 end
233 end
234 end
234 end
235 prepare_announcements
235 prepare_announcements
236 end
236 end
237
237
238 def check_viewability
238 def check_viewability
239 @user = User.find(session[:user_id])
239 @user = User.find(session[:user_id])
240 if (!GraderConfiguration.show_tasks_to?(@user)) and
240 if (!GraderConfiguration.show_tasks_to?(@user)) and
241 ((action_name=='submission') or (action_name=='submit'))
241 ((action_name=='submission') or (action_name=='submit'))
242 redirect_to :action => 'list' and return
242 redirect_to :action => 'list' and return
243 end
243 end
244 end
244 end
245
245
246 def prepare_grading_result(submission)
246 def prepare_grading_result(submission)
247 if GraderConfiguration.task_grading_info.has_key? submission.problem.name
247 if GraderConfiguration.task_grading_info.has_key? submission.problem.name
248 grading_info = GraderConfiguration.task_grading_info[submission.problem.name]
248 grading_info = GraderConfiguration.task_grading_info[submission.problem.name]
249 else
249 else
250 # guess task info from problem.full_score
250 # guess task info from problem.full_score
251 cases = submission.problem.full_score / 10
251 cases = submission.problem.full_score / 10
252 grading_info = {
252 grading_info = {
253 'testruns' => cases,
253 'testruns' => cases,
254 'testcases' => cases
254 'testcases' => cases
255 }
255 }
256 end
256 end
257 @test_runs = []
257 @test_runs = []
258 if grading_info['testruns'].is_a? Integer
258 if grading_info['testruns'].is_a? Integer
259 trun_count = grading_info['testruns']
259 trun_count = grading_info['testruns']
260 trun_count.times do |i|
260 trun_count.times do |i|
261 @test_runs << [ read_grading_result(@user.login,
261 @test_runs << [ read_grading_result(@user.login,
262 submission.problem.name,
262 submission.problem.name,
263 submission.id,
263 submission.id,
264 i+1) ]
264 i+1) ]
265 end
265 end
266 else
266 else
267 grading_info['testruns'].keys.sort.each do |num|
267 grading_info['testruns'].keys.sort.each do |num|
268 run = []
268 run = []
269 testrun = grading_info['testruns'][num]
269 testrun = grading_info['testruns'][num]
270 testrun.each do |c|
270 testrun.each do |c|
271 run << read_grading_result(@user.login,
271 run << read_grading_result(@user.login,
272 submission.problem.name,
272 submission.problem.name,
273 submission.id,
273 submission.id,
274 c)
274 c)
275 end
275 end
276 @test_runs << run
276 @test_runs << run
277 end
277 end
278 end
278 end
279 end
279 end
280
280
281 def grading_result_dir(user_name, problem_name, submission_id, case_num)
281 def grading_result_dir(user_name, problem_name, submission_id, case_num)
282 return "#{GRADING_RESULT_DIR}/#{user_name}/#{problem_name}/#{submission_id}/test-result/#{case_num}"
282 return "#{GRADING_RESULT_DIR}/#{user_name}/#{problem_name}/#{submission_id}/test-result/#{case_num}"
283 end
283 end
284
284
285 def output_filename(user_name, problem_name, submission_id, case_num)
285 def output_filename(user_name, problem_name, submission_id, case_num)
286 dir = grading_result_dir(user_name,problem_name, submission_id, case_num)
286 dir = grading_result_dir(user_name,problem_name, submission_id, case_num)
287 return "#{dir}/output.txt"
287 return "#{dir}/output.txt"
288 end
288 end
289
289
290 def read_grading_result(user_name, problem_name, submission_id, case_num)
290 def read_grading_result(user_name, problem_name, submission_id, case_num)
291 dir = grading_result_dir(user_name,problem_name, submission_id, case_num)
291 dir = grading_result_dir(user_name,problem_name, submission_id, case_num)
@@ -1,31 +1,34
1 %h1 Contest management
1 %h1 Contest management
2
2
3 .infobox
3 .infobox
4
4
5 - if @num_contests>1
5 - if @num_contests>1
6 %b Multiple contests:
6 %b Multiple contests:
7 = "There are #{@num_contests} contests running."
7 = "There are #{@num_contests} contests running."
8 - else
8 - else
9 %b Single contest:
9 %b Single contest:
10 =raw "[#{link_to 'Add/remove contests', :controller => 'contests', :action => 'index'}]"
10 =raw "[#{link_to 'Add/remove contests', :controller => 'contests', :action => 'index'}]"
11
11
12 .infobox
12 .infobox
13 %b Web interface mode:
13 %b Web interface mode:
14 - - if (not GraderConfiguration.contest_mode?) and (not GraderConfiguration.indv_contest_mode?)
14 + - if GraderConfiguration.analysis_mode?
15 - standard mode
15 + Analysis Mode
16 + - elsif (not GraderConfiguration.contest_mode?) and (not GraderConfiguration.indv_contest_mode?)
17 + Standard Mode
16 - elsif GraderConfiguration.contest_mode?
18 - elsif GraderConfiguration.contest_mode?
17 - normal contest mode.
19 + Normal Contest Mode
18 - else
20 - else
19 - individual contest mode.
21 + Individual Contest Mode
20
22
21 %br/
23 %br/
22 Change mode to:
24 Change mode to:
23 - =raw "[#{link_to 'standard', :action => 'change_contest_mode', :id => 'standard'}]"
25 + =raw "[#{link_to 'Standard', :action => 'change_contest_mode', :id => 'standard'}]"
24 - =raw "[#{link_to 'contest', :action => 'change_contest_mode', :id => 'contest'}]"
26 + =raw "[#{link_to 'Contest', :action => 'change_contest_mode', :id => 'contest'}]"
25 - =raw "[#{link_to 'individual contest', :action => 'change_contest_mode', :id => 'indv-contest'}]"
27 + =raw "[#{link_to 'Individual Contest', :action => 'change_contest_mode', :id => 'indv-contest'}]"
28 + =raw "[#{link_to 'Analysis', :action => 'change_contest_mode', :id => 'analysis'}]"
26
29
27 - if GraderConfiguration.indv_contest_mode?
30 - if GraderConfiguration.indv_contest_mode?
28 = render :partial => 'indv_contest_mode_index'
31 = render :partial => 'indv_contest_mode_index'
29
32
30 %br/
33 %br/
31
34
@@ -1,40 +1,40
1 %h1= "Test Request: #{@test_request.id}"
1 %h1= "Test Request: #{@test_request.id}"
2
2
3 %p
3 %p
4 User:
4 User:
5 = "#{@test_request.user.login}"
5 = "#{@test_request.user.login}"
6 %br/
6 %br/
7 Problem:
7 Problem:
8 - if @test_request.problem!=nil
8 - if @test_request.problem!=nil
9 = "#{@test_request.problem.full_name}"
9 = "#{@test_request.problem.full_name}"
10 - else
10 - else
11 = "(n/a)"
11 = "(n/a)"
12 %br/
12 %br/
13 = "Submission: #{@test_request.submission.number}"
13 = "Submission: #{@test_request.submission.number}"
14 = link_to '[view submission]', :action => 'submission', :id => @test_request.submission.id
14 = link_to '[view submission]', :action => 'submission', :id => @test_request.submission.id
15 %br/
15 %br/
16 = "Test submitted at: #{format_short_time(@test_request.submitted_at)}"
16 = "Test submitted at: #{format_short_time(@test_request.submitted_at)}"
17 %br/
17 %br/
18 = "Execution time: #{@test_request.running_time} s."
18 = "Execution time: #{@test_request.running_time} s."
19 %br/
19 %br/
20 = "Memory usage: #{@test_request.memory_usage}kb"
20 = "Memory usage: #{@test_request.memory_usage}kb"
21 %br/
21 %br/
22 %b= @test_request.exit_status
22 %b= @test_request.exit_status
23 %br/
23 %br/
24
24
25 - if @test_request.compiler_message!=nil and @test_request.compiler_message!=''
25 - if @test_request.compiler_message!=nil and @test_request.compiler_message!=''
26 %b Compiler Message
26 %b Compiler Message
27 %div{:style => "border: 1px solid black; background: lightgrey"}
27 %div{:style => "border: 1px solid black; background: lightgrey"}
28 - = simple_format(truncate((@test_request.compiler_message or ''),200))
28 + = simple_format(truncate((@test_request.compiler_message or ''), :length => 200))
29
29
30 %b Input (first 2kb)
30 %b Input (first 2kb)
31 %div{:style => "border: 1px solid black; background: lightgrey"}
31 %div{:style => "border: 1px solid black; background: lightgrey"}
32 - if @test_request.input_file_name!=nil
32 - if @test_request.input_file_name!=nil
33 = simple_format(read_textfile(@test_request.input_file_name,2048))
33 = simple_format(read_textfile(@test_request.input_file_name,2048))
34
34
35 %b Output (first 2kb)
35 %b Output (first 2kb)
36 %div{:style => "border: 1px solid black; background: lightgrey"}
36 %div{:style => "border: 1px solid black; background: lightgrey"}
37 - if @test_request.output_file_name!=nil
37 - if @test_request.output_file_name!=nil
38 = simple_format(read_textfile(@test_request.output_file_name,2048))
38 = simple_format(read_textfile(@test_request.output_file_name,2048))
39 - else
39 - else
40 (no output)
40 (no output)
@@ -1,16 +1,16
1 = user_title_bar(@user)
1 = user_title_bar(@user)
2
2
3 .announcementbox
3 .announcementbox
4 %span{:class => 'title'}
4 %span{:class => 'title'}
5 =t 'main.confirm_contest_start.box_title'
5 =t 'main.confirm_contest_start.box_title'
6 .announcement
6 .announcement
7 %center
7 %center
8 =t 'main.confirm_contest_start.contest_list'
8 =t 'main.confirm_contest_start.contest_list'
9 - @contests.each do |contest|
9 - @contests.each do |contest|
10 = contest.title
10 = contest.title
11 %br
11 %br
12
12
13 =t 'main.confirm_contest_start.timer_starts_after_click'
13 =t 'main.confirm_contest_start.timer_starts_after_click'
14
14
15 - = form_tag :action => 'confirm_contest_start', :method => 'post' do
15 + = form_tag :action => 'confirm_contest_start' do
16 = submit_tag t('main.confirm_contest_start.start_button'), :confirm => t('main.confirm_contest_start.start_button_confirm')
16 = submit_tag t('main.confirm_contest_start.start_button'), :confirm => t('main.confirm_contest_start.start_button_confirm')
You need to be logged in to leave comments. Login now