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 # 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, :new_input, :download_input, :submit_solution],
11 + verify :method => :post, :only => [:submit, :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
@@ -176,8 +176,10
176 :locals => {:announcement_effect => true})
176 :locals => {:announcement_effect => true})
177 end
177 end
178
178
179 + #
179 # actions for Code Jom
180 # actions for Code Jom
180 - def new_input
181 + #
182 + def download_input
181 problem = Problem.find(params[:id])
183 problem = Problem.find(params[:id])
182 user = User.find(session[:user_id])
184 user = User.find(session[:user_id])
183 if user.can_request_new_test_pair_for? problem
185 if user.can_request_new_test_pair_for? problem
@@ -187,23 +189,11
187 send_data(assignment.test_pair.input,
189 send_data(assignment.test_pair.input,
188 { :filename => "#{problem.name}-#{assignment.request_number}.in",
190 { :filename => "#{problem.name}-#{assignment.request_number}.in",
189 :type => 'text/plain' })
191 :type => 'text/plain' })
190 - else
192 + else
191 - flash[:notice] = 'You cannot request new input now.'
193 + recent_assignment = user.get_recent_test_pair_assignment_for problem
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
201 send_data(recent_assignment.test_pair.input,
194 send_data(recent_assignment.test_pair.input,
202 { :filename => "#{problem.name}-#{recent_assignment.request_number}.in",
195 { :filename => "#{problem.name}-#{recent_assignment.request_number}.in",
203 :type => 'text/plain' })
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 end
197 end
208 end
198 end
209
199
@@ -211,32 +201,52
211 problem = Problem.find(params[:id])
201 problem = Problem.find(params[:id])
212 user = User.find(session[:user_id])
202 user = User.find(session[:user_id])
213 recent_assignment = user.get_recent_test_pair_assignment_for problem
203 recent_assignment = user.get_recent_test_pair_assignment_for problem
214 - if recent_assignment != nil
204 + if recent_assignment == nil
215 - submitted_solution = params[:file].read
205 + flash[:notice] = 'You have not requested for any input data for this problem. Please download an input first.'
216 - test_pair = recent_assignment.test_pair
206 + redirect_to :action => 'list' and return
217 - passed = test_pair.grade(submitted_solution)
207 + end
218 - points = passed ? 100 : 0
208 +
219 - submission = Submission.new(:user => user,
209 + if recent_assignment.submitted
220 - :problem => problem,
210 + flash[:notice] = 'You have already submitted an incorrect solution for this input. Please download a new input data.'
221 - :source => params[:file].read,
211 + redirect_to :action => 'list' and return
222 - :source_filename => params['file'].original_filename,
212 + end
223 - :language_id => 0,
213 +
224 - :submitted_at => Time.new.gmtime,
214 + if params[:file] == nil
225 - :graded_at => Time.new.gmtime,
215 + flash[:notice] = 'You have not submitted any output.'
226 - :points => points)
216 + redirect_to :action => 'list' and return
227 - submission.save
217 + end
228 - recent_assignment.submitted = true
218 +
229 - recent_assignment.save
219 + submitted_solution = params[:file].read
230 - if passed
220 + test_pair = recent_assignment.test_pair
231 - flash[:notice] = 'Correct solution'
221 + passed = test_pair.grade(submitted_solution)
232 - else
222 + points = passed ? 100 : 0
233 - flash[:notice] = 'Incorrect solution'
223 + submission = Submission.new(:user => user,
234 - end
224 + :problem => problem,
235 - redirect_to :action => 'list'
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 else
246 else
237 - flash[:notice] = 'You have not requested for any input data for this problem.'
247 + flash[:notice] = 'Incorrect solution.'
238 - redirect_to :action => 'list'
239 end
248 end
249 + redirect_to :action => 'list'
240 end
250 end
241
251
242 protected
252 protected
@@ -254,15 +264,27
254 end
264 end
255
265
256 def prepare_list_information
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 @prob_submissions = Array.new
282 @prob_submissions = Array.new
259 - @user = User.find(session[:user_id])
260 @problems.each do |p|
283 @problems.each do |p|
261 - sub = Submission.find_last_by_user_and_problem(@user.id,p.id)
284 + if sub_count.has_key? p.id
262 - if sub!=nil
285 + @prob_submissions << { :count => sub_count[p.id] }
263 - @prob_submissions << { :count => sub.number, :submission => sub }
264 else
286 else
265 - @prob_submissions << { :count => 0, :submission => nil }
287 + @prob_submissions << { :count => 0 }
266 end
288 end
267 end
289 end
268 prepare_announcements
290 prepare_announcements
@@ -11,7 +11,7
11 validates_length_of :source, :maximum => 100_000, :allow_blank => true, :message => 'too long'
11 validates_length_of :source, :maximum => 100_000, :allow_blank => true, :message => 'too long'
12 validates_length_of :source, :minimum => 1, :allow_blank => true, :message => 'too short'
12 validates_length_of :source, :minimum => 1, :allow_blank => true, :message => 'too short'
13 validate :must_have_valid_problem
13 validate :must_have_valid_problem
14 - validate :must_specify_language
14 + #validate :must_specify_language
15
15
16 before_save :assign_latest_number_if_new_recond
16 before_save :assign_latest_number_if_new_recond
17
17
@@ -17,6 +17,7
17 :order => 'created_at DESC'
17 :order => 'created_at DESC'
18
18
19 has_many :test_pair_assignments, :dependent => :delete_all
19 has_many :test_pair_assignments, :dependent => :delete_all
20 + has_many :submission_statuses
20
21
21 belongs_to :site
22 belongs_to :site
22 belongs_to :country
23 belongs_to :country
@@ -111,6 +112,14
111 end
112 end
112 end
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 def email_for_editing
123 def email_for_editing
115 if self.email==nil
124 if self.email==nil
116 "(unknown)"
125 "(unknown)"
@@ -9,7 +9,7
9 #
9 #
10 # It's strongly recommended to check this file into your version control system.
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 create_table "announcements", :force => true do |t|
14 create_table "announcements", :force => true do |t|
15 t.string "author"
15 t.string "author"
@@ -129,6 +129,15
129 t.string "password"
129 t.string "password"
130 end
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 create_table "submissions", :force => true do |t|
141 create_table "submissions", :force => true do |t|
133 t.integer "user_id"
142 t.integer "user_id"
134 t.integer "problem_id"
143 t.integer "problem_id"
deleted file
You need to be logged in to leave comments. Login now