Description:
added submission_status to store grading results, first page shows only unpassed problems.
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r216:fa11dca6b078 - - 10 files changed: 149 inserted, 74 deleted

@@ -0,0 +1,6
1 + class SubmissionStatus < ActiveRecord::Base
2 +
3 + belongs_to :user
4 + belongs_to :problem
5 +
6 + end
@@ -0,0 +1,18
1 + .problem-panel{:id => "problem-panel-#{problem.id}", :style => "display:none"}
2 + .problem-form{:id => "problem-form-#{problem.id}"}
3 + - form_tag({ :action => 'download_input', :id => problem.id }, :method => :post) do
4 + %b Input:
5 + %input{:type => "submit", :value => "Download input"}
6 + - form_tag({ :action => 'submit_solution', :id => problem.id }, :method => :post, :multipart => true) do
7 + %b Submit output:
8 + %input{:type => "file", :name => "file"}
9 + %input{:type => "submit", :value => "Submit solution"}
10 +
11 + .problem-description
12 + - if problem.description!=nil
13 + - if problem.description.markdowned
14 + = markdown(problem.description.body)
15 + - else
16 + = problem.description.body
17 + - else
18 + (not available)
@@ -0,0 +1,16
1 + class CreateSubmissionStatuses < ActiveRecord::Migration
2 + def self.up
3 + create_table :submission_statuses do |t|
4 + t.integer :user_id
5 + t.integer :problem_id
6 + t.boolean :passed
7 + t.integer :submission_count
8 +
9 + t.timestamps
10 + end
11 + end
12 +
13 + def self.down
14 + drop_table :submission_statuses
15 + end
16 + end
@@ -0,0 +1,13
1 + # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2 +
3 + one:
4 + user_id: 1
5 + problem_id: 1
6 + passed: false
7 + submission_count: 1
8 +
9 + two:
10 + user_id: 1
11 + problem_id: 1
12 + passed: false
13 + submission_count: 1
@@ -0,0 +1,8
1 + require 'test_helper'
2 +
3 + class SubmissionStatusTest < ActiveSupport::TestCase
4 + # Replace this with your real tests.
5 + test "the truth" do
6 + assert true
7 + end
8 + end
@@ -8,7 +8,7
8 8 # COMMENTED OUT: filter in each action instead
9 9 # before_filter :verify_time_limit, :only => [:submit]
10 10
11 - verify :method => :post, :only => [:submit, :new_input, :download_input, :submit_solution],
11 + verify :method => :post, :only => [:submit, :download_input, :submit_solution],
12 12 :redirect_to => { :action => :index }
13 13
14 14 # COMMENT OUT: only need when having high load
@@ -176,8 +176,10
176 176 :locals => {:announcement_effect => true})
177 177 end
178 178
179 + #
179 180 # actions for Code Jom
180 - def new_input
181 + #
182 + def download_input
181 183 problem = Problem.find(params[:id])
182 184 user = User.find(session[:user_id])
183 185 if user.can_request_new_test_pair_for? problem
@@ -187,23 +189,11
187 189 send_data(assignment.test_pair.input,
188 190 { :filename => "#{problem.name}-#{assignment.request_number}.in",
189 191 :type => 'text/plain' })
190 - else
191 - flash[:notice] = 'You cannot request new input now.'
192 - redirect_to :action => 'list'
193 - end
194 - end
195 -
196 - def download_input
197 - problem = Problem.find(params[:id])
198 - user = User.find(session[:user_id])
199 - recent_assignment = user.get_recent_test_pair_assignment_for problem
200 - if recent_assignment != nil
192 + else
193 + recent_assignment = user.get_recent_test_pair_assignment_for problem
201 194 send_data(recent_assignment.test_pair.input,
202 195 { :filename => "#{problem.name}-#{recent_assignment.request_number}.in",
203 196 :type => 'text/plain' })
204 - else
205 - flash[:notice] = 'You have not requested for any input data for this problem.'
206 - redirect_to :action => 'list'
207 197 end
208 198 end
209 199
@@ -211,32 +201,52
211 201 problem = Problem.find(params[:id])
212 202 user = User.find(session[:user_id])
213 203 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'
204 + if recent_assignment == nil
205 + flash[:notice] = 'You have not requested for any input data for this problem. Please download an input first.'
206 + redirect_to :action => 'list' and return
207 + end
208 +
209 + if recent_assignment.submitted
210 + flash[:notice] = 'You have already submitted an incorrect solution for this input. Please download a new input data.'
211 + redirect_to :action => 'list' and return
212 + end
213 +
214 + if params[:file] == nil
215 + flash[:notice] = 'You have not submitted any output.'
216 + redirect_to :action => 'list' and return
217 + end
218 +
219 + submitted_solution = params[:file].read
220 + test_pair = recent_assignment.test_pair
221 + passed = test_pair.grade(submitted_solution)
222 + points = passed ? 100 : 0
223 + submission = Submission.new(:user => user,
224 + :problem => problem,
225 + :source => submitted_solution,
226 + :source_filename => params['file'].original_filename,
227 + :language_id => 0,
228 + :submitted_at => Time.new.gmtime,
229 + :graded_at => Time.new.gmtime,
230 + :points => points)
231 + submission.save
232 + recent_assignment.submitted = true
233 + recent_assignment.save
234 +
235 + status = user.get_submission_status_for(problem)
236 + if status == nil
237 + status = SubmissionStatus.new :user => user, :problem => problem, :submission_count => 0
238 + end
239 +
240 + status.submission_count += 1
241 + status.passed = passed
242 + status.save
243 +
244 + if passed
245 + flash[:notice] = 'Correct solution.'
236 246 else
237 - flash[:notice] = 'You have not requested for any input data for this problem.'
238 - redirect_to :action => 'list'
247 + flash[:notice] = 'Incorrect solution.'
239 248 end
249 + redirect_to :action => 'list'
240 250 end
241 251
242 252 protected
@@ -254,15 +264,27
254 264 end
255 265
256 266 def prepare_list_information
257 - @problems = Problem.find_available_problems
267 + @user = User.find(session[:user_id])
268 +
269 + all_problems = Problem.find_available_problems
270 +
271 + passed = {}
272 + sub_count = {}
273 + @user.submission_statuses.each do |status|
274 + if status.passed
275 + passed[status.problem_id] = true
276 + end
277 + sub_count[status.problem_id] = status.submission_count
278 + end
279 +
280 + @problems = all_problems.reject { |problem| passed.has_key? problem.id }
281 +
258 282 @prob_submissions = Array.new
259 - @user = User.find(session[:user_id])
260 283 @problems.each do |p|
261 - sub = Submission.find_last_by_user_and_problem(@user.id,p.id)
262 - if sub!=nil
263 - @prob_submissions << { :count => sub.number, :submission => sub }
284 + if sub_count.has_key? p.id
285 + @prob_submissions << { :count => sub_count[p.id] }
264 286 else
265 - @prob_submissions << { :count => 0, :submission => nil }
287 + @prob_submissions << { :count => 0 }
266 288 end
267 289 end
268 290 prepare_announcements
@@ -11,7 +11,7
11 11 validates_length_of :source, :maximum => 100_000, :allow_blank => true, :message => 'too long'
12 12 validates_length_of :source, :minimum => 1, :allow_blank => true, :message => 'too short'
13 13 validate :must_have_valid_problem
14 - validate :must_specify_language
14 + #validate :must_specify_language
15 15
16 16 before_save :assign_latest_number_if_new_recond
17 17
@@ -17,6 +17,7
17 17 :order => 'created_at DESC'
18 18
19 19 has_many :test_pair_assignments, :dependent => :delete_all
20 + has_many :submission_statuses
20 21
21 22 belongs_to :site
22 23 belongs_to :country
@@ -111,6 +112,14
111 112 end
112 113 end
113 114
115 + def get_submission_status_for(problem)
116 + SubmissionStatus.find(:first,
117 + :conditions => {
118 + :user_id => id,
119 + :problem_id => problem.id
120 + })
121 + end
122 +
114 123 def email_for_editing
115 124 if self.email==nil
116 125 "(unknown)"
@@ -9,7 +9,7
9 9 #
10 10 # It's strongly recommended to check this file into your version control system.
11 11
12 - ActiveRecord::Schema.define(:version => 20100118174404) do
12 + ActiveRecord::Schema.define(:version => 20100123154326) do
13 13
14 14 create_table "announcements", :force => true do |t|
15 15 t.string "author"
@@ -129,6 +129,15
129 129 t.string "password"
130 130 end
131 131
132 + create_table "submission_statuses", :force => true do |t|
133 + t.integer "user_id"
134 + t.integer "problem_id"
135 + t.boolean "passed"
136 + t.integer "submission_count"
137 + t.datetime "created_at"
138 + t.datetime "updated_at"
139 + end
140 +
132 141 create_table "submissions", :force => true do |t|
133 142 t.integer "user_id"
134 143 t.integer "problem_id"
deleted file
You need to be logged in to leave comments. Login now