Description:
shows recent problem after wrong submissions
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r223:1586858ff9d5 - - 4 files changed: 21 inserted, 1 deleted
@@ -195,29 +195,34 | |||||
|
195 | end |
|
195 | end |
|
196 |
|
196 | ||
|
197 | def submit_solution |
|
197 | def submit_solution |
|
198 | problem = Problem.find(params[:id]) |
|
198 | problem = Problem.find(params[:id]) |
|
199 | user = User.find(session[:user_id]) |
|
199 | user = User.find(session[:user_id]) |
|
200 | recent_assignment = user.get_recent_test_pair_assignment_for problem |
|
200 | recent_assignment = user.get_recent_test_pair_assignment_for problem |
|
|
201 | + | ||
|
201 | if recent_assignment == nil |
|
202 | if recent_assignment == nil |
|
202 | flash[:notice] = 'You have not requested for any input data for this problem. Please download an input first.' |
|
203 | flash[:notice] = 'You have not requested for any input data for this problem. Please download an input first.' |
|
|
204 | + session[:current_problem_id] = problem.id | ||
|
203 | redirect_to :action => 'list' and return |
|
205 | redirect_to :action => 'list' and return |
|
204 | end |
|
206 | end |
|
205 |
|
207 | ||
|
206 | if recent_assignment.expired? |
|
208 | if recent_assignment.expired? |
|
207 | flash[:notice] = 'The current input is expired. Please download a new input data.' |
|
209 | flash[:notice] = 'The current input is expired. Please download a new input data.' |
|
|
210 | + session[:current_problem_id] = problem.id | ||
|
208 | redirect_to :action => 'list' and return |
|
211 | redirect_to :action => 'list' and return |
|
209 | end |
|
212 | end |
|
210 |
|
213 | ||
|
211 | if recent_assignment.submitted |
|
214 | if recent_assignment.submitted |
|
212 | flash[:notice] = 'You have already submitted an incorrect solution for this input. Please download a new input data.' |
|
215 | flash[:notice] = 'You have already submitted an incorrect solution for this input. Please download a new input data.' |
|
|
216 | + session[:current_problem_id] = problem.id | ||
|
213 | redirect_to :action => 'list' and return |
|
217 | redirect_to :action => 'list' and return |
|
214 | end |
|
218 | end |
|
215 |
|
219 | ||
|
216 | if params[:file] == nil |
|
220 | if params[:file] == nil |
|
217 | flash[:notice] = 'You have not submitted any output.' |
|
221 | flash[:notice] = 'You have not submitted any output.' |
|
|
222 | + session[:current_problem_id] = problem.id | ||
|
218 | redirect_to :action => 'list' and return |
|
223 | redirect_to :action => 'list' and return |
|
219 | end |
|
224 | end |
|
220 |
|
225 | ||
|
221 | submitted_solution = params[:file].read |
|
226 | submitted_solution = params[:file].read |
|
222 | test_pair = recent_assignment.test_pair |
|
227 | test_pair = recent_assignment.test_pair |
|
223 | passed = test_pair.grade(submitted_solution) |
|
228 | passed = test_pair.grade(submitted_solution) |
@@ -244,12 +249,13 | |||||
|
244 | status.save |
|
249 | status.save |
|
245 |
|
250 | ||
|
246 | if passed |
|
251 | if passed |
|
247 | flash[:notice] = 'Correct solution.' |
|
252 | flash[:notice] = 'Correct solution.' |
|
248 | user.update_codejom_status |
|
253 | user.update_codejom_status |
|
249 | else |
|
254 | else |
|
|
255 | + session[:current_problem_id] = problem.id | ||
|
250 | flash[:notice] = 'Incorrect solution.' |
|
256 | flash[:notice] = 'Incorrect solution.' |
|
251 | end |
|
257 | end |
|
252 | redirect_to :action => 'list' |
|
258 | redirect_to :action => 'list' |
|
253 | end |
|
259 | end |
|
254 |
|
260 | ||
|
255 | protected |
|
261 | protected |
@@ -277,12 +283,19 | |||||
|
277 | if status.passed |
|
283 | if status.passed |
|
278 | passed[status.problem_id] = true |
|
284 | passed[status.problem_id] = true |
|
279 | end |
|
285 | end |
|
280 | sub_count[status.problem_id] = status.submission_count |
|
286 | sub_count[status.problem_id] = status.submission_count |
|
281 | end |
|
287 | end |
|
282 |
|
288 | ||
|
|
289 | + if session.has_key? :current_problem_id | ||
|
|
290 | + @current_problem_id = session[:current_problem_id] | ||
|
|
291 | + session.delete(:current_problem_id) | ||
|
|
292 | + else | ||
|
|
293 | + @current_problem_id = nil | ||
|
|
294 | + end | ||
|
|
295 | + | ||
|
283 | @problems = all_problems.reject { |problem| passed.has_key? problem.id } |
|
296 | @problems = all_problems.reject { |problem| passed.has_key? problem.id } |
|
284 |
|
297 | ||
|
285 | @prob_submissions = Array.new |
|
298 | @prob_submissions = Array.new |
|
286 | @problems.each do |p| |
|
299 | @problems.each do |p| |
|
287 | if sub_count.has_key? p.id |
|
300 | if sub_count.has_key? p.id |
|
288 | @prob_submissions << { :count => sub_count[p.id] } |
|
301 | @prob_submissions << { :count => sub_count[p.id] } |
@@ -16,15 +16,19 | |||||
|
16 |
|
16 | ||
|
17 | def uses_random_test_pair? |
|
17 | def uses_random_test_pair? |
|
18 | test_pair_count != 0 |
|
18 | test_pair_count != 0 |
|
19 | end |
|
19 | end |
|
20 |
|
20 | ||
|
21 | def random_test_pair(forbidden_numbers=nil) |
|
21 | def random_test_pair(forbidden_numbers=nil) |
|
|
22 | + if forbidden_numbers.length < test_pair_count | ||
|
22 | begin |
|
23 | begin |
|
23 | test_num = 1 + rand(test_pair_count) |
|
24 | test_num = 1 + rand(test_pair_count) |
|
24 | end while forbidden_numbers!=nil and forbidden_numbers.include? test_num |
|
25 | end while forbidden_numbers!=nil and forbidden_numbers.include? test_num |
|
|
26 | + else | ||
|
|
27 | + test_num = 1 + rand(test_pair_count) | ||
|
|
28 | + end | ||
|
25 | test_pairs.find_by_number test_num |
|
29 | test_pairs.find_by_number test_num |
|
26 | end |
|
30 | end |
|
27 |
|
31 | ||
|
28 | def self.find_available_problems |
|
32 | def self.find_available_problems |
|
29 | find(:all, :conditions => {:available => true}, :order => "date_added DESC") |
|
33 | find(:all, :conditions => {:available => true}, :order => "date_added DESC") |
|
30 | end |
|
34 | end |
@@ -1,12 +1,14 | |||||
|
1 | - .problem-panel{:id => "problem-panel-#{problem.id}", :style => "display:none"} |
|
1 | + .problem-panel{:id => "problem-panel-#{problem.id}", :style => "#{(problem.id != @current_problem_id) ? "display:none" : ""}"} |
|
2 | .problem-form{:id => "problem-form-#{problem.id}"} |
|
2 | .problem-form{:id => "problem-form-#{problem.id}"} |
|
3 | - form_tag({ :action => 'download_input', :id => problem.id }, :method => :post) do |
|
3 | - form_tag({ :action => 'download_input', :id => problem.id }, :method => :post) do |
|
4 | %b Input: |
|
4 | %b Input: |
|
5 | %input{:type => "submit", :value => "Download input"} |
|
5 | %input{:type => "submit", :value => "Download input"} |
|
|
6 | + %span{:id => "problem-timing-message-#{problem.id}"} | ||
|
6 | = "After downloading, you have #{TEST_ASSIGNMENT_EXPIRATION_DURATION/60} minutes to submit." |
|
7 | = "After downloading, you have #{TEST_ASSIGNMENT_EXPIRATION_DURATION/60} minutes to submit." |
|
|
8 | + %div{:id => "problem-submission-form-#{problem.id}"} | ||
|
7 | - form_tag({ :action => 'submit_solution', :id => problem.id }, :method => :post, :multipart => true) do |
|
9 | - form_tag({ :action => 'submit_solution', :id => problem.id }, :method => :post, :multipart => true) do |
|
8 | %b Submit output: |
|
10 | %b Submit output: |
|
9 | %input{:type => "file", :name => "file"} |
|
11 | %input{:type => "file", :name => "file"} |
|
10 | %input{:type => "submit", :value => "Submit solution"} |
|
12 | %input{:type => "submit", :value => "Submit solution"} |
|
11 |
|
13 | ||
|
12 | .problem-description |
|
14 | .problem-description |
@@ -17,12 +17,13 | |||||
|
17 | %p=t 'main.start_soon' |
|
17 | %p=t 'main.start_soon' |
|
18 |
|
18 | ||
|
19 | - if Configuration.show_tasks_to?(@user) |
|
19 | - if Configuration.show_tasks_to?(@user) |
|
20 | .problem-list |
|
20 | .problem-list |
|
21 | = render :partial => 'problem_title', :collection => @problems, :as => :problem |
|
21 | = render :partial => 'problem_title', :collection => @problems, :as => :problem |
|
22 | .problem-content |
|
22 | .problem-content |
|
|
23 | + - if @current_problem_id==nil | ||
|
23 | %span{:id => "problem-panel-filler"} |
|
24 | %span{:id => "problem-panel-filler"} |
|
24 | %b Welcome to Code Jom |
|
25 | %b Welcome to Code Jom |
|
25 | %br/ |
|
26 | %br/ |
|
26 | Choose problems from the list on the right. |
|
27 | Choose problems from the list on the right. |
|
27 | = render :partial => 'problem', :collection => @problems |
|
28 | = render :partial => 'problem', :collection => @problems |
|
28 |
|
29 |
You need to be logged in to leave comments.
Login now