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 | + |
@@ -179,200 +179,204 | |||
|
179 | 179 | |
|
180 | 180 | # announcement refreshing and hiding methods |
|
181 | 181 | |
|
182 | 182 | def announcements |
|
183 | 183 | if params.has_key? 'recent' |
|
184 | 184 | prepare_announcements(params[:recent]) |
|
185 | 185 | else |
|
186 | 186 | prepare_announcements |
|
187 | 187 | end |
|
188 | 188 | render(:partial => 'announcement', |
|
189 | 189 | :collection => @announcements, |
|
190 | 190 | :locals => {:announcement_effect => true}) |
|
191 | 191 | end |
|
192 | 192 | |
|
193 | 193 | def confirm_contest_start |
|
194 | 194 | user = User.find(session[:user_id]) |
|
195 | 195 | if request.method == 'POST' |
|
196 | 196 | user.update_start_time |
|
197 | 197 | redirect_to :action => 'list' |
|
198 | 198 | else |
|
199 | 199 | @contests = user.contests |
|
200 | 200 | @user = user |
|
201 | 201 | end |
|
202 | 202 | end |
|
203 | 203 | |
|
204 | 204 | # thailandoi contests |
|
205 | 205 | |
|
206 | 206 | def verifying_testcase |
|
207 | 207 | problem = Problem.find(params[:id]) |
|
208 | 208 | if !problem.available |
|
209 | 209 | flash[:notice] = 'Error: problem is not available' |
|
210 | 210 | redirect_to :action => 'list' |
|
211 | 211 | else |
|
212 | 212 | test_pair = TestPair.get_for(problem, false) |
|
213 | 213 | send_data(test_pair.input, |
|
214 | 214 | {:filename => problem.name + '-verifying-input.txt', |
|
215 | 215 | :type => 'text/plain'}) |
|
216 | 216 | end |
|
217 | 217 | end |
|
218 | 218 | |
|
219 | 219 | def testcase |
|
220 | 220 | problem = Problem.find(params[:id]) |
|
221 | 221 | if !problem.available |
|
222 | 222 | flash[:notice] = 'Error: problem is not available' |
|
223 | 223 | redirect_to :action => 'list' |
|
224 | 224 | else |
|
225 | 225 | test_pair = TestPair.get_for(problem, true) |
|
226 | 226 | |
|
227 | 227 | user = User.find(session[:user_id]) |
|
228 | 228 | assignent = user.get_test_pair_assignment_for(problem) |
|
229 | 229 | |
|
230 | 230 | if !assignent |
|
231 | 231 | assignent = TestPairAssignment.new |
|
232 | 232 | assignent.user = user |
|
233 | 233 | assignent.problem = problem |
|
234 | 234 | assignent.test_pair = test_pair |
|
235 | 235 | assignent.submitted = false |
|
236 | 236 | assignent.save |
|
237 | 237 | end |
|
238 | 238 | |
|
239 | 239 | send_data(test_pair.input, |
|
240 | 240 | {:filename => problem.name + '-input.txt', |
|
241 | 241 | :type => 'text/plain'}) |
|
242 | 242 | end |
|
243 | 243 | end |
|
244 | 244 | |
|
245 | 245 | def verifying_submit |
|
246 | 246 | user = User.find(session[:user_id]) |
|
247 | 247 | problem_id = params[:id] |
|
248 | 248 | problem = Problem.find(problem_id) |
|
249 | 249 | |
|
250 | 250 | if !problem or !problem.available |
|
251 | 251 | flash[:notice] = 'Error: problem is not available' |
|
252 | 252 | redirect_to :action => 'list' and return |
|
253 | 253 | end |
|
254 | 254 | |
|
255 | 255 | test_pair = TestPair.get_for(problem, false) |
|
256 | 256 | if (params['output_file']) and (params['output_file']!='') |
|
257 | 257 | output = params['output_file'].read |
|
258 | 258 | |
|
259 | 259 | @current_problem = problem |
|
260 | 260 | @grading_result = grade(output, test_pair.solution) |
|
261 | 261 | prepare_list_information |
|
262 | 262 | render :action => 'list' and return |
|
263 | 263 | else |
|
264 | 264 | flash[:notice] = 'Error: output file errors' |
|
265 | 265 | redirect_to :action => 'list' |
|
266 | 266 | end |
|
267 | 267 | end |
|
268 | 268 | |
|
269 | 269 | protected |
|
270 | 270 | |
|
271 | 271 | def grade(output, solution) |
|
272 | 272 | out_items = output.split |
|
273 | 273 | sol_items = solution.split |
|
274 | 274 | res = '' |
|
275 | + f = 0 | |
|
276 | + s = 0 | |
|
275 | 277 | sol_items.length.times do |i| |
|
278 | + f += 1 | |
|
276 | 279 | if out_items[i] == sol_items[i] |
|
277 | 280 | res = res + 'P' |
|
281 | + s += 1 | |
|
278 | 282 | else |
|
279 | 283 | res = res + '-' |
|
280 | 284 | end |
|
281 | 285 | end |
|
282 | - return res | |
|
286 | + return { :score => s, :full_score => f, :msg => res } | |
|
283 | 287 | end |
|
284 | 288 | |
|
285 | 289 | def prepare_announcements(recent=nil) |
|
286 | 290 | if GraderConfiguration.show_tasks_to?(@user) |
|
287 | 291 | @announcements = Announcement.find_published(true) |
|
288 | 292 | else |
|
289 | 293 | @announcements = Announcement.find_published |
|
290 | 294 | end |
|
291 | 295 | if recent!=nil |
|
292 | 296 | recent_id = recent.to_i |
|
293 | 297 | @announcements = @announcements.find_all { |a| a.id > recent_id } |
|
294 | 298 | end |
|
295 | 299 | end |
|
296 | 300 | |
|
297 | 301 | def prepare_timeout_information(problems) |
|
298 | 302 | @submission_timeouts = {} |
|
299 | 303 | problems.each do |problem| |
|
300 | 304 | assignment = @user.get_test_pair_assignment_for(problem) |
|
301 | 305 | if assignment == nil |
|
302 | 306 | timeout = nil |
|
303 | 307 | else |
|
304 | 308 | if (assignment.expired?) or (assignment.submitted) |
|
305 | 309 | timeout = 0 |
|
306 | 310 | else |
|
307 | 311 | timeout = assignment.created_at + TEST_ASSIGNMENT_EXPIRATION_DURATION - Time.new.gmtime |
|
308 | 312 | end |
|
309 | 313 | end |
|
310 | 314 | @submission_timeouts[problem.id] = timeout |
|
311 | 315 | end |
|
312 | 316 | end |
|
313 | 317 | |
|
314 | 318 | def prepare_list_information |
|
315 | 319 | @user = User.find(session[:user_id]) |
|
316 | 320 | if not GraderConfiguration.multicontests? |
|
317 | 321 | @problems = @user.available_problems |
|
318 | 322 | else |
|
319 | 323 | @contest_problems = @user.available_problems_group_by_contests |
|
320 | 324 | @problems = @user.available_problems |
|
321 | 325 | end |
|
322 | 326 | @prob_submissions = {} |
|
323 | 327 | @problems.each do |p| |
|
324 | 328 | sub = Submission.find_last_by_user_and_problem(@user.id,p.id) |
|
325 | 329 | if sub!=nil |
|
326 | 330 | @prob_submissions[p.id] = { :count => sub.number, :submission => sub } |
|
327 | 331 | else |
|
328 | 332 | @prob_submissions[p.id] = { :count => 0, :submission => nil } |
|
329 | 333 | end |
|
330 | 334 | end |
|
331 | 335 | prepare_announcements |
|
332 | 336 | prepare_timeout_information(@problems) |
|
333 | 337 | end |
|
334 | 338 | |
|
335 | 339 | def check_viewability |
|
336 | 340 | @user = User.find(session[:user_id]) |
|
337 | 341 | if (!GraderConfiguration.show_tasks_to?(@user)) and |
|
338 | 342 | ((action_name=='submission') or (action_name=='submit')) |
|
339 | 343 | redirect_to :action => 'list' and return |
|
340 | 344 | end |
|
341 | 345 | end |
|
342 | 346 | |
|
343 | 347 | def prepare_grading_result(submission) |
|
344 | 348 | if GraderConfiguration.task_grading_info.has_key? submission.problem.name |
|
345 | 349 | grading_info = GraderConfiguration.task_grading_info[submission.problem.name] |
|
346 | 350 | else |
|
347 | 351 | # guess task info from problem.full_score |
|
348 | 352 | cases = submission.problem.full_score / 10 |
|
349 | 353 | grading_info = { |
|
350 | 354 | 'testruns' => cases, |
|
351 | 355 | 'testcases' => cases |
|
352 | 356 | } |
|
353 | 357 | end |
|
354 | 358 | @test_runs = [] |
|
355 | 359 | if grading_info['testruns'].is_a? Integer |
|
356 | 360 | trun_count = grading_info['testruns'] |
|
357 | 361 | trun_count.times do |i| |
|
358 | 362 | @test_runs << [ read_grading_result(@user.login, |
|
359 | 363 | submission.problem.name, |
|
360 | 364 | submission.id, |
|
361 | 365 | i+1) ] |
|
362 | 366 | end |
|
363 | 367 | else |
|
364 | 368 | grading_info['testruns'].keys.sort.each do |num| |
|
365 | 369 | run = [] |
|
366 | 370 | testrun = grading_info['testruns'][num] |
|
367 | 371 | testrun.each do |c| |
|
368 | 372 | run << read_grading_result(@user.login, |
|
369 | 373 | submission.problem.name, |
|
370 | 374 | submission.id, |
|
371 | 375 | c) |
|
372 | 376 | end |
|
373 | 377 | @test_runs << run |
|
374 | 378 | end |
|
375 | 379 | end |
|
376 | 380 | end |
|
377 | 381 | |
|
378 | 382 | def grading_result_dir(user_name, problem_name, submission_id, case_num) |
@@ -1,51 +1,36 | |||
|
1 | 1 | <div class="submitbox"> |
|
2 | 2 | <b>Problem:</b> <%= select 'submission', 'problem_id', |
|
3 | 3 | [['กรุณาเลือกข้อที่ต้องการส่งหรือทดสอบ','-1']] + |
|
4 | 4 | @problems.collect {|p| [p.full_name, p.id]}, |
|
5 | 5 | { :selected => '-1' }, |
|
6 |
- { :onchange => ' |
|
|
6 | + { :onchange => 'TOIContest.problemSelectClick()' } %> | |
|
7 | 7 | </div> |
|
8 | 8 | |
|
9 | 9 | <% @problems.each do |problem| %> |
|
10 | 10 | <div class="submission-submit-divs" id="submission_submit_div_<%= problem.id %>_id" style="displanny: none;"> |
|
11 | 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 | 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 | 15 | <% if @grading_result %> |
|
16 | - | <b>ผลการตรวจ:</b> <%= @grading_result %> | |
|
16 | + | <b>ผลการตรวจ:</b> <%= "#{@grading_result[:score]}/#{@grading_result[:full_score]} [#{@grading_result[:msg]}]" %> | |
|
17 | 17 | <% end %> |
|
18 | 18 | <% end %> |
|
19 | 19 | <%= form_tag({:controller => 'main', :action => 'verifying_submit', :id => problem.id}, {:method => 'post', :multipart => true}) do %> |
|
20 | 20 | ส่งคำตอบของข้อมูลสำหรับตรวจสอบ: |
|
21 | 21 | <%= file_field_tag 'output_file' %> |
|
22 | 22 | <%= submit_tag 'Submit' %> |
|
23 | 23 | <% end %> |
|
24 | 24 | </div> |
|
25 | 25 | <div style="border: 1px solid #c0c0c0; padding: 5px; margin: 5px 0 5px 0;"> |
|
26 | 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 | 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 | 30 | ข้อมูลส่งออก: <%= file_field_tag 'output_file' %> |
|
31 | 31 | โปรแกรมคำตอบ: <%= file_field_tag 'source_file' %> |
|
32 | 32 | <%= submit_tag 'Submit' %> |
|
33 | 33 | <% end %> |
|
34 | 34 | </div> |
|
35 | 35 | </div> |
|
36 | 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 | 1 | - content_for :head do |
|
2 | 2 | = javascript_include_tag "announcement_refresh" |
|
3 | + = javascript_include_tag "toicontest" | |
|
3 | 4 | |
|
4 | 5 | = user_title_bar(@user) |
|
5 | 6 | |
|
6 | 7 | .announcementbox{:style => (@announcements.length==0 ? "display:none" : "")} |
|
7 | 8 | %span{:class => 'title'} |
|
8 | 9 | Announcements |
|
9 | 10 | #announcementbox-body |
|
10 | 11 | = render :partial => 'announcement', :collection => @announcements |
|
11 | 12 | |
|
12 | 13 | - if GraderConfiguration.show_submitbox_to?(@user) |
|
13 | 14 | = error_messages_for 'submission' |
|
14 | 15 | = render :partial => 'submission_box' |
|
15 | 16 | |
|
16 | 17 | |
|
17 | 18 | %hr/ |
|
18 | 19 | |
|
19 | 20 | - if (GraderConfiguration.contest_mode?) and (@user.site!=nil) and (@user.site.started!=true) |
|
20 | 21 | %p=t 'main.start_soon' |
|
21 | 22 | |
|
22 | 23 | - if GraderConfiguration.show_tasks_to?(@user) |
|
23 | 24 | - if not GraderConfiguration.multicontests? |
|
24 | 25 | %table.info |
|
25 | 26 | %tr.info-head |
|
26 | 27 | %th |
|
27 | 28 | %th Tasks |
|
28 | 29 | %th # of sub(s) |
|
29 | 30 | %th Results |
|
30 | 31 | = render :partial => 'problem', :collection => @problems |
|
31 | 32 | - else |
|
32 | 33 | - @contest_problems.each do |cp| |
|
33 | 34 | - if cp[:problems].length > 0 |
|
34 | 35 | %h2{:class =>'contest-title'} |
|
35 | 36 | = "#{cp[:contest] ? cp[:contest].title : 'Public problems'}" |
|
36 | 37 | %table.info |
|
37 | 38 | %tr.info-head |
|
38 | 39 | %th |
|
39 | 40 | %th Tasks |
|
40 | 41 | %th # of sub(s) |
|
41 | 42 | %th Results |
|
42 | 43 | = render :partial => 'problem', :collection => cp[:problems] |
|
43 | 44 | |
|
44 | 45 | |
|
45 | 46 | %hr/ |
|
46 | 47 | |
|
47 | 48 | %script{:type => 'text/javascript'} |
|
48 | 49 | = "Announcement.refreshUrl = '#{url_for :controller => 'main', :action => 'announcements'}';" |
|
49 | 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