Description:
shows submission timeouts
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r382:c141e39c9118 - - 4 files changed: 57 inserted, 22 deleted
@@ -0,0 +1,37 | |||||
|
|
1 | + var TOIContest = { | ||
|
|
2 | + NO_TIMEOUT: -1, | ||
|
|
3 | + | ||
|
|
4 | + timeOuts: {}, | ||
|
|
5 | + | ||
|
|
6 | + problemSelectClick: function() { | ||
|
|
7 | + $$(".submission-submit-divs").each(function(item) { | ||
|
|
8 | + item.hide(); | ||
|
|
9 | + }); | ||
|
|
10 | + var problem_id = $('submission_problem_id').value; | ||
|
|
11 | + if ( problem_id < 0 ) { | ||
|
|
12 | + return; | ||
|
|
13 | + } | ||
|
|
14 | + $("submission_submit_div_" + problem_id + "_id").show(); | ||
|
|
15 | + }, | ||
|
|
16 | + | ||
|
|
17 | + confirmDownload: function() { | ||
|
|
18 | + return confirm("แน่ใจ?"); | ||
|
|
19 | + }, | ||
|
|
20 | + | ||
|
|
21 | + refreshTimeOutMessages: function() { | ||
|
|
22 | + for ( var pid in TOIContest.timeOuts ) { | ||
|
|
23 | + var timeOut = TOIContest.timeOuts[ pid ]; | ||
|
|
24 | + if ( timeOut != TOIContest.NO_TIMEOUT ) { | ||
|
|
25 | + if ( timeOut > 0 ) { | ||
|
|
26 | + var minLeft = parseInt(timeOut / 60); | ||
|
|
27 | + var secLeft = parseInt(timeOut % 60); | ||
|
|
28 | + $('submission_time_left_' + pid + '_id').innerHTML = '| <b>เหลือเวลาอีก ' + minLeft + ':' + secLeft + ' นาที</b>'; | ||
|
|
29 | + } else { | ||
|
|
30 | + $('submission_time_left_' + pid + '_id').innerHTML = '| <b>หมดเวลาส่ง</a>'; | ||
|
|
31 | + $('submission_form_'+ pid + '_id').hide(); | ||
|
|
32 | + } | ||
|
|
33 | + } | ||
|
|
34 | + } | ||
|
|
35 | + } | ||
|
|
36 | + }; | ||
|
|
37 | + |
@@ -83,392 +83,396 | |||||
|
83 | end |
|
83 | end |
|
84 | else |
|
84 | else |
|
85 | prepare_list_information |
|
85 | prepare_list_information |
|
86 | render :action => 'list' and return |
|
86 | render :action => 'list' and return |
|
87 | end |
|
87 | end |
|
88 | redirect_to :action => 'list' |
|
88 | redirect_to :action => 'list' |
|
89 | end |
|
89 | end |
|
90 |
|
90 | ||
|
91 | def source |
|
91 | def source |
|
92 | submission = Submission.find(params[:id]) |
|
92 | submission = Submission.find(params[:id]) |
|
93 | if ((submission.user_id == session[:user_id]) and |
|
93 | if ((submission.user_id == session[:user_id]) and |
|
94 | (submission.problem != nil) and |
|
94 | (submission.problem != nil) and |
|
95 | (submission.problem.available)) |
|
95 | (submission.problem.available)) |
|
96 | send_data(submission.source, |
|
96 | send_data(submission.source, |
|
97 | {:filename => submission.download_filename, |
|
97 | {:filename => submission.download_filename, |
|
98 | :type => 'text/plain'}) |
|
98 | :type => 'text/plain'}) |
|
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 | # thailandoi contests |
|
204 | # thailandoi contests |
|
205 |
|
205 | ||
|
206 | def verifying_testcase |
|
206 | def verifying_testcase |
|
207 | problem = Problem.find(params[:id]) |
|
207 | problem = Problem.find(params[:id]) |
|
208 | if !problem.available |
|
208 | if !problem.available |
|
209 | flash[:notice] = 'Error: problem is not available' |
|
209 | flash[:notice] = 'Error: problem is not available' |
|
210 | redirect_to :action => 'list' |
|
210 | redirect_to :action => 'list' |
|
211 | else |
|
211 | else |
|
212 | test_pair = TestPair.get_for(problem, false) |
|
212 | test_pair = TestPair.get_for(problem, false) |
|
213 | send_data(test_pair.input, |
|
213 | send_data(test_pair.input, |
|
214 | {:filename => problem.name + '-verifying-input.txt', |
|
214 | {:filename => problem.name + '-verifying-input.txt', |
|
215 | :type => 'text/plain'}) |
|
215 | :type => 'text/plain'}) |
|
216 | end |
|
216 | end |
|
217 | end |
|
217 | end |
|
218 |
|
218 | ||
|
219 | def testcase |
|
219 | def testcase |
|
220 | problem = Problem.find(params[:id]) |
|
220 | problem = Problem.find(params[:id]) |
|
221 | if !problem.available |
|
221 | if !problem.available |
|
222 | flash[:notice] = 'Error: problem is not available' |
|
222 | flash[:notice] = 'Error: problem is not available' |
|
223 | redirect_to :action => 'list' |
|
223 | redirect_to :action => 'list' |
|
224 | else |
|
224 | else |
|
225 | test_pair = TestPair.get_for(problem, true) |
|
225 | test_pair = TestPair.get_for(problem, true) |
|
226 |
|
226 | ||
|
227 | user = User.find(session[:user_id]) |
|
227 | user = User.find(session[:user_id]) |
|
228 | assignent = user.get_test_pair_assignment_for(problem) |
|
228 | assignent = user.get_test_pair_assignment_for(problem) |
|
229 |
|
229 | ||
|
230 | if !assignent |
|
230 | if !assignent |
|
231 | assignent = TestPairAssignment.new |
|
231 | assignent = TestPairAssignment.new |
|
232 | assignent.user = user |
|
232 | assignent.user = user |
|
233 | assignent.problem = problem |
|
233 | assignent.problem = problem |
|
234 | assignent.test_pair = test_pair |
|
234 | assignent.test_pair = test_pair |
|
235 | assignent.submitted = false |
|
235 | assignent.submitted = false |
|
236 | assignent.save |
|
236 | assignent.save |
|
237 | end |
|
237 | end |
|
238 |
|
238 | ||
|
239 | send_data(test_pair.input, |
|
239 | send_data(test_pair.input, |
|
240 | {:filename => problem.name + '-input.txt', |
|
240 | {:filename => problem.name + '-input.txt', |
|
241 | :type => 'text/plain'}) |
|
241 | :type => 'text/plain'}) |
|
242 | end |
|
242 | end |
|
243 | end |
|
243 | end |
|
244 |
|
244 | ||
|
245 | def verifying_submit |
|
245 | def verifying_submit |
|
246 | user = User.find(session[:user_id]) |
|
246 | user = User.find(session[:user_id]) |
|
247 | problem_id = params[:id] |
|
247 | problem_id = params[:id] |
|
248 | problem = Problem.find(problem_id) |
|
248 | problem = Problem.find(problem_id) |
|
249 |
|
249 | ||
|
250 | if !problem or !problem.available |
|
250 | if !problem or !problem.available |
|
251 | flash[:notice] = 'Error: problem is not available' |
|
251 | flash[:notice] = 'Error: problem is not available' |
|
252 | redirect_to :action => 'list' and return |
|
252 | redirect_to :action => 'list' and return |
|
253 | end |
|
253 | end |
|
254 |
|
254 | ||
|
255 | test_pair = TestPair.get_for(problem, false) |
|
255 | test_pair = TestPair.get_for(problem, false) |
|
256 | if (params['output_file']) and (params['output_file']!='') |
|
256 | if (params['output_file']) and (params['output_file']!='') |
|
257 | output = params['output_file'].read |
|
257 | output = params['output_file'].read |
|
258 |
|
258 | ||
|
259 | @current_problem = problem |
|
259 | @current_problem = problem |
|
260 | @grading_result = grade(output, test_pair.solution) |
|
260 | @grading_result = grade(output, test_pair.solution) |
|
261 | prepare_list_information |
|
261 | prepare_list_information |
|
262 | render :action => 'list' and return |
|
262 | render :action => 'list' and return |
|
263 | else |
|
263 | else |
|
264 | flash[:notice] = 'Error: output file errors' |
|
264 | flash[:notice] = 'Error: output file errors' |
|
265 | redirect_to :action => 'list' |
|
265 | redirect_to :action => 'list' |
|
266 | end |
|
266 | end |
|
267 | end |
|
267 | end |
|
268 |
|
268 | ||
|
269 | protected |
|
269 | protected |
|
270 |
|
270 | ||
|
271 | def grade(output, solution) |
|
271 | def grade(output, solution) |
|
272 | out_items = output.split |
|
272 | out_items = output.split |
|
273 | sol_items = solution.split |
|
273 | sol_items = solution.split |
|
274 | res = '' |
|
274 | res = '' |
|
|
275 | + f = 0 | ||
|
|
276 | + s = 0 | ||
|
275 | sol_items.length.times do |i| |
|
277 | sol_items.length.times do |i| |
|
|
278 | + f += 1 | ||
|
276 | if out_items[i] == sol_items[i] |
|
279 | if out_items[i] == sol_items[i] |
|
277 | res = res + 'P' |
|
280 | res = res + 'P' |
|
|
281 | + s += 1 | ||
|
278 | else |
|
282 | else |
|
279 | res = res + '-' |
|
283 | res = res + '-' |
|
280 | end |
|
284 | end |
|
281 | end |
|
285 | end |
|
282 | - return res |
|
286 | + return { :score => s, :full_score => f, :msg => res } |
|
283 | end |
|
287 | end |
|
284 |
|
288 | ||
|
285 | def prepare_announcements(recent=nil) |
|
289 | def prepare_announcements(recent=nil) |
|
286 | if GraderConfiguration.show_tasks_to?(@user) |
|
290 | if GraderConfiguration.show_tasks_to?(@user) |
|
287 | @announcements = Announcement.find_published(true) |
|
291 | @announcements = Announcement.find_published(true) |
|
288 | else |
|
292 | else |
|
289 | @announcements = Announcement.find_published |
|
293 | @announcements = Announcement.find_published |
|
290 | end |
|
294 | end |
|
291 | if recent!=nil |
|
295 | if recent!=nil |
|
292 | recent_id = recent.to_i |
|
296 | recent_id = recent.to_i |
|
293 | @announcements = @announcements.find_all { |a| a.id > recent_id } |
|
297 | @announcements = @announcements.find_all { |a| a.id > recent_id } |
|
294 | end |
|
298 | end |
|
295 | end |
|
299 | end |
|
296 |
|
300 | ||
|
297 | def prepare_timeout_information(problems) |
|
301 | def prepare_timeout_information(problems) |
|
298 | @submission_timeouts = {} |
|
302 | @submission_timeouts = {} |
|
299 | problems.each do |problem| |
|
303 | problems.each do |problem| |
|
300 | assignment = @user.get_test_pair_assignment_for(problem) |
|
304 | assignment = @user.get_test_pair_assignment_for(problem) |
|
301 | if assignment == nil |
|
305 | if assignment == nil |
|
302 | timeout = nil |
|
306 | timeout = nil |
|
303 | else |
|
307 | else |
|
304 | if (assignment.expired?) or (assignment.submitted) |
|
308 | if (assignment.expired?) or (assignment.submitted) |
|
305 | timeout = 0 |
|
309 | timeout = 0 |
|
306 | else |
|
310 | else |
|
307 | timeout = assignment.created_at + TEST_ASSIGNMENT_EXPIRATION_DURATION - Time.new.gmtime |
|
311 | timeout = assignment.created_at + TEST_ASSIGNMENT_EXPIRATION_DURATION - Time.new.gmtime |
|
308 | end |
|
312 | end |
|
309 | end |
|
313 | end |
|
310 | @submission_timeouts[problem.id] = timeout |
|
314 | @submission_timeouts[problem.id] = timeout |
|
311 | end |
|
315 | end |
|
312 | end |
|
316 | end |
|
313 |
|
317 | ||
|
314 | def prepare_list_information |
|
318 | def prepare_list_information |
|
315 | @user = User.find(session[:user_id]) |
|
319 | @user = User.find(session[:user_id]) |
|
316 | if not GraderConfiguration.multicontests? |
|
320 | if not GraderConfiguration.multicontests? |
|
317 | @problems = @user.available_problems |
|
321 | @problems = @user.available_problems |
|
318 | else |
|
322 | else |
|
319 | @contest_problems = @user.available_problems_group_by_contests |
|
323 | @contest_problems = @user.available_problems_group_by_contests |
|
320 | @problems = @user.available_problems |
|
324 | @problems = @user.available_problems |
|
321 | end |
|
325 | end |
|
322 | @prob_submissions = {} |
|
326 | @prob_submissions = {} |
|
323 | @problems.each do |p| |
|
327 | @problems.each do |p| |
|
324 | sub = Submission.find_last_by_user_and_problem(@user.id,p.id) |
|
328 | sub = Submission.find_last_by_user_and_problem(@user.id,p.id) |
|
325 | if sub!=nil |
|
329 | if sub!=nil |
|
326 | @prob_submissions[p.id] = { :count => sub.number, :submission => sub } |
|
330 | @prob_submissions[p.id] = { :count => sub.number, :submission => sub } |
|
327 | else |
|
331 | else |
|
328 | @prob_submissions[p.id] = { :count => 0, :submission => nil } |
|
332 | @prob_submissions[p.id] = { :count => 0, :submission => nil } |
|
329 | end |
|
333 | end |
|
330 | end |
|
334 | end |
|
331 | prepare_announcements |
|
335 | prepare_announcements |
|
332 | prepare_timeout_information(@problems) |
|
336 | prepare_timeout_information(@problems) |
|
333 | end |
|
337 | end |
|
334 |
|
338 | ||
|
335 | def check_viewability |
|
339 | def check_viewability |
|
336 | @user = User.find(session[:user_id]) |
|
340 | @user = User.find(session[:user_id]) |
|
337 | if (!GraderConfiguration.show_tasks_to?(@user)) and |
|
341 | if (!GraderConfiguration.show_tasks_to?(@user)) and |
|
338 | ((action_name=='submission') or (action_name=='submit')) |
|
342 | ((action_name=='submission') or (action_name=='submit')) |
|
339 | redirect_to :action => 'list' and return |
|
343 | redirect_to :action => 'list' and return |
|
340 | end |
|
344 | end |
|
341 | end |
|
345 | end |
|
342 |
|
346 | ||
|
343 | def prepare_grading_result(submission) |
|
347 | def prepare_grading_result(submission) |
|
344 | if GraderConfiguration.task_grading_info.has_key? submission.problem.name |
|
348 | if GraderConfiguration.task_grading_info.has_key? submission.problem.name |
|
345 | grading_info = GraderConfiguration.task_grading_info[submission.problem.name] |
|
349 | grading_info = GraderConfiguration.task_grading_info[submission.problem.name] |
|
346 | else |
|
350 | else |
|
347 | # guess task info from problem.full_score |
|
351 | # guess task info from problem.full_score |
|
348 | cases = submission.problem.full_score / 10 |
|
352 | cases = submission.problem.full_score / 10 |
|
349 | grading_info = { |
|
353 | grading_info = { |
|
350 | 'testruns' => cases, |
|
354 | 'testruns' => cases, |
|
351 | 'testcases' => cases |
|
355 | 'testcases' => cases |
|
352 | } |
|
356 | } |
|
353 | end |
|
357 | end |
|
354 | @test_runs = [] |
|
358 | @test_runs = [] |
|
355 | if grading_info['testruns'].is_a? Integer |
|
359 | if grading_info['testruns'].is_a? Integer |
|
356 | trun_count = grading_info['testruns'] |
|
360 | trun_count = grading_info['testruns'] |
|
357 | trun_count.times do |i| |
|
361 | trun_count.times do |i| |
|
358 | @test_runs << [ read_grading_result(@user.login, |
|
362 | @test_runs << [ read_grading_result(@user.login, |
|
359 | submission.problem.name, |
|
363 | submission.problem.name, |
|
360 | submission.id, |
|
364 | submission.id, |
|
361 | i+1) ] |
|
365 | i+1) ] |
|
362 | end |
|
366 | end |
|
363 | else |
|
367 | else |
|
364 | grading_info['testruns'].keys.sort.each do |num| |
|
368 | grading_info['testruns'].keys.sort.each do |num| |
|
365 | run = [] |
|
369 | run = [] |
|
366 | testrun = grading_info['testruns'][num] |
|
370 | testrun = grading_info['testruns'][num] |
|
367 | testrun.each do |c| |
|
371 | testrun.each do |c| |
|
368 | run << read_grading_result(@user.login, |
|
372 | run << read_grading_result(@user.login, |
|
369 | submission.problem.name, |
|
373 | submission.problem.name, |
|
370 | submission.id, |
|
374 | submission.id, |
|
371 | c) |
|
375 | c) |
|
372 | end |
|
376 | end |
|
373 | @test_runs << run |
|
377 | @test_runs << run |
|
374 | end |
|
378 | end |
|
375 | end |
|
379 | end |
|
376 | end |
|
380 | end |
|
377 |
|
381 | ||
|
378 | def grading_result_dir(user_name, problem_name, submission_id, case_num) |
|
382 | def grading_result_dir(user_name, problem_name, submission_id, case_num) |
|
379 | return "#{GRADING_RESULT_DIR}/#{user_name}/#{problem_name}/#{submission_id}/test-result/#{case_num}" |
|
383 | return "#{GRADING_RESULT_DIR}/#{user_name}/#{problem_name}/#{submission_id}/test-result/#{case_num}" |
|
380 | end |
|
384 | end |
|
381 |
|
385 | ||
|
382 | def output_filename(user_name, problem_name, submission_id, case_num) |
|
386 | def output_filename(user_name, problem_name, submission_id, case_num) |
|
383 | dir = grading_result_dir(user_name,problem_name, submission_id, case_num) |
|
387 | dir = grading_result_dir(user_name,problem_name, submission_id, case_num) |
|
384 | return "#{dir}/output.txt" |
|
388 | return "#{dir}/output.txt" |
|
385 | end |
|
389 | end |
|
386 |
|
390 | ||
|
387 | def read_grading_result(user_name, problem_name, submission_id, case_num) |
|
391 | def read_grading_result(user_name, problem_name, submission_id, case_num) |
|
388 | dir = grading_result_dir(user_name,problem_name, submission_id, case_num) |
|
392 | dir = grading_result_dir(user_name,problem_name, submission_id, case_num) |
|
389 | result_file_name = "#{dir}/result" |
|
393 | result_file_name = "#{dir}/result" |
|
390 | if !FileTest.exists?(result_file_name) |
|
394 | if !FileTest.exists?(result_file_name) |
|
391 | return {:num => case_num, :msg => 'program did not run'} |
|
395 | return {:num => case_num, :msg => 'program did not run'} |
|
392 | else |
|
396 | else |
|
393 | results = File.open(result_file_name).readlines |
|
397 | results = File.open(result_file_name).readlines |
|
394 | run_stat = extract_running_stat(results) |
|
398 | run_stat = extract_running_stat(results) |
|
395 | output_filename = "#{dir}/output.txt" |
|
399 | output_filename = "#{dir}/output.txt" |
|
396 | if FileTest.exists?(output_filename) |
|
400 | if FileTest.exists?(output_filename) |
|
397 | output_file = true |
|
401 | output_file = true |
|
398 | output_size = File.size(output_filename) |
|
402 | output_size = File.size(output_filename) |
|
399 | else |
|
403 | else |
|
400 | output_file = false |
|
404 | output_file = false |
|
401 | output_size = 0 |
|
405 | output_size = 0 |
|
402 | end |
|
406 | end |
|
403 |
|
407 | ||
|
404 | return { |
|
408 | return { |
|
405 | :num => case_num, |
|
409 | :num => case_num, |
|
406 | :msg => results[0], |
|
410 | :msg => results[0], |
|
407 | :run_stat => run_stat, |
|
411 | :run_stat => run_stat, |
|
408 | :output => output_file, |
|
412 | :output => output_file, |
|
409 | :output_size => output_size |
|
413 | :output_size => output_size |
|
410 | } |
|
414 | } |
|
411 | end |
|
415 | end |
|
412 | end |
|
416 | end |
|
413 |
|
417 | ||
|
414 | # copied from grader/script/lib/test_request_helper.rb |
|
418 | # copied from grader/script/lib/test_request_helper.rb |
|
415 | def extract_running_stat(results) |
|
419 | def extract_running_stat(results) |
|
416 | running_stat_line = results[-1] |
|
420 | running_stat_line = results[-1] |
|
417 |
|
421 | ||
|
418 | # extract exit status line |
|
422 | # extract exit status line |
|
419 | run_stat = "" |
|
423 | run_stat = "" |
|
420 | if !(/[Cc]orrect/.match(results[0])) |
|
424 | if !(/[Cc]orrect/.match(results[0])) |
|
421 | run_stat = results[0].chomp |
|
425 | run_stat = results[0].chomp |
|
422 | else |
|
426 | else |
|
423 | run_stat = 'Program exited normally' |
|
427 | run_stat = 'Program exited normally' |
|
424 | end |
|
428 | end |
|
425 |
|
429 | ||
|
426 | logger.info "Stat line: #{running_stat_line}" |
|
430 | logger.info "Stat line: #{running_stat_line}" |
|
427 |
|
431 | ||
|
428 | # extract running time |
|
432 | # extract running time |
|
429 | if res = /r(.*)u(.*)s/.match(running_stat_line) |
|
433 | if res = /r(.*)u(.*)s/.match(running_stat_line) |
|
430 | seconds = (res[1].to_f + res[2].to_f) |
|
434 | seconds = (res[1].to_f + res[2].to_f) |
|
431 | time_stat = "Time used: #{seconds} sec." |
|
435 | time_stat = "Time used: #{seconds} sec." |
|
432 | else |
|
436 | else |
|
433 | seconds = nil |
|
437 | seconds = nil |
|
434 | time_stat = "Time used: n/a sec." |
|
438 | time_stat = "Time used: n/a sec." |
|
435 | end |
|
439 | end |
|
436 |
|
440 | ||
|
437 | # extract memory usage |
|
441 | # extract memory usage |
|
438 | if res = /s(.*)m/.match(running_stat_line) |
|
442 | if res = /s(.*)m/.match(running_stat_line) |
|
439 | memory_used = res[1].to_i |
|
443 | memory_used = res[1].to_i |
|
440 | else |
|
444 | else |
|
441 | memory_used = -1 |
|
445 | memory_used = -1 |
|
442 | end |
|
446 | end |
|
443 |
|
447 | ||
|
444 | return { |
|
448 | return { |
|
445 | :msg => "#{run_stat}\n#{time_stat}", |
|
449 | :msg => "#{run_stat}\n#{time_stat}", |
|
446 | :running_time => seconds, |
|
450 | :running_time => seconds, |
|
447 | :exit_status => run_stat, |
|
451 | :exit_status => run_stat, |
|
448 | :memory_usage => memory_used |
|
452 | :memory_usage => memory_used |
|
449 | } |
|
453 | } |
|
450 | end |
|
454 | end |
|
451 |
|
455 | ||
|
452 | def confirm_and_update_start_time |
|
456 | def confirm_and_update_start_time |
|
453 | user = User.find(session[:user_id]) |
|
457 | user = User.find(session[:user_id]) |
|
454 | if (GraderConfiguration.indv_contest_mode? and |
|
458 | if (GraderConfiguration.indv_contest_mode? and |
|
455 | GraderConfiguration['contest.confirm_indv_contest_start'] and |
|
459 | GraderConfiguration['contest.confirm_indv_contest_start'] and |
|
456 | !user.contest_started?) |
|
460 | !user.contest_started?) |
|
457 | redirect_to :action => 'confirm_contest_start' and return |
|
461 | redirect_to :action => 'confirm_contest_start' and return |
|
458 | end |
|
462 | end |
|
459 | if not GraderConfiguration.analysis_mode? |
|
463 | if not GraderConfiguration.analysis_mode? |
|
460 | user.update_start_time |
|
464 | user.update_start_time |
|
461 | end |
|
465 | end |
|
462 | end |
|
466 | end |
|
463 |
|
467 | ||
|
464 | def reject_announcement_refresh_when_logged_out |
|
468 | def reject_announcement_refresh_when_logged_out |
|
465 | if not session[:user_id] |
|
469 | if not session[:user_id] |
|
466 | render :text => 'Access forbidden', :status => 403 |
|
470 | render :text => 'Access forbidden', :status => 403 |
|
467 | end |
|
471 | end |
|
468 |
|
472 | ||
|
469 | if GraderConfiguration.multicontests? |
|
473 | if GraderConfiguration.multicontests? |
|
470 | user = User.find(session[:user_id]) |
|
474 | user = User.find(session[:user_id]) |
|
471 | if user.contest_stat.forced_logout |
|
475 | if user.contest_stat.forced_logout |
|
472 | render :text => 'Access forbidden', :status => 403 |
|
476 | render :text => 'Access forbidden', :status => 403 |
|
473 | end |
|
477 | end |
|
474 | end |
|
478 | end |
@@ -1,51 +1,36 | |||||
|
1 | <div class="submitbox"> |
|
1 | <div class="submitbox"> |
|
2 | <b>Problem:</b> <%= select 'submission', 'problem_id', |
|
2 | <b>Problem:</b> <%= select 'submission', 'problem_id', |
|
3 | [['กรุณาเลือกข้อที่ต้องการส่งหรือทดสอบ','-1']] + |
|
3 | [['กรุณาเลือกข้อที่ต้องการส่งหรือทดสอบ','-1']] + |
|
4 | @problems.collect {|p| [p.full_name, p.id]}, |
|
4 | @problems.collect {|p| [p.full_name, p.id]}, |
|
5 | { :selected => '-1' }, |
|
5 | { :selected => '-1' }, |
|
6 |
- { :onchange => ' |
|
6 | + { :onchange => 'TOIContest.problemSelectClick()' } %> |
|
7 | </div> |
|
7 | </div> |
|
8 |
|
8 | ||
|
9 | <% @problems.each do |problem| %> |
|
9 | <% @problems.each do |problem| %> |
|
10 | <div class="submission-submit-divs" id="submission_submit_div_<%= problem.id %>_id" style="displanny: none;"> |
|
10 | <div class="submission-submit-divs" id="submission_submit_div_<%= problem.id %>_id" style="displanny: none;"> |
|
11 | <div style="border: 1px solid #c0c0c0; padding: 5px; margin: 5px 0 5px 0;"> |
|
11 | <div style="border: 1px solid #c0c0c0; padding: 5px; margin: 5px 0 5px 0;"> |
|
12 | - <b><%= problem.full_name %>: ข้อมูลสำหรับตรวจสอบ</b> (สามารถดาวน์โหลดและส่งกี่ครั้งก็ได้): |
|
12 | + <b><%= problem.full_name %>: ข้อมูลสำหรับตรวจสอบ</b> (สามารถดาวน์โหลดและส่งกี่ครั้งก็ได้,ไม่มีคะแนน): |
|
13 | <%= link_to 'ดาวน์โหลด input', :action => 'verifying_testcase', :id => problem.id %> |
|
13 | <%= link_to 'ดาวน์โหลด input', :action => 'verifying_testcase', :id => problem.id %> |
|
14 | - <% if @current_problem.id == problem.id %> |
|
14 | + <% if @current_problem and @current_problem.id == problem.id %> |
|
15 | <% if @grading_result %> |
|
15 | <% if @grading_result %> |
|
16 | - | <b>ผลการตรวจ:</b> <%= @grading_result %> |
|
16 | + | <b>ผลการตรวจ:</b> <%= "#{@grading_result[:score]}/#{@grading_result[:full_score]} [#{@grading_result[:msg]}]" %> |
|
17 | <% end %> |
|
17 | <% end %> |
|
18 | <% end %> |
|
18 | <% end %> |
|
19 | <%= form_tag({:controller => 'main', :action => 'verifying_submit', :id => problem.id}, {:method => 'post', :multipart => true}) do %> |
|
19 | <%= form_tag({:controller => 'main', :action => 'verifying_submit', :id => problem.id}, {:method => 'post', :multipart => true }) do %> |
|
20 | ส่งคำตอบของข้อมูลสำหรับตรวจสอบ: |
|
20 | ส่งคำตอบของข้อมูลสำหรับตรวจสอบ: |
|
21 | <%= file_field_tag 'output_file' %> |
|
21 | <%= file_field_tag 'output_file' %> |
|
22 | <%= submit_tag 'Submit' %> |
|
22 | <%= submit_tag 'Submit' %> |
|
23 | <% end %> |
|
23 | <% end %> |
|
24 | </div> |
|
24 | </div> |
|
25 | <div style="border: 1px solid #c0c0c0; padding: 5px; margin: 5px 0 5px 0;"> |
|
25 | <div style="border: 1px solid #c0c0c0; padding: 5px; margin: 5px 0 5px 0;"> |
|
26 | <b><%= problem.full_name %>: ข้อมูลทดสอบจริง</b> (ส่งกี่ครั้งก็ได้ภายในเวลา 5 นาทีหลังดาวน์โหลด): |
|
26 | <b><%= problem.full_name %>: ข้อมูลทดสอบจริง</b> (ส่งกี่ครั้งก็ได้ภายในเวลา 5 นาทีหลังดาวน์โหลด): |
|
27 |
- <%= link_to 'ดาวน์โหลด input และเริ่มจับเวลา', { :action => 'testcase', :id => problem.id}, { :onclick => 'return confirm |
|
27 | + <%= link_to 'ดาวน์โหลด input และเริ่มจับเวลา', { :action => 'testcase', :id => problem.id}, { :onclick => 'return TOIContest.confirmDownload()' } %> |
|
28 | <span id="submission_time_left_<%= problem.id %>_id"></span> |
|
28 | <span id="submission_time_left_<%= problem.id %>_id"></span> |
|
29 | - <%= form_tag do %> |
|
29 | + <%= form_tag({:controller => 'main', :action => 'submit', :id => problem.id}, {:method => 'post', :multipart => true, :id => "submission_form_#{problem.id}_id" }) do %> |
|
30 | ข้อมูลส่งออก: <%= file_field_tag 'output_file' %> |
|
30 | ข้อมูลส่งออก: <%= file_field_tag 'output_file' %> |
|
31 | โปรแกรมคำตอบ: <%= file_field_tag 'source_file' %> |
|
31 | โปรแกรมคำตอบ: <%= file_field_tag 'source_file' %> |
|
32 | <%= submit_tag 'Submit' %> |
|
32 | <%= submit_tag 'Submit' %> |
|
33 | <% end %> |
|
33 | <% end %> |
|
34 | </div> |
|
34 | </div> |
|
35 | </div> |
|
35 | </div> |
|
36 | <% end %> |
|
36 | <% end %> |
|
37 | - <script> |
|
||
|
38 | - function select_click() { |
|
||
|
39 | - $$(".submission-submit-divs").each(function(item) { |
|
||
|
40 | - item.hide(); |
|
||
|
41 | - }); |
|
||
|
42 | - var problem_id = $('submission_problem_id').value; |
|
||
|
43 | - if ( problem_id < 0 ) { |
|
||
|
44 | - return; |
|
||
|
45 | - } |
|
||
|
46 | - $("submission_submit_div_" + problem_id + "_id").show(); |
|
||
|
47 | - } |
|
||
|
48 | - function confirm_download() { |
|
||
|
49 | - return confirm("แน่ใจ?"); |
|
||
|
50 | - } |
|
||
|
51 | - </script> |
|
@@ -1,50 +1,59 | |||||
|
1 | - content_for :head do |
|
1 | - content_for :head do |
|
2 | = javascript_include_tag "announcement_refresh" |
|
2 | = javascript_include_tag "announcement_refresh" |
|
|
3 | + = javascript_include_tag "toicontest" | ||
|
3 |
|
4 | ||
|
4 | = user_title_bar(@user) |
|
5 | = user_title_bar(@user) |
|
5 |
|
6 | ||
|
6 | .announcementbox{:style => (@announcements.length==0 ? "display:none" : "")} |
|
7 | .announcementbox{:style => (@announcements.length==0 ? "display:none" : "")} |
|
7 | %span{:class => 'title'} |
|
8 | %span{:class => 'title'} |
|
8 | Announcements |
|
9 | Announcements |
|
9 | #announcementbox-body |
|
10 | #announcementbox-body |
|
10 | = render :partial => 'announcement', :collection => @announcements |
|
11 | = render :partial => 'announcement', :collection => @announcements |
|
11 |
|
12 | ||
|
12 | - if GraderConfiguration.show_submitbox_to?(@user) |
|
13 | - if GraderConfiguration.show_submitbox_to?(@user) |
|
13 | = error_messages_for 'submission' |
|
14 | = error_messages_for 'submission' |
|
14 | = render :partial => 'submission_box' |
|
15 | = render :partial => 'submission_box' |
|
15 |
|
16 | ||
|
16 |
|
17 | ||
|
17 | %hr/ |
|
18 | %hr/ |
|
18 |
|
19 | ||
|
19 | - if (GraderConfiguration.contest_mode?) and (@user.site!=nil) and (@user.site.started!=true) |
|
20 | - if (GraderConfiguration.contest_mode?) and (@user.site!=nil) and (@user.site.started!=true) |
|
20 | %p=t 'main.start_soon' |
|
21 | %p=t 'main.start_soon' |
|
21 |
|
22 | ||
|
22 | - if GraderConfiguration.show_tasks_to?(@user) |
|
23 | - if GraderConfiguration.show_tasks_to?(@user) |
|
23 | - if not GraderConfiguration.multicontests? |
|
24 | - if not GraderConfiguration.multicontests? |
|
24 | %table.info |
|
25 | %table.info |
|
25 | %tr.info-head |
|
26 | %tr.info-head |
|
26 | %th |
|
27 | %th |
|
27 | %th Tasks |
|
28 | %th Tasks |
|
28 | %th # of sub(s) |
|
29 | %th # of sub(s) |
|
29 | %th Results |
|
30 | %th Results |
|
30 | = render :partial => 'problem', :collection => @problems |
|
31 | = render :partial => 'problem', :collection => @problems |
|
31 | - else |
|
32 | - else |
|
32 | - @contest_problems.each do |cp| |
|
33 | - @contest_problems.each do |cp| |
|
33 | - if cp[:problems].length > 0 |
|
34 | - if cp[:problems].length > 0 |
|
34 | %h2{:class =>'contest-title'} |
|
35 | %h2{:class =>'contest-title'} |
|
35 | = "#{cp[:contest] ? cp[:contest].title : 'Public problems'}" |
|
36 | = "#{cp[:contest] ? cp[:contest].title : 'Public problems'}" |
|
36 | %table.info |
|
37 | %table.info |
|
37 | %tr.info-head |
|
38 | %tr.info-head |
|
38 | %th |
|
39 | %th |
|
39 | %th Tasks |
|
40 | %th Tasks |
|
40 | %th # of sub(s) |
|
41 | %th # of sub(s) |
|
41 | %th Results |
|
42 | %th Results |
|
42 | = render :partial => 'problem', :collection => cp[:problems] |
|
43 | = render :partial => 'problem', :collection => cp[:problems] |
|
43 |
|
44 | ||
|
44 |
|
45 | ||
|
45 | %hr/ |
|
46 | %hr/ |
|
46 |
|
47 | ||
|
47 | %script{:type => 'text/javascript'} |
|
48 | %script{:type => 'text/javascript'} |
|
48 | = "Announcement.refreshUrl = '#{url_for :controller => 'main', :action => 'announcements'}';" |
|
49 | = "Announcement.refreshUrl = '#{url_for :controller => 'main', :action => 'announcements'}';" |
|
49 | Announcement.registerRefreshEventTimer(); |
|
50 | Announcement.registerRefreshEventTimer(); |
|
50 |
|
51 | ||
|
|
52 | + TOIContest.timeOuts = {}; | ||
|
|
53 | + - @problems.each do |p| | ||
|
|
54 | + - if (@submission_timeouts.has_key? p.id) and (@submission_timeouts[p.id] != nil) | ||
|
|
55 | + = "TOIContest.timeOuts[#{p.id}] = #{@submission_timeouts[p.id]};" | ||
|
|
56 | + - else | ||
|
|
57 | + = "TOIContest.timeOuts[#{p.id}] = TOIContest.NO_TIMEOUT;" | ||
|
|
58 | + | ||
|
|
59 | + TOIContest.refreshTimeOutMessages(); |
You need to be logged in to leave comments.
Login now