Description:
saves and grades submission in standard mode
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r388:b5766b7ed3ec - - 2 files changed: 18 inserted, 6 deleted

@@ -32,120 +32,128
32 32 def login
33 33 saved_notice = flash[:notice]
34 34 reset_session
35 35 flash.now[:notice] = saved_notice
36 36
37 37 # EXPERIMENT:
38 38 # Hide login if in single user mode and the url does not
39 39 # explicitly specify /login
40 40 #
41 41 # logger.info "PATH: #{request.path}"
42 42 # if GraderConfiguration['system.single_user_mode'] and
43 43 # request.path!='/main/login'
44 44 # @hidelogin = true
45 45 # end
46 46
47 47 @announcements = Announcement.find_for_frontpage
48 48 render :action => 'login', :layout => 'empty'
49 49 end
50 50
51 51 def list
52 52 if session[:current_problem_id]
53 53 @current_problem = Problem.find(session[:current_problem_id])
54 54 session[:current_problem_id] = nil
55 55 end
56 56 prepare_list_information
57 57 end
58 58
59 59 def help
60 60 @user = User.find(session[:user_id])
61 61 end
62 62
63 63 def submit
64 64 user = User.find(session[:user_id])
65 65
66 66 @submission = Submission.new
67 67 @current_problem = Problem.find(params[:submission][:problem_id])
68 68
69 69 if !@current_problem
70 70 flash[:notice] = 'Error: คุณยังไม่ได้ระบุข้อที่ต้องการส่ง'
71 71 redirect_to :action => 'list'
72 72 end
73 73
74 74 assignment = user.get_test_pair_assignment_for(@current_problem)
75 75 if !assignment
76 76 flash[:notice] = 'Error: คุณยังไม่ได้ดาวน์โหลดข้อมูลทดสอบ'
77 77 prepare_list_information
78 78 render :action => 'list' and return
79 79 end
80 - if assignment.expired?
80 + if (assignment.expired?) and (!GraderConfiguration.standard_mode?)
81 81 flash[:notice] = 'Error: หมดเวลาส่งสำหรับข้อนี้'
82 82 prepare_list_information
83 83 render :action => 'list' and return
84 84 end
85 85
86 86 @submission.problem = @current_problem
87 87 @submission.user = user
88 88 @submission.language_id = 0
89 89 if (params['file']) and (params['file']!='')
90 90 @submission.source = params['file'].read
91 91 @submission.source_filename = params['file'].original_filename
92 92 end
93 93 if (params['output_file']) and (params['output_file']!='')
94 94 @submission.output = params['output_file'].read
95 95 end
96 96 @submission.submitted_at = Time.new.gmtime
97 97
98 98 if GraderConfiguration.time_limit_mode? and user.contest_finished?
99 99 @submission.errors.add(:base,"The contest is over.")
100 100 prepare_list_information
101 101 render :action => 'list' and return
102 102 end
103 103
104 + if GraderConfiguration.standard_mode?
105 + test_pair = assignment.test_pair
106 + result = test_pair.grade(@submission.output)
107 + @submission.points = result[:score]*100 / result[:full_score]
108 + @submission.grader_comment = result[:msg]
109 + @submission.graded_at = Time.now.gmtime
110 + end
111 +
104 112 if @submission.valid?
105 113 if @submission.save == false
106 114 flash[:notice] = 'Error saving your submission'
107 115 elsif Task.create(:submission_id => @submission.id,
108 116 :status => Task::STATUS_INQUEUE) == false
109 117 flash[:notice] = 'Error adding your submission to task queue'
110 118 else
111 119 flash[:notice] = 'จัดเก็บคำตอบและโปรแกรมที่คุณส่งเรียบร้อย'
112 120 end
113 121 else
114 122 prepare_list_information
115 123 render :action => 'list' and return
116 124 end
117 125
118 126 if @current_problem
119 127 session[:current_problem_id] = @current_problem.id
120 128 end
121 129 redirect_to :action => 'list'
122 130 end
123 131
124 132 def source
125 133 submission = Submission.find(params[:id])
126 134 if ((submission.user_id == session[:user_id]) and
127 135 (submission.problem != nil) and
128 136 (submission.problem.available))
129 137 send_data(submission.source,
130 138 {:filename => submission.download_filename,
131 139 :type => 'text/plain'})
132 140 else
133 141 flash[:notice] = 'Error viewing source'
134 142 redirect_to :action => 'list'
135 143 end
136 144 end
137 145
138 146 def compiler_msg
139 147 @submission = Submission.find(params[:id])
140 148 if @submission.user_id == session[:user_id]
141 149 render :action => 'compiler_msg', :layout => 'empty'
142 150 else
143 151 flash[:notice] = 'Error viewing source'
144 152 redirect_to :action => 'list'
145 153 end
146 154 end
147 155
148 156 def submission
149 157 @user = User.find(session[:user_id])
150 158 @problems = @user.available_problems
151 159 if params[:id]==nil
@@ -269,103 +277,107
269 277 {:filename => problem.name + '-input.txt',
270 278 :type => 'text/plain'})
271 279 end
272 280 end
273 281
274 282 def verifying_submit
275 283 user = User.find(session[:user_id])
276 284 problem_id = params[:id]
277 285 problem = Problem.find(problem_id)
278 286
279 287 if !problem or !problem.available
280 288 flash[:notice] = 'Error: problem is not available'
281 289 redirect_to :action => 'list' and return
282 290 end
283 291
284 292 @current_problem = problem
285 293 test_pair = TestPair.get_for(problem, false)
286 294 if (params['output_file']) and (params['output_file']!='')
287 295 output = params['output_file'].read
288 296
289 297 @grading_result = test_pair.grade(output)
290 298 prepare_list_information
291 299 render :action => 'list' and return
292 300 else
293 301 flash[:notice] = 'Error: output file errors'
294 302 prepare_list_information
295 303 render :action => 'list' and return
296 304 end
297 305 end
298 306
299 307 protected
300 308
301 309 def prepare_announcements(recent=nil)
302 310 if GraderConfiguration.show_tasks_to?(@user)
303 311 @announcements = Announcement.find_published(true)
304 312 else
305 313 @announcements = Announcement.find_published
306 314 end
307 315 if recent!=nil
308 316 recent_id = recent.to_i
309 317 @announcements = @announcements.find_all { |a| a.id > recent_id }
310 318 end
311 319 end
312 320
313 321 def prepare_timeout_information(problems)
314 322 @submission_timeouts = {}
315 323 problems.each do |problem|
316 324 assignment = @user.get_test_pair_assignment_for(problem)
317 - if assignment == nil
325 + if GraderConfiguration.standard_mode?
318 326 timeout = nil
319 327 else
320 - if (assignment.expired?) or (assignment.submitted)
321 - timeout = 0
328 + if assignment == nil
329 + timeout = nil
322 330 else
323 - timeout = assignment.created_at + TEST_ASSIGNMENT_EXPIRATION_DURATION - Time.new.gmtime
331 + if (assignment.expired?) or (assignment.submitted)
332 + timeout = 0
333 + else
334 + timeout = assignment.created_at + TEST_ASSIGNMENT_EXPIRATION_DURATION - Time.new.gmtime
335 + end
324 336 end
325 337 end
326 338 @submission_timeouts[problem.id] = timeout
327 339 end
328 340 end
329 341
330 342 def prepare_list_information
331 343 @user = User.find(session[:user_id])
332 344 if not GraderConfiguration.multicontests?
333 345 @problems = @user.available_problems
334 346 else
335 347 @contest_problems = @user.available_problems_group_by_contests
336 348 @problems = @user.available_problems
337 349 end
338 350 @prob_submissions = {}
339 351 @problems.each do |p|
340 352 sub = Submission.find_last_by_user_and_problem(@user.id,p.id)
341 353 if sub!=nil
342 354 @prob_submissions[p.id] = { :count => sub.number, :submission => sub }
343 355 else
344 356 @prob_submissions[p.id] = { :count => 0, :submission => nil }
345 357 end
346 358 end
347 359 prepare_announcements
348 360 prepare_timeout_information(@problems)
349 361 end
350 362
351 363 def check_viewability
352 364 @user = User.find(session[:user_id])
353 365 if (!GraderConfiguration.show_tasks_to?(@user)) and
354 366 ((action_name=='submission') or (action_name=='submit'))
355 367 redirect_to :action => 'list' and return
356 368 end
357 369 end
358 370
359 371 def prepare_grading_result(submission)
360 372 if GraderConfiguration.task_grading_info.has_key? submission.problem.name
361 373 grading_info = GraderConfiguration.task_grading_info[submission.problem.name]
362 374 else
363 375 # guess task info from problem.full_score
364 376 cases = submission.problem.full_score / 10
365 377 grading_info = {
366 378 'testruns' => cases,
367 379 'testcases' => cases
368 380 }
369 381 end
370 382 @test_runs = []
371 383 if grading_info['testruns'].is_a? Integer
@@ -1,38 +1,38
1 1 <% selected_problem_id = @current_problem ? @current_problem.id : -1 %>
2 2 <div class="submitbox">
3 3 <b>Problem:</b> <%= select 'submission', 'problem_id',
4 4 [['กรุณาเลือกข้อที่ต้องการส่งหรือทดสอบ','-1']] +
5 5 @problems.collect {|p| [p.full_name, p.id]},
6 6 { :selected => selected_problem_id },
7 7 { :onchange => 'TOIContest.problemSelectClick()' } %>
8 8 </div>
9 9
10 10 <% @problems.each do |problem| %>
11 11 <div class="submission-submit-divs" id="submission_submit_div_<%= problem.id %>_id" style="display: none;">
12 12 <div style="border: 1px solid #c0c0c0; padding: 5px; margin: 5px 0 5px 0;">
13 13 <b><%= problem.full_name %>: ข้อมูลสำหรับตรวจสอบ</b> (สามารถดาวน์โหลดและส่งกี่ครั้งก็ได้,ไม่มีคะแนน):
14 14 <%= link_to 'ดาวน์โหลด input', :action => 'verifying_testcase', :id => problem.id %>
15 15 <% if @current_problem and @current_problem.id == problem.id %>
16 16 <% if @grading_result %>
17 17 | <b>ผลการตรวจ:</b> <%= "#{@grading_result[:score]}/#{@grading_result[:full_score]} [#{@grading_result[:msg]}]" %>
18 18 <% end %>
19 19 <% end %>
20 20 <%= form_tag({:controller => 'main', :action => 'verifying_submit', :id => problem.id}, {:method => 'post', :multipart => true }) do %>
21 21 ส่งคำตอบของข้อมูลสำหรับตรวจสอบ:
22 22 <%= file_field_tag 'output_file' %>
23 23 <%= submit_tag 'Submit' %>
24 24 <% end %>
25 25 </div>
26 26 <div style="border: 1px solid #c0c0c0; padding: 5px; margin: 5px 0 5px 0;">
27 27 <b><%= problem.full_name %>: ข้อมูลทดสอบจริง</b> (ส่งกี่ครั้งก็ได้ภายในเวลา 5 นาทีหลังดาวน์โหลด):
28 28 <%= link_to 'ดาวน์โหลด input และเริ่มจับเวลา', { :action => 'testcase', :id => problem.id}, { :onclick => "return TOIContest.confirmDownload(#{problem.id})" } %>
29 29 <span id="submission_time_left_<%= problem.id %>_id"></span>
30 30 <%= form_tag({:controller => 'main', :action => 'submit'}, {:method => 'post', :multipart => true, :id => "submission_form_#{problem.id}_id" }) do %>
31 31 <%= hidden_field_tag 'submission[problem_id]', problem.id %>
32 32 ข้อมูลส่งออก: <%= file_field_tag 'output_file' %>
33 - โปรแกรมคำตอบ: <%= file_field_tag 'file' %>
33 + โปรแกรมของคุณ: <%= file_field_tag 'file' %>
34 34 <%= submit_tag 'Submit' %>
35 35 <% end %>
36 36 </div>
37 37 </div>
38 38 <% end %>
You need to be logged in to leave comments. Login now