Description:
added test pair assignment, requests new input, downloads input
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r213:805be1d05f2d - - 13 files changed: 178 inserted, 5 deleted

@@ -0,0 +1,5
1 + class TestPairAssignment < ActiveRecord::Base
2 + belongs_to :user
3 + belongs_to :test_pair
4 + belongs_to :problem
5 + end
@@ -0,0 +1,9
1 + class AddNumberToTestPair < ActiveRecord::Migration
2 + def self.up
3 + add_column 'test_pairs', 'number', :integer
4 + end
5 +
6 + def self.down
7 + remove_column 'test_pairs', 'number'
8 + end
9 + end
@@ -0,0 +1,16
1 + class CreateTestPairAssignments < ActiveRecord::Migration
2 + def self.up
3 + create_table :test_pair_assignments do |t|
4 + t.integer "user_id"
5 + t.integer "problem_id"
6 + t.integer "test_pair_id"
7 + t.integer "test_pair_number"
8 + t.integer "request_number"
9 + t.timestamps
10 + end
11 + end
12 +
13 + def self.down
14 + drop_table :test_pair_assignments
15 + end
16 + end
@@ -0,0 +1,9
1 + class AddSubmittedToTestPairAssignment < ActiveRecord::Migration
2 + def self.up
3 + add_column 'test_pair_assignments', 'submitted', :boolean
4 + end
5 +
6 + def self.down
7 + remove_column 'test_pair_assignments', 'submitted'
8 + end
9 + end
@@ -0,0 +1,7
1 + # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2 +
3 + # one:
4 + # column: value
5 + #
6 + # two:
7 + # column: value
@@ -0,0 +1,8
1 + require 'test_helper'
2 +
3 + class TestPairAssignmentTest < ActiveSupport::TestCase
4 + # Replace this with your real tests.
5 + test "the truth" do
6 + assert true
7 + end
8 + end
@@ -176,6 +176,37
176 :locals => {:announcement_effect => true})
176 :locals => {:announcement_effect => true})
177 end
177 end
178
178
179 + # actions for Code Jom
180 + def new_input
181 + problem = Problem.find(params[:id])
182 + user = User.find(session[:user_id])
183 + if user.can_request_new_test_pair_for? problem
184 + assignment = user.get_new_test_pair_assignment_for problem
185 + assignment.save
186 +
187 + send_data(assignment.test_pair.input,
188 + { :filename => "#{problem.name}-#{assignment.request_number}.in",
189 + :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
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,
202 + { :filename => "#{problem.name}-#{recent_assignment.request_number}.in",
203 + :type => 'text/plain' })
204 + else
205 + flash[:notice] = 'You have not request for any input data for this problem.'
206 + redirect_to :action => 'list'
207 + end
208 + end
209 +
179 protected
210 protected
180
211
181 def prepare_announcements(recent=nil)
212 def prepare_announcements(recent=nil)
@@ -10,6 +10,21
10 DEFAULT_TIME_LIMIT = 1
10 DEFAULT_TIME_LIMIT = 1
11 DEFAULT_MEMORY_LIMIT = 32
11 DEFAULT_MEMORY_LIMIT = 32
12
12
13 + def test_pair_count
14 + @test_pair_count ||= test_pairs.size
15 + end
16 +
17 + def uses_random_test_pair?
18 + test_pair_count != 0
19 + end
20 +
21 + def random_test_pair(forbidden_numbers=nil)
22 + begin
23 + test_num = 1 + rand(test_pair_count)
24 + end while forbidden_numbers!=nil and forbidden_numbers.include? test_num
25 + test_pairs.find_by_number test_num
26 + end
27 +
13 def self.find_available_problems
28 def self.find_available_problems
14 find(:all, :conditions => {:available => true}, :order => "date_added DESC")
29 find(:all, :conditions => {:available => true}, :order => "date_added DESC")
15 end
30 end
@@ -1,3 +1,9
1 + # TestPair stores an input-solution pair for a problem. This is used
2 + # in a certain "test-pair"-type problem for the CodeJom competition
3 + # which follows the Google Code Jam format, i.e., a participant only
4 + # submits a solution to a single random input that the participant
5 + # requested. This input-solution pair is a TestPair.
6 +
1 class TestPair < ActiveRecord::Base
7 class TestPair < ActiveRecord::Base
2 belongs_to :problem
8 belongs_to :problem
3 end
9 end
@@ -16,6 +16,8
16 :foreign_key => "receiver_id",
16 :foreign_key => "receiver_id",
17 :order => 'created_at DESC'
17 :order => 'created_at DESC'
18
18
19 + has_many :test_pair_assignments, :dependent => :delete_all
20 +
19 belongs_to :site
21 belongs_to :site
20 belongs_to :country
22 belongs_to :country
21
23
@@ -67,6 +69,48
67 self.roles.detect {|r| r.name == 'admin' }
69 self.roles.detect {|r| r.name == 'admin' }
68 end
70 end
69
71
72 + # These are methods related to test pairs
73 +
74 + def get_test_pair_assignments_for(problem)
75 + test_pair_assignments.find_all { |a| a.problem_id == problem.id }
76 + end
77 +
78 + def get_recent_test_pair_assignment_for(problem)
79 + assignments = get_test_pair_assignments_for problem
80 + if assignments.length == 0
81 + return nil
82 + else
83 + recent = assignments[0]
84 + assignments.each do |a|
85 + recent = a if a.request_number > recent.request_number
86 + end
87 + return recent
88 + end
89 + end
90 +
91 + def can_request_new_test_pair_for?(problem)
92 + recent = get_recent_test_pair_assignment_for problem
93 + return (recent == nil or recent.submitted)
94 + end
95 +
96 + def get_new_test_pair_assignment_for(problem)
97 + previous_assignment_numbers =
98 + get_test_pair_assignments_for(problem).collect {|a| a.test_pair_number }
99 + test_pair = problem.random_test_pair(previous_assignment_numbers)
100 + if test_pair
101 + assignment = TestPairAssignment.new(:user => self,
102 + :problem => problem,
103 + :test_pair => test_pair,
104 + :test_pair_number => test_pair.number,
105 + :request_number =>
106 + previous_assignment_numbers.length + 1,
107 + :submitted => false)
108 + return assignment
109 + else
110 + return nil
111 + end
112 + end
113 +
70 def email_for_editing
114 def email_for_editing
71 if self.email==nil
115 if self.email==nil
72 "(unknown)"
116 "(unknown)"
@@ -10,9 +10,17
10 <%= @prob_submissions[problem_counter][:count] %>
10 <%= @prob_submissions[problem_counter][:count] %>
11 </td>
11 </td>
12 <td>
12 <td>
13 - <%= render :partial => 'submission_short',
13 + <span id="problem-form-<%= problem.id %>">
14 - :locals => {
14 + <% form_tag "new_input/#{problem.id}", :method => :post do -%>
15 - :submission => @prob_submissions[problem_counter][:submission],
15 + <input type="submit" value="New input"/>
16 - :problem_name => problem.name }%>
16 + <% end -%>
17 + <% form_tag "download/#{problem.id}", :method => :post do -%>
18 + <input type="submit" value="Download input"/>
19 + <% end -%>
20 + <% form_tag "submit_solution/#{problem.id}", :method => :post do -%>
21 + <input type="file">
22 + <input type="submit" value="Submit solution"/>
23 + <% end -%>
24 + </span>
17 </td>
25 </td>
18 </tr>
26 </tr>
@@ -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 => 20100113094740) do
12 + ActiveRecord::Schema.define(:version => 20100118174404) 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"
@@ -155,12 +155,24
155 t.datetime "updated_at"
155 t.datetime "updated_at"
156 end
156 end
157
157
158 + create_table "test_pair_assignments", :force => true do |t|
159 + t.integer "user_id"
160 + t.integer "problem_id"
161 + t.integer "test_pair_id"
162 + t.integer "test_pair_number"
163 + t.integer "request_number"
164 + t.datetime "created_at"
165 + t.datetime "updated_at"
166 + t.boolean "submitted"
167 + end
168 +
158 create_table "test_pairs", :force => true do |t|
169 create_table "test_pairs", :force => true do |t|
159 t.integer "problem_id"
170 t.integer "problem_id"
160 t.text "input"
171 t.text "input"
161 t.text "solution"
172 t.text "solution"
162 t.datetime "created_at"
173 t.datetime "created_at"
163 t.datetime "updated_at"
174 t.datetime "updated_at"
175 + t.integer "number"
164 end
176 end
165
177
166 create_table "test_requests", :force => true do |t|
178 create_table "test_requests", :force => true do |t|
@@ -99,8 +99,11
99
99
100 break if not FileTest.exists? sol_filename
100 break if not FileTest.exists? sol_filename
101
101
102 + puts "#{dirname}"
103 +
102 test_pair = TestPair.new(:input => open(in_filename).read,
104 test_pair = TestPair.new(:input => open(in_filename).read,
103 :solution => open(sol_filename).read,
105 :solution => open(sol_filename).read,
106 + :number => test_num,
104 :problem => @problem)
107 :problem => @problem)
105 break if not test_pair.save
108 break if not test_pair.save
106
109
You need to be logged in to leave comments. Login now