Description:
added solution submission with grading
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r214:cdf8c2c3dce8 - - 3 files changed: 53 inserted, 8 deleted

@@ -8,7 +8,7
8 # COMMENTED OUT: filter in each action instead
8 # COMMENTED OUT: filter in each action instead
9 # before_filter :verify_time_limit, :only => [:submit]
9 # before_filter :verify_time_limit, :only => [:submit]
10
10
11 - verify :method => :post, :only => [:submit],
11 + verify :method => :post, :only => [:submit, :new_input, :download_input, :submit_solution],
12 :redirect_to => { :action => :index }
12 :redirect_to => { :action => :index }
13
13
14 # COMMENT OUT: only need when having high load
14 # COMMENT OUT: only need when having high load
@@ -187,13 +187,13
187 send_data(assignment.test_pair.input,
187 send_data(assignment.test_pair.input,
188 { :filename => "#{problem.name}-#{assignment.request_number}.in",
188 { :filename => "#{problem.name}-#{assignment.request_number}.in",
189 :type => 'text/plain' })
189 :type => 'text/plain' })
190 - else
190 + else
191 flash[:notice] = 'You cannot request new input now.'
191 flash[:notice] = 'You cannot request new input now.'
192 redirect_to :action => 'list'
192 redirect_to :action => 'list'
193 end
193 end
194 end
194 end
195
195
196 - def download
196 + def download_input
197 problem = Problem.find(params[:id])
197 problem = Problem.find(params[:id])
198 user = User.find(session[:user_id])
198 user = User.find(session[:user_id])
199 recent_assignment = user.get_recent_test_pair_assignment_for problem
199 recent_assignment = user.get_recent_test_pair_assignment_for problem
@@ -202,7 +202,39
202 { :filename => "#{problem.name}-#{recent_assignment.request_number}.in",
202 { :filename => "#{problem.name}-#{recent_assignment.request_number}.in",
203 :type => 'text/plain' })
203 :type => 'text/plain' })
204 else
204 else
205 - flash[:notice] = 'You have not request for any input data for this problem.'
205 + flash[:notice] = 'You have not requested for any input data for this problem.'
206 + redirect_to :action => 'list'
207 + end
208 + end
209 +
210 + def submit_solution
211 + problem = Problem.find(params[:id])
212 + user = User.find(session[:user_id])
213 + recent_assignment = user.get_recent_test_pair_assignment_for problem
214 + if recent_assignment != nil
215 + submitted_solution = params[:file].read
216 + test_pair = recent_assignment.test_pair
217 + passed = test_pair.grade(submitted_solution)
218 + points = passed ? 100 : 0
219 + submission = Submission.new(:user => user,
220 + :problem => problem,
221 + :source => params[:file].read,
222 + :source_filename => params['file'].original_filename,
223 + :language_id => 0,
224 + :submitted_at => Time.new.gmtime,
225 + :graded_at => Time.new.gmtime,
226 + :points => points)
227 + submission.save
228 + recent_assignment.submitted = true
229 + recent_assignment.save
230 + if passed
231 + flash[:notice] = 'Correct solution'
232 + else
233 + flash[:notice] = 'Incorrect solution'
234 + end
235 + redirect_to :action => 'list'
236 + else
237 + flash[:notice] = 'You have not requested for any input data for this problem.'
206 redirect_to :action => 'list'
238 redirect_to :action => 'list'
207 end
239 end
208 end
240 end
@@ -6,4 +6,17
6
6
7 class TestPair < ActiveRecord::Base
7 class TestPair < ActiveRecord::Base
8 belongs_to :problem
8 belongs_to :problem
9 +
10 + def grade(submitted_solution)
11 + sols = solution.split
12 + subs = submitted_solution.split
13 + if sols.length == subs.length
14 + subs.length.times do |i|
15 + return false if subs[i]!=sols[i]
16 + end
17 + return true
18 + else
19 + return false
20 + end
21 + end
9 end
22 end
@@ -11,14 +11,14
11 </td>
11 </td>
12 <td>
12 <td>
13 <span id="problem-form-<%= problem.id %>">
13 <span id="problem-form-<%= problem.id %>">
14 - <% form_tag "new_input/#{problem.id}", :method => :post do -%>
14 + <% form_tag({:action => 'new_input', :id => problem.id}, :method => :post) do -%>
15 <input type="submit" value="New input"/>
15 <input type="submit" value="New input"/>
16 <% end -%>
16 <% end -%>
17 - <% form_tag "download/#{problem.id}", :method => :post do -%>
17 + <% form_tag({ :action => 'download_input', :id => problem.id }, :method => :post) do -%>
18 <input type="submit" value="Download input"/>
18 <input type="submit" value="Download input"/>
19 <% end -%>
19 <% end -%>
20 - <% form_tag "submit_solution/#{problem.id}", :method => :post do -%>
20 + <% form_tag({ :action => 'submit_solution', :id => problem.id }, :method => :post, :multipart => true) do -%>
21 - <input type="file">
21 + <input type="file" name="file">
22 <input type="submit" value="Submit solution"/>
22 <input type="submit" value="Submit solution"/>
23 <% end -%>
23 <% end -%>
24 </span>
24 </span>
You need to be logged in to leave comments. Login now