Description:
added test pair assignment, requests new input, downloads input
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
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 |
@@ -83,192 +83,223 | |||||
|
83 | def source |
|
83 | def source |
|
84 | submission = Submission.find(params[:id]) |
|
84 | submission = Submission.find(params[:id]) |
|
85 | if submission.user_id == session[:user_id] |
|
85 | if submission.user_id == session[:user_id] |
|
86 | send_data(submission.source, |
|
86 | send_data(submission.source, |
|
87 | {:filename => submission.download_filename, |
|
87 | {:filename => submission.download_filename, |
|
88 | :type => 'text/plain'}) |
|
88 | :type => 'text/plain'}) |
|
89 | else |
|
89 | else |
|
90 | flash[:notice] = 'Error viewing source' |
|
90 | flash[:notice] = 'Error viewing source' |
|
91 | redirect_to :action => 'list' |
|
91 | redirect_to :action => 'list' |
|
92 | end |
|
92 | end |
|
93 | end |
|
93 | end |
|
94 |
|
94 | ||
|
95 | def compiler_msg |
|
95 | def compiler_msg |
|
96 | @submission = Submission.find(params[:id]) |
|
96 | @submission = Submission.find(params[:id]) |
|
97 | if @submission.user_id == session[:user_id] |
|
97 | if @submission.user_id == session[:user_id] |
|
98 | render :action => 'compiler_msg', :layout => 'empty' |
|
98 | render :action => 'compiler_msg', :layout => 'empty' |
|
99 | else |
|
99 | else |
|
100 | flash[:notice] = 'Error viewing source' |
|
100 | flash[:notice] = 'Error viewing source' |
|
101 | redirect_to :action => 'list' |
|
101 | redirect_to :action => 'list' |
|
102 | end |
|
102 | end |
|
103 | end |
|
103 | end |
|
104 |
|
104 | ||
|
105 | def submission |
|
105 | def submission |
|
106 | @user = User.find(session[:user_id]) |
|
106 | @user = User.find(session[:user_id]) |
|
107 | @problems = Problem.find_available_problems |
|
107 | @problems = Problem.find_available_problems |
|
108 | if params[:id]==nil |
|
108 | if params[:id]==nil |
|
109 | @problem = nil |
|
109 | @problem = nil |
|
110 | @submissions = nil |
|
110 | @submissions = nil |
|
111 | else |
|
111 | else |
|
112 | @problem = Problem.find_by_name(params[:id]) |
|
112 | @problem = Problem.find_by_name(params[:id]) |
|
113 | if not @problem.available |
|
113 | if not @problem.available |
|
114 | redirect_to :action => 'list' |
|
114 | redirect_to :action => 'list' |
|
115 | flash[:notice] = 'Error: submissions for that problem are not viewable.' |
|
115 | flash[:notice] = 'Error: submissions for that problem are not viewable.' |
|
116 | return |
|
116 | return |
|
117 | end |
|
117 | end |
|
118 | @submissions = Submission.find_all_by_user_problem(@user.id, @problem.id) |
|
118 | @submissions = Submission.find_all_by_user_problem(@user.id, @problem.id) |
|
119 | end |
|
119 | end |
|
120 | end |
|
120 | end |
|
121 |
|
121 | ||
|
122 | def result |
|
122 | def result |
|
123 | if !Configuration.show_grading_result |
|
123 | if !Configuration.show_grading_result |
|
124 | redirect_to :action => 'list' and return |
|
124 | redirect_to :action => 'list' and return |
|
125 | end |
|
125 | end |
|
126 | @user = User.find(session[:user_id]) |
|
126 | @user = User.find(session[:user_id]) |
|
127 | @submission = Submission.find(params[:id]) |
|
127 | @submission = Submission.find(params[:id]) |
|
128 | if @submission.user!=@user |
|
128 | if @submission.user!=@user |
|
129 | flash[:notice] = 'You are not allowed to view result of other users.' |
|
129 | flash[:notice] = 'You are not allowed to view result of other users.' |
|
130 | redirect_to :action => 'list' and return |
|
130 | redirect_to :action => 'list' and return |
|
131 | end |
|
131 | end |
|
132 | prepare_grading_result(@submission) |
|
132 | prepare_grading_result(@submission) |
|
133 | end |
|
133 | end |
|
134 |
|
134 | ||
|
135 | def load_output |
|
135 | def load_output |
|
136 | if !Configuration.show_grading_result or params[:num]==nil |
|
136 | if !Configuration.show_grading_result or params[:num]==nil |
|
137 | redirect_to :action => 'list' and return |
|
137 | redirect_to :action => 'list' and return |
|
138 | end |
|
138 | end |
|
139 | @user = User.find(session[:user_id]) |
|
139 | @user = User.find(session[:user_id]) |
|
140 | @submission = Submission.find(params[:id]) |
|
140 | @submission = Submission.find(params[:id]) |
|
141 | if @submission.user!=@user |
|
141 | if @submission.user!=@user |
|
142 | flash[:notice] = 'You are not allowed to view result of other users.' |
|
142 | flash[:notice] = 'You are not allowed to view result of other users.' |
|
143 | redirect_to :action => 'list' and return |
|
143 | redirect_to :action => 'list' and return |
|
144 | end |
|
144 | end |
|
145 | case_num = params[:num].to_i |
|
145 | case_num = params[:num].to_i |
|
146 | out_filename = output_filename(@user.login, |
|
146 | out_filename = output_filename(@user.login, |
|
147 | @submission.problem.name, |
|
147 | @submission.problem.name, |
|
148 | @submission.id, |
|
148 | @submission.id, |
|
149 | case_num) |
|
149 | case_num) |
|
150 | if !FileTest.exists?(out_filename) |
|
150 | if !FileTest.exists?(out_filename) |
|
151 | flash[:notice] = 'Output not found.' |
|
151 | flash[:notice] = 'Output not found.' |
|
152 | redirect_to :action => 'list' and return |
|
152 | redirect_to :action => 'list' and return |
|
153 | end |
|
153 | end |
|
154 |
|
154 | ||
|
155 | response.headers['Content-Type'] = "application/force-download" |
|
155 | response.headers['Content-Type'] = "application/force-download" |
|
156 | response.headers['Content-Disposition'] = "attachment; filename=\"output-#{case_num}.txt\"" |
|
156 | response.headers['Content-Disposition'] = "attachment; filename=\"output-#{case_num}.txt\"" |
|
157 | response.headers["X-Sendfile"] = out_filename |
|
157 | response.headers["X-Sendfile"] = out_filename |
|
158 | response.headers['Content-length'] = File.size(out_filename) |
|
158 | response.headers['Content-length'] = File.size(out_filename) |
|
159 | render :nothing => true |
|
159 | render :nothing => true |
|
160 | end |
|
160 | end |
|
161 |
|
161 | ||
|
162 | def error |
|
162 | def error |
|
163 | @user = User.find(session[:user_id]) |
|
163 | @user = User.find(session[:user_id]) |
|
164 | end |
|
164 | end |
|
165 |
|
165 | ||
|
166 | # announcement refreshing and hiding methods |
|
166 | # announcement refreshing and hiding methods |
|
167 |
|
167 | ||
|
168 | def announcements |
|
168 | def announcements |
|
169 | if params.has_key? 'recent' |
|
169 | if params.has_key? 'recent' |
|
170 | prepare_announcements(params[:recent]) |
|
170 | prepare_announcements(params[:recent]) |
|
171 | else |
|
171 | else |
|
172 | prepare_announcements |
|
172 | prepare_announcements |
|
173 | end |
|
173 | end |
|
174 | render(:partial => 'announcement', |
|
174 | render(:partial => 'announcement', |
|
175 | :collection => @announcements, |
|
175 | :collection => @announcements, |
|
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) |
|
182 | if Configuration.show_tasks_to?(@user) |
|
213 | if Configuration.show_tasks_to?(@user) |
|
183 | @announcements = Announcement.find_published(true) |
|
214 | @announcements = Announcement.find_published(true) |
|
184 | else |
|
215 | else |
|
185 | @announcements = Announcement.find_published |
|
216 | @announcements = Announcement.find_published |
|
186 | end |
|
217 | end |
|
187 | if recent!=nil |
|
218 | if recent!=nil |
|
188 | recent_id = recent.to_i |
|
219 | recent_id = recent.to_i |
|
189 | @announcements = @announcements.find_all { |a| a.id > recent_id } |
|
220 | @announcements = @announcements.find_all { |a| a.id > recent_id } |
|
190 | end |
|
221 | end |
|
191 | end |
|
222 | end |
|
192 |
|
223 | ||
|
193 | def prepare_list_information |
|
224 | def prepare_list_information |
|
194 | @problems = Problem.find_available_problems |
|
225 | @problems = Problem.find_available_problems |
|
195 | @prob_submissions = Array.new |
|
226 | @prob_submissions = Array.new |
|
196 | @user = User.find(session[:user_id]) |
|
227 | @user = User.find(session[:user_id]) |
|
197 | @problems.each do |p| |
|
228 | @problems.each do |p| |
|
198 | sub = Submission.find_last_by_user_and_problem(@user.id,p.id) |
|
229 | sub = Submission.find_last_by_user_and_problem(@user.id,p.id) |
|
199 | if sub!=nil |
|
230 | if sub!=nil |
|
200 | @prob_submissions << { :count => sub.number, :submission => sub } |
|
231 | @prob_submissions << { :count => sub.number, :submission => sub } |
|
201 | else |
|
232 | else |
|
202 | @prob_submissions << { :count => 0, :submission => nil } |
|
233 | @prob_submissions << { :count => 0, :submission => nil } |
|
203 | end |
|
234 | end |
|
204 | end |
|
235 | end |
|
205 | prepare_announcements |
|
236 | prepare_announcements |
|
206 | end |
|
237 | end |
|
207 |
|
238 | ||
|
208 | def check_viewability |
|
239 | def check_viewability |
|
209 | @user = User.find(session[:user_id]) |
|
240 | @user = User.find(session[:user_id]) |
|
210 | if (!Configuration.show_tasks_to?(@user)) and |
|
241 | if (!Configuration.show_tasks_to?(@user)) and |
|
211 | ((action_name=='submission') or (action_name=='submit')) |
|
242 | ((action_name=='submission') or (action_name=='submit')) |
|
212 | redirect_to :action => 'list' and return |
|
243 | redirect_to :action => 'list' and return |
|
213 | end |
|
244 | end |
|
214 | end |
|
245 | end |
|
215 |
|
246 | ||
|
216 | def prepare_grading_result(submission) |
|
247 | def prepare_grading_result(submission) |
|
217 | if Configuration.task_grading_info.has_key? submission.problem.name |
|
248 | if Configuration.task_grading_info.has_key? submission.problem.name |
|
218 | grading_info = Configuration.task_grading_info[submission.problem.name] |
|
249 | grading_info = Configuration.task_grading_info[submission.problem.name] |
|
219 | else |
|
250 | else |
|
220 | # guess task info from problem.full_score |
|
251 | # guess task info from problem.full_score |
|
221 | cases = submission.problem.full_score / 10 |
|
252 | cases = submission.problem.full_score / 10 |
|
222 | grading_info = { |
|
253 | grading_info = { |
|
223 | 'testruns' => cases, |
|
254 | 'testruns' => cases, |
|
224 | 'testcases' => cases |
|
255 | 'testcases' => cases |
|
225 | } |
|
256 | } |
|
226 | end |
|
257 | end |
|
227 | @test_runs = [] |
|
258 | @test_runs = [] |
|
228 | if grading_info['testruns'].is_a? Integer |
|
259 | if grading_info['testruns'].is_a? Integer |
|
229 | trun_count = grading_info['testruns'] |
|
260 | trun_count = grading_info['testruns'] |
|
230 | trun_count.times do |i| |
|
261 | trun_count.times do |i| |
|
231 | @test_runs << [ read_grading_result(@user.login, |
|
262 | @test_runs << [ read_grading_result(@user.login, |
|
232 | submission.problem.name, |
|
263 | submission.problem.name, |
|
233 | submission.id, |
|
264 | submission.id, |
|
234 | i+1) ] |
|
265 | i+1) ] |
|
235 | end |
|
266 | end |
|
236 | else |
|
267 | else |
|
237 | grading_info['testruns'].keys.sort.each do |num| |
|
268 | grading_info['testruns'].keys.sort.each do |num| |
|
238 | run = [] |
|
269 | run = [] |
|
239 | testrun = grading_info['testruns'][num] |
|
270 | testrun = grading_info['testruns'][num] |
|
240 | testrun.each do |c| |
|
271 | testrun.each do |c| |
|
241 | run << read_grading_result(@user.login, |
|
272 | run << read_grading_result(@user.login, |
|
242 | submission.problem.name, |
|
273 | submission.problem.name, |
|
243 | submission.id, |
|
274 | submission.id, |
|
244 | c) |
|
275 | c) |
|
245 | end |
|
276 | end |
|
246 | @test_runs << run |
|
277 | @test_runs << run |
|
247 | end |
|
278 | end |
|
248 | end |
|
279 | end |
|
249 | end |
|
280 | end |
|
250 |
|
281 | ||
|
251 | def grading_result_dir(user_name, problem_name, submission_id, case_num) |
|
282 | def grading_result_dir(user_name, problem_name, submission_id, case_num) |
|
252 | return "#{GRADING_RESULT_DIR}/#{user_name}/#{problem_name}/#{submission_id}/test-result/#{case_num}" |
|
283 | return "#{GRADING_RESULT_DIR}/#{user_name}/#{problem_name}/#{submission_id}/test-result/#{case_num}" |
|
253 | end |
|
284 | end |
|
254 |
|
285 | ||
|
255 | def output_filename(user_name, problem_name, submission_id, case_num) |
|
286 | def output_filename(user_name, problem_name, submission_id, case_num) |
|
256 | dir = grading_result_dir(user_name,problem_name, submission_id, case_num) |
|
287 | dir = grading_result_dir(user_name,problem_name, submission_id, case_num) |
|
257 | return "#{dir}/output.txt" |
|
288 | return "#{dir}/output.txt" |
|
258 | end |
|
289 | end |
|
259 |
|
290 | ||
|
260 | def read_grading_result(user_name, problem_name, submission_id, case_num) |
|
291 | def read_grading_result(user_name, problem_name, submission_id, case_num) |
|
261 | dir = grading_result_dir(user_name,problem_name, submission_id, case_num) |
|
292 | dir = grading_result_dir(user_name,problem_name, submission_id, case_num) |
|
262 | result_file_name = "#{dir}/result" |
|
293 | result_file_name = "#{dir}/result" |
|
263 | if !FileTest.exists?(result_file_name) |
|
294 | if !FileTest.exists?(result_file_name) |
|
264 | return {:num => case_num, :msg => 'program did not run'} |
|
295 | return {:num => case_num, :msg => 'program did not run'} |
|
265 | else |
|
296 | else |
|
266 | results = File.open(result_file_name).readlines |
|
297 | results = File.open(result_file_name).readlines |
|
267 | run_stat = extract_running_stat(results) |
|
298 | run_stat = extract_running_stat(results) |
|
268 | output_filename = "#{dir}/output.txt" |
|
299 | output_filename = "#{dir}/output.txt" |
|
269 | if FileTest.exists?(output_filename) |
|
300 | if FileTest.exists?(output_filename) |
|
270 | output_file = true |
|
301 | output_file = true |
|
271 | output_size = File.size(output_filename) |
|
302 | output_size = File.size(output_filename) |
|
272 | else |
|
303 | else |
|
273 | output_file = false |
|
304 | output_file = false |
|
274 | output_size = 0 |
|
305 | output_size = 0 |
@@ -1,101 +1,116 | |||||
|
1 | class Problem < ActiveRecord::Base |
|
1 | class Problem < ActiveRecord::Base |
|
2 |
|
2 | ||
|
3 | belongs_to :description |
|
3 | belongs_to :description |
|
4 | has_many :test_pairs, :dependent => :delete_all |
|
4 | has_many :test_pairs, :dependent => :delete_all |
|
5 |
|
5 | ||
|
6 | validates_presence_of :name |
|
6 | validates_presence_of :name |
|
7 | validates_format_of :name, :with => /^\w+$/ |
|
7 | validates_format_of :name, :with => /^\w+$/ |
|
8 | validates_presence_of :full_name |
|
8 | validates_presence_of :full_name |
|
9 |
|
9 | ||
|
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 |
|
16 |
|
31 | ||
|
17 | def self.create_from_import_form_params(params, old_problem=nil) |
|
32 | def self.create_from_import_form_params(params, old_problem=nil) |
|
18 | problem = old_problem || Problem.new |
|
33 | problem = old_problem || Problem.new |
|
19 | import_params = Problem.extract_params_and_check(params, problem) |
|
34 | import_params = Problem.extract_params_and_check(params, problem) |
|
20 |
|
35 | ||
|
21 | if not problem.valid? |
|
36 | if not problem.valid? |
|
22 | return problem, 'Error importing' |
|
37 | return problem, 'Error importing' |
|
23 | end |
|
38 | end |
|
24 |
|
39 | ||
|
25 | problem.full_score = 100 |
|
40 | problem.full_score = 100 |
|
26 | problem.date_added = Time.new |
|
41 | problem.date_added = Time.new |
|
27 | problem.test_allowed = true |
|
42 | problem.test_allowed = true |
|
28 | problem.output_only = false |
|
43 | problem.output_only = false |
|
29 | problem.available = false |
|
44 | problem.available = false |
|
30 |
|
45 | ||
|
31 | if not problem.save |
|
46 | if not problem.save |
|
32 | return problem, 'Error importing' |
|
47 | return problem, 'Error importing' |
|
33 | end |
|
48 | end |
|
34 |
|
49 | ||
|
35 | import_to_db = params.has_key? :import_to_db |
|
50 | import_to_db = params.has_key? :import_to_db |
|
36 |
|
51 | ||
|
37 | importer = TestdataImporter.new(problem) |
|
52 | importer = TestdataImporter.new(problem) |
|
38 |
|
53 | ||
|
39 | if not importer.import_from_file(import_params[:file], |
|
54 | if not importer.import_from_file(import_params[:file], |
|
40 | import_params[:time_limit], |
|
55 | import_params[:time_limit], |
|
41 | import_params[:memory_limit], |
|
56 | import_params[:memory_limit], |
|
42 | import_to_db) |
|
57 | import_to_db) |
|
43 | problem.errors.add_to_base('Import error.') |
|
58 | problem.errors.add_to_base('Import error.') |
|
44 | end |
|
59 | end |
|
45 |
|
60 | ||
|
46 | return problem, importer.log_msg |
|
61 | return problem, importer.log_msg |
|
47 | end |
|
62 | end |
|
48 |
|
63 | ||
|
49 | protected |
|
64 | protected |
|
50 |
|
65 | ||
|
51 | def self.to_i_or_default(st, default) |
|
66 | def self.to_i_or_default(st, default) |
|
52 | if st!='' |
|
67 | if st!='' |
|
53 | st.to_i |
|
68 | st.to_i |
|
54 | else |
|
69 | else |
|
55 | default |
|
70 | default |
|
56 | end |
|
71 | end |
|
57 | end |
|
72 | end |
|
58 |
|
73 | ||
|
59 | def self.extract_params_and_check(params, problem) |
|
74 | def self.extract_params_and_check(params, problem) |
|
60 | time_limit = Problem.to_i_or_default(params[:time_limit], |
|
75 | time_limit = Problem.to_i_or_default(params[:time_limit], |
|
61 | DEFAULT_TIME_LIMIT) |
|
76 | DEFAULT_TIME_LIMIT) |
|
62 | memory_limit = Problem.to_i_or_default(params[:memory_limit], |
|
77 | memory_limit = Problem.to_i_or_default(params[:memory_limit], |
|
63 | DEFAULT_MEMORY_LIMIT) |
|
78 | DEFAULT_MEMORY_LIMIT) |
|
64 |
|
79 | ||
|
65 | if time_limit==0 and time_limit_s!='0' |
|
80 | if time_limit==0 and time_limit_s!='0' |
|
66 | problem.errors.add_to_base('Time limit format errors.') |
|
81 | problem.errors.add_to_base('Time limit format errors.') |
|
67 | elsif time_limit<=0 or time_limit >60 |
|
82 | elsif time_limit<=0 or time_limit >60 |
|
68 | problem.errors.add_to_base('Time limit out of range.') |
|
83 | problem.errors.add_to_base('Time limit out of range.') |
|
69 | end |
|
84 | end |
|
70 |
|
85 | ||
|
71 | if memory_limit==0 and memory_limit_s!='0' |
|
86 | if memory_limit==0 and memory_limit_s!='0' |
|
72 | problem.errors.add_to_base('Memory limit format errors.') |
|
87 | problem.errors.add_to_base('Memory limit format errors.') |
|
73 | elsif memory_limit<=0 or memory_limit >512 |
|
88 | elsif memory_limit<=0 or memory_limit >512 |
|
74 | problem.errors.add_to_base('Memory limit out of range.') |
|
89 | problem.errors.add_to_base('Memory limit out of range.') |
|
75 | end |
|
90 | end |
|
76 |
|
91 | ||
|
77 | if params[:file]==nil or params[:file]=='' |
|
92 | if params[:file]==nil or params[:file]=='' |
|
78 | problem.errors.add_to_base('No testdata file.') |
|
93 | problem.errors.add_to_base('No testdata file.') |
|
79 | end |
|
94 | end |
|
80 |
|
95 | ||
|
81 | file = params[:file] |
|
96 | file = params[:file] |
|
82 |
|
97 | ||
|
83 | if problem.errors.length!=0 |
|
98 | if problem.errors.length!=0 |
|
84 | return problem |
|
99 | return problem |
|
85 | end |
|
100 | end |
|
86 |
|
101 | ||
|
87 | problem.name = params[:name] |
|
102 | problem.name = params[:name] |
|
88 | if params[:full_name]!='' |
|
103 | if params[:full_name]!='' |
|
89 | problem.full_name = params[:full_name] |
|
104 | problem.full_name = params[:full_name] |
|
90 | else |
|
105 | else |
|
91 | problem.full_name = params[:name] |
|
106 | problem.full_name = params[:name] |
|
92 | end |
|
107 | end |
|
93 |
|
108 | ||
|
94 | return { |
|
109 | return { |
|
95 | :time_limit => time_limit, |
|
110 | :time_limit => time_limit, |
|
96 | :memory_limit => memory_limit, |
|
111 | :memory_limit => memory_limit, |
|
97 | :file => file |
|
112 | :file => file |
|
98 | } |
|
113 | } |
|
99 | end |
|
114 | end |
|
100 |
|
115 | ||
|
101 | end |
|
116 | 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 |
@@ -1,165 +1,209 | |||||
|
1 | require 'digest/sha1' |
|
1 | require 'digest/sha1' |
|
2 |
|
2 | ||
|
3 | class User < ActiveRecord::Base |
|
3 | class User < ActiveRecord::Base |
|
4 |
|
4 | ||
|
5 | has_and_belongs_to_many :roles |
|
5 | has_and_belongs_to_many :roles |
|
6 |
|
6 | ||
|
7 | has_many :test_requests, :order => "submitted_at DESC" |
|
7 | has_many :test_requests, :order => "submitted_at DESC" |
|
8 |
|
8 | ||
|
9 | has_many :messages, |
|
9 | has_many :messages, |
|
10 | :class_name => "Message", |
|
10 | :class_name => "Message", |
|
11 | :foreign_key => "sender_id", |
|
11 | :foreign_key => "sender_id", |
|
12 | :order => 'created_at DESC' |
|
12 | :order => 'created_at DESC' |
|
13 |
|
13 | ||
|
14 | has_many :replied_messages, |
|
14 | has_many :replied_messages, |
|
15 | :class_name => "Message", |
|
15 | :class_name => "Message", |
|
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 | ||
|
22 | named_scope :activated_users, :conditions => {:activated => true} |
|
24 | named_scope :activated_users, :conditions => {:activated => true} |
|
23 |
|
25 | ||
|
24 | validates_presence_of :login |
|
26 | validates_presence_of :login |
|
25 | validates_uniqueness_of :login |
|
27 | validates_uniqueness_of :login |
|
26 | validates_format_of :login, :with => /^[\_A-Za-z0-9]+$/ |
|
28 | validates_format_of :login, :with => /^[\_A-Za-z0-9]+$/ |
|
27 | validates_length_of :login, :within => 3..30 |
|
29 | validates_length_of :login, :within => 3..30 |
|
28 |
|
30 | ||
|
29 | validates_presence_of :full_name |
|
31 | validates_presence_of :full_name |
|
30 | validates_length_of :full_name, :minimum => 1 |
|
32 | validates_length_of :full_name, :minimum => 1 |
|
31 |
|
33 | ||
|
32 | validates_presence_of :password, :if => :password_required? |
|
34 | validates_presence_of :password, :if => :password_required? |
|
33 | validates_length_of :password, :within => 4..20, :if => :password_required? |
|
35 | validates_length_of :password, :within => 4..20, :if => :password_required? |
|
34 | validates_confirmation_of :password, :if => :password_required? |
|
36 | validates_confirmation_of :password, :if => :password_required? |
|
35 |
|
37 | ||
|
36 | validates_format_of :email, |
|
38 | validates_format_of :email, |
|
37 | :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, |
|
39 | :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, |
|
38 | :if => :email_validation? |
|
40 | :if => :email_validation? |
|
39 | validate :uniqueness_of_email_from_activated_users, |
|
41 | validate :uniqueness_of_email_from_activated_users, |
|
40 | :if => :email_validation? |
|
42 | :if => :email_validation? |
|
41 | validate :enough_time_interval_between_same_email_registrations, |
|
43 | validate :enough_time_interval_between_same_email_registrations, |
|
42 | :if => :email_validation? |
|
44 | :if => :email_validation? |
|
43 |
|
45 | ||
|
44 | # these are for ytopc |
|
46 | # these are for ytopc |
|
45 | # disable for now |
|
47 | # disable for now |
|
46 | #validates_presence_of :province |
|
48 | #validates_presence_of :province |
|
47 |
|
49 | ||
|
48 | attr_accessor :password |
|
50 | attr_accessor :password |
|
49 |
|
51 | ||
|
50 | before_save :encrypt_new_password |
|
52 | before_save :encrypt_new_password |
|
51 | before_save :assign_default_site |
|
53 | before_save :assign_default_site |
|
52 |
|
54 | ||
|
53 | def self.authenticate(login, password) |
|
55 | def self.authenticate(login, password) |
|
54 | user = find_by_login(login) |
|
56 | user = find_by_login(login) |
|
55 | return user if user && user.authenticated?(password) |
|
57 | return user if user && user.authenticated?(password) |
|
56 | end |
|
58 | end |
|
57 |
|
59 | ||
|
58 | def authenticated?(password) |
|
60 | def authenticated?(password) |
|
59 | if self.activated |
|
61 | if self.activated |
|
60 | hashed_password == User.encrypt(password,self.salt) |
|
62 | hashed_password == User.encrypt(password,self.salt) |
|
61 | else |
|
63 | else |
|
62 | false |
|
64 | false |
|
63 | end |
|
65 | end |
|
64 | end |
|
66 | end |
|
65 |
|
67 | ||
|
66 | def admin? |
|
68 | def admin? |
|
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)" |
|
73 | elsif self.email=='' |
|
117 | elsif self.email=='' |
|
74 | "(blank)" |
|
118 | "(blank)" |
|
75 | else |
|
119 | else |
|
76 | self.email |
|
120 | self.email |
|
77 | end |
|
121 | end |
|
78 | end |
|
122 | end |
|
79 |
|
123 | ||
|
80 | def email_for_editing=(e) |
|
124 | def email_for_editing=(e) |
|
81 | self.email=e |
|
125 | self.email=e |
|
82 | end |
|
126 | end |
|
83 |
|
127 | ||
|
84 | def alias_for_editing |
|
128 | def alias_for_editing |
|
85 | if self.alias==nil |
|
129 | if self.alias==nil |
|
86 | "(unknown)" |
|
130 | "(unknown)" |
|
87 | elsif self.alias=='' |
|
131 | elsif self.alias=='' |
|
88 | "(blank)" |
|
132 | "(blank)" |
|
89 | else |
|
133 | else |
|
90 | self.alias |
|
134 | self.alias |
|
91 | end |
|
135 | end |
|
92 | end |
|
136 | end |
|
93 |
|
137 | ||
|
94 | def alias_for_editing=(e) |
|
138 | def alias_for_editing=(e) |
|
95 | self.alias=e |
|
139 | self.alias=e |
|
96 | end |
|
140 | end |
|
97 |
|
141 | ||
|
98 | def activation_key |
|
142 | def activation_key |
|
99 | if self.hashed_password==nil |
|
143 | if self.hashed_password==nil |
|
100 | encrypt_new_password |
|
144 | encrypt_new_password |
|
101 | end |
|
145 | end |
|
102 | Digest::SHA1.hexdigest(self.hashed_password)[0..7] |
|
146 | Digest::SHA1.hexdigest(self.hashed_password)[0..7] |
|
103 | end |
|
147 | end |
|
104 |
|
148 | ||
|
105 | def verify_activation_key(key) |
|
149 | def verify_activation_key(key) |
|
106 | key == activation_key |
|
150 | key == activation_key |
|
107 | end |
|
151 | end |
|
108 |
|
152 | ||
|
109 | def self.random_password(length=5) |
|
153 | def self.random_password(length=5) |
|
110 | chars = 'abcdefghjkmnopqrstuvwxyz' |
|
154 | chars = 'abcdefghjkmnopqrstuvwxyz' |
|
111 | password = '' |
|
155 | password = '' |
|
112 | length.times { password << chars[rand(chars.length - 1)] } |
|
156 | length.times { password << chars[rand(chars.length - 1)] } |
|
113 | password |
|
157 | password |
|
114 | end |
|
158 | end |
|
115 |
|
159 | ||
|
116 | def self.find_non_admin_with_prefix(prefix='') |
|
160 | def self.find_non_admin_with_prefix(prefix='') |
|
117 | users = User.find(:all) |
|
161 | users = User.find(:all) |
|
118 | return users.find_all { |u| !(u.admin?) and u.login.index(prefix)==0 } |
|
162 | return users.find_all { |u| !(u.admin?) and u.login.index(prefix)==0 } |
|
119 | end |
|
163 | end |
|
120 |
|
164 | ||
|
121 | protected |
|
165 | protected |
|
122 | def encrypt_new_password |
|
166 | def encrypt_new_password |
|
123 | return if password.blank? |
|
167 | return if password.blank? |
|
124 | self.salt = (10+rand(90)).to_s |
|
168 | self.salt = (10+rand(90)).to_s |
|
125 | self.hashed_password = User.encrypt(self.password,self.salt) |
|
169 | self.hashed_password = User.encrypt(self.password,self.salt) |
|
126 | end |
|
170 | end |
|
127 |
|
171 | ||
|
128 | def assign_default_site |
|
172 | def assign_default_site |
|
129 | # have to catch error when migrating (because self.site is not available). |
|
173 | # have to catch error when migrating (because self.site is not available). |
|
130 | begin |
|
174 | begin |
|
131 | if self.site==nil |
|
175 | if self.site==nil |
|
132 | self.site = Site.find_by_name('default') |
|
176 | self.site = Site.find_by_name('default') |
|
133 | if self.site==nil |
|
177 | if self.site==nil |
|
134 | self.site = Site.find(1) # when 'default has be renamed' |
|
178 | self.site = Site.find(1) # when 'default has be renamed' |
|
135 | end |
|
179 | end |
|
136 | end |
|
180 | end |
|
137 | rescue |
|
181 | rescue |
|
138 | end |
|
182 | end |
|
139 | end |
|
183 | end |
|
140 |
|
184 | ||
|
141 | def password_required? |
|
185 | def password_required? |
|
142 | self.hashed_password.blank? || !self.password.blank? |
|
186 | self.hashed_password.blank? || !self.password.blank? |
|
143 | end |
|
187 | end |
|
144 |
|
188 | ||
|
145 | def self.encrypt(string,salt) |
|
189 | def self.encrypt(string,salt) |
|
146 | Digest::SHA1.hexdigest(salt + string) |
|
190 | Digest::SHA1.hexdigest(salt + string) |
|
147 | end |
|
191 | end |
|
148 |
|
192 | ||
|
149 | def uniqueness_of_email_from_activated_users |
|
193 | def uniqueness_of_email_from_activated_users |
|
150 | user = User.activated_users.find_by_email(self.email) |
|
194 | user = User.activated_users.find_by_email(self.email) |
|
151 | if user and (user.login != self.login) |
|
195 | if user and (user.login != self.login) |
|
152 | self.errors.add_to_base("Email has already been taken") |
|
196 | self.errors.add_to_base("Email has already been taken") |
|
153 | end |
|
197 | end |
|
154 | end |
|
198 | end |
|
155 |
|
199 | ||
|
156 | def enough_time_interval_between_same_email_registrations |
|
200 | def enough_time_interval_between_same_email_registrations |
|
157 | return if !self.new_record? |
|
201 | return if !self.new_record? |
|
158 | return if self.activated |
|
202 | return if self.activated |
|
159 | open_user = User.find_by_email(self.email, |
|
203 | open_user = User.find_by_email(self.email, |
|
160 | :order => 'created_at DESC') |
|
204 | :order => 'created_at DESC') |
|
161 | if open_user and open_user.created_at and |
|
205 | if open_user and open_user.created_at and |
|
162 | (open_user.created_at > Time.now.gmtime - 5.minutes) |
|
206 | (open_user.created_at > Time.now.gmtime - 5.minutes) |
|
163 | self.errors.add_to_base("There are already unactivated registrations with this e-mail address (please wait for 5 minutes)") |
|
207 | self.errors.add_to_base("There are already unactivated registrations with this e-mail address (please wait for 5 minutes)") |
|
164 | end |
|
208 | end |
|
165 | end |
|
209 | end |
@@ -1,18 +1,26 | |||||
|
1 | <tr class="info-<%= (problem_counter%2==0) ? "even" : "odd" %>"> |
|
1 | <tr class="info-<%= (problem_counter%2==0) ? "even" : "odd" %>"> |
|
2 | <td> |
|
2 | <td> |
|
3 | <%= "#{problem_counter+1}" %> |
|
3 | <%= "#{problem_counter+1}" %> |
|
4 | </td> |
|
4 | </td> |
|
5 | <td> |
|
5 | <td> |
|
6 | <%= "#{problem.full_name} (#{problem.name})" %> |
|
6 | <%= "#{problem.full_name} (#{problem.name})" %> |
|
7 | <%= link_to "[#{t 'main.problem_desc'}]", problem.url, :popup => true if (problem.url!=nil) and (problem.url!='') %> |
|
7 | <%= link_to "[#{t 'main.problem_desc'}]", problem.url, :popup => true if (problem.url!=nil) and (problem.url!='') %> |
|
8 | </td> |
|
8 | </td> |
|
9 | <td align="center"> |
|
9 | <td align="center"> |
|
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> |
@@ -1,204 +1,216 | |||||
|
1 | # This file is auto-generated from the current state of the database. Instead of editing this file, |
|
1 | # This file is auto-generated from the current state of the database. Instead of editing this file, |
|
2 | # please use the migrations feature of Active Record to incrementally modify your database, and |
|
2 | # please use the migrations feature of Active Record to incrementally modify your database, and |
|
3 | # then regenerate this schema definition. |
|
3 | # then regenerate this schema definition. |
|
4 | # |
|
4 | # |
|
5 | # Note that this schema.rb definition is the authoritative source for your database schema. If you need |
|
5 | # Note that this schema.rb definition is the authoritative source for your database schema. If you need |
|
6 | # to create the application database on another system, you should be using db:schema:load, not running |
|
6 | # to create the application database on another system, you should be using db:schema:load, not running |
|
7 | # all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations |
|
7 | # all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations |
|
8 | # you'll amass, the slower it'll run and the greater likelihood for issues). |
|
8 | # you'll amass, the slower it'll run and the greater likelihood for issues). |
|
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 => 2010011 |
|
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" |
|
16 | t.text "body" |
|
16 | t.text "body" |
|
17 | t.boolean "published" |
|
17 | t.boolean "published" |
|
18 | t.datetime "created_at" |
|
18 | t.datetime "created_at" |
|
19 | t.datetime "updated_at" |
|
19 | t.datetime "updated_at" |
|
20 | t.boolean "frontpage", :default => false |
|
20 | t.boolean "frontpage", :default => false |
|
21 | t.boolean "contest_only", :default => false |
|
21 | t.boolean "contest_only", :default => false |
|
22 | t.string "title" |
|
22 | t.string "title" |
|
23 | end |
|
23 | end |
|
24 |
|
24 | ||
|
25 | create_table "configurations", :force => true do |t| |
|
25 | create_table "configurations", :force => true do |t| |
|
26 | t.string "key" |
|
26 | t.string "key" |
|
27 | t.string "value_type" |
|
27 | t.string "value_type" |
|
28 | t.string "value" |
|
28 | t.string "value" |
|
29 | t.datetime "created_at" |
|
29 | t.datetime "created_at" |
|
30 | t.datetime "updated_at" |
|
30 | t.datetime "updated_at" |
|
31 | end |
|
31 | end |
|
32 |
|
32 | ||
|
33 | create_table "countries", :force => true do |t| |
|
33 | create_table "countries", :force => true do |t| |
|
34 | t.string "name" |
|
34 | t.string "name" |
|
35 | t.datetime "created_at" |
|
35 | t.datetime "created_at" |
|
36 | t.datetime "updated_at" |
|
36 | t.datetime "updated_at" |
|
37 | end |
|
37 | end |
|
38 |
|
38 | ||
|
39 | create_table "descriptions", :force => true do |t| |
|
39 | create_table "descriptions", :force => true do |t| |
|
40 | t.text "body" |
|
40 | t.text "body" |
|
41 | t.boolean "markdowned" |
|
41 | t.boolean "markdowned" |
|
42 | t.datetime "created_at" |
|
42 | t.datetime "created_at" |
|
43 | t.datetime "updated_at" |
|
43 | t.datetime "updated_at" |
|
44 | end |
|
44 | end |
|
45 |
|
45 | ||
|
46 | create_table "grader_processes", :force => true do |t| |
|
46 | create_table "grader_processes", :force => true do |t| |
|
47 | t.string "host", :limit => 20 |
|
47 | t.string "host", :limit => 20 |
|
48 | t.integer "pid" |
|
48 | t.integer "pid" |
|
49 | t.string "mode" |
|
49 | t.string "mode" |
|
50 | t.boolean "active" |
|
50 | t.boolean "active" |
|
51 | t.datetime "created_at" |
|
51 | t.datetime "created_at" |
|
52 | t.datetime "updated_at" |
|
52 | t.datetime "updated_at" |
|
53 | t.integer "task_id" |
|
53 | t.integer "task_id" |
|
54 | t.string "task_type" |
|
54 | t.string "task_type" |
|
55 | t.boolean "terminated" |
|
55 | t.boolean "terminated" |
|
56 | end |
|
56 | end |
|
57 |
|
57 | ||
|
58 | add_index "grader_processes", ["host", "pid"], :name => "index_grader_processes_on_ip_and_pid" |
|
58 | add_index "grader_processes", ["host", "pid"], :name => "index_grader_processes_on_ip_and_pid" |
|
59 |
|
59 | ||
|
60 | create_table "languages", :force => true do |t| |
|
60 | create_table "languages", :force => true do |t| |
|
61 | t.string "name", :limit => 10 |
|
61 | t.string "name", :limit => 10 |
|
62 | t.string "pretty_name" |
|
62 | t.string "pretty_name" |
|
63 | t.string "ext", :limit => 10 |
|
63 | t.string "ext", :limit => 10 |
|
64 | t.string "common_ext" |
|
64 | t.string "common_ext" |
|
65 | end |
|
65 | end |
|
66 |
|
66 | ||
|
67 | create_table "messages", :force => true do |t| |
|
67 | create_table "messages", :force => true do |t| |
|
68 | t.integer "sender_id" |
|
68 | t.integer "sender_id" |
|
69 | t.integer "receiver_id" |
|
69 | t.integer "receiver_id" |
|
70 | t.integer "replying_message_id" |
|
70 | t.integer "replying_message_id" |
|
71 | t.text "body" |
|
71 | t.text "body" |
|
72 | t.boolean "replied" |
|
72 | t.boolean "replied" |
|
73 | t.datetime "created_at" |
|
73 | t.datetime "created_at" |
|
74 | t.datetime "updated_at" |
|
74 | t.datetime "updated_at" |
|
75 | end |
|
75 | end |
|
76 |
|
76 | ||
|
77 | create_table "problems", :force => true do |t| |
|
77 | create_table "problems", :force => true do |t| |
|
78 | t.string "name", :limit => 30 |
|
78 | t.string "name", :limit => 30 |
|
79 | t.string "full_name" |
|
79 | t.string "full_name" |
|
80 | t.integer "full_score" |
|
80 | t.integer "full_score" |
|
81 | t.date "date_added" |
|
81 | t.date "date_added" |
|
82 | t.boolean "available" |
|
82 | t.boolean "available" |
|
83 | t.string "url" |
|
83 | t.string "url" |
|
84 | t.integer "description_id" |
|
84 | t.integer "description_id" |
|
85 | t.boolean "test_allowed" |
|
85 | t.boolean "test_allowed" |
|
86 | t.boolean "output_only" |
|
86 | t.boolean "output_only" |
|
87 | end |
|
87 | end |
|
88 |
|
88 | ||
|
89 | create_table "rights", :force => true do |t| |
|
89 | create_table "rights", :force => true do |t| |
|
90 | t.string "name" |
|
90 | t.string "name" |
|
91 | t.string "controller" |
|
91 | t.string "controller" |
|
92 | t.string "action" |
|
92 | t.string "action" |
|
93 | end |
|
93 | end |
|
94 |
|
94 | ||
|
95 | create_table "rights_roles", :id => false, :force => true do |t| |
|
95 | create_table "rights_roles", :id => false, :force => true do |t| |
|
96 | t.integer "right_id" |
|
96 | t.integer "right_id" |
|
97 | t.integer "role_id" |
|
97 | t.integer "role_id" |
|
98 | end |
|
98 | end |
|
99 |
|
99 | ||
|
100 | add_index "rights_roles", ["role_id"], :name => "index_rights_roles_on_role_id" |
|
100 | add_index "rights_roles", ["role_id"], :name => "index_rights_roles_on_role_id" |
|
101 |
|
101 | ||
|
102 | create_table "roles", :force => true do |t| |
|
102 | create_table "roles", :force => true do |t| |
|
103 | t.string "name" |
|
103 | t.string "name" |
|
104 | end |
|
104 | end |
|
105 |
|
105 | ||
|
106 | create_table "roles_users", :id => false, :force => true do |t| |
|
106 | create_table "roles_users", :id => false, :force => true do |t| |
|
107 | t.integer "role_id" |
|
107 | t.integer "role_id" |
|
108 | t.integer "user_id" |
|
108 | t.integer "user_id" |
|
109 | end |
|
109 | end |
|
110 |
|
110 | ||
|
111 | add_index "roles_users", ["user_id"], :name => "index_roles_users_on_user_id" |
|
111 | add_index "roles_users", ["user_id"], :name => "index_roles_users_on_user_id" |
|
112 |
|
112 | ||
|
113 | create_table "sessions", :force => true do |t| |
|
113 | create_table "sessions", :force => true do |t| |
|
114 | t.string "session_id" |
|
114 | t.string "session_id" |
|
115 | t.text "data" |
|
115 | t.text "data" |
|
116 | t.datetime "updated_at" |
|
116 | t.datetime "updated_at" |
|
117 | end |
|
117 | end |
|
118 |
|
118 | ||
|
119 | add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id" |
|
119 | add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id" |
|
120 | add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at" |
|
120 | add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at" |
|
121 |
|
121 | ||
|
122 | create_table "sites", :force => true do |t| |
|
122 | create_table "sites", :force => true do |t| |
|
123 | t.string "name" |
|
123 | t.string "name" |
|
124 | t.boolean "started" |
|
124 | t.boolean "started" |
|
125 | t.datetime "start_time" |
|
125 | t.datetime "start_time" |
|
126 | t.datetime "created_at" |
|
126 | t.datetime "created_at" |
|
127 | t.datetime "updated_at" |
|
127 | t.datetime "updated_at" |
|
128 | t.integer "country_id" |
|
128 | t.integer "country_id" |
|
129 | t.string "password" |
|
129 | t.string "password" |
|
130 | end |
|
130 | end |
|
131 |
|
131 | ||
|
132 | create_table "submissions", :force => true do |t| |
|
132 | create_table "submissions", :force => true do |t| |
|
133 | t.integer "user_id" |
|
133 | t.integer "user_id" |
|
134 | t.integer "problem_id" |
|
134 | t.integer "problem_id" |
|
135 | t.integer "language_id" |
|
135 | t.integer "language_id" |
|
136 | t.text "source" |
|
136 | t.text "source" |
|
137 | t.binary "binary" |
|
137 | t.binary "binary" |
|
138 | t.datetime "submitted_at" |
|
138 | t.datetime "submitted_at" |
|
139 | t.datetime "compiled_at" |
|
139 | t.datetime "compiled_at" |
|
140 | t.text "compiler_message" |
|
140 | t.text "compiler_message" |
|
141 | t.datetime "graded_at" |
|
141 | t.datetime "graded_at" |
|
142 | t.integer "points" |
|
142 | t.integer "points" |
|
143 | t.text "grader_comment" |
|
143 | t.text "grader_comment" |
|
144 | t.integer "number" |
|
144 | t.integer "number" |
|
145 | t.string "source_filename" |
|
145 | t.string "source_filename" |
|
146 | end |
|
146 | end |
|
147 |
|
147 | ||
|
148 | add_index "submissions", ["user_id", "problem_id", "number"], :name => "index_submissions_on_user_id_and_problem_id_and_number", :unique => true |
|
148 | add_index "submissions", ["user_id", "problem_id", "number"], :name => "index_submissions_on_user_id_and_problem_id_and_number", :unique => true |
|
149 | add_index "submissions", ["user_id", "problem_id"], :name => "index_submissions_on_user_id_and_problem_id" |
|
149 | add_index "submissions", ["user_id", "problem_id"], :name => "index_submissions_on_user_id_and_problem_id" |
|
150 |
|
150 | ||
|
151 | create_table "tasks", :force => true do |t| |
|
151 | create_table "tasks", :force => true do |t| |
|
152 | t.integer "submission_id" |
|
152 | t.integer "submission_id" |
|
153 | t.datetime "created_at" |
|
153 | t.datetime "created_at" |
|
154 | t.integer "status" |
|
154 | t.integer "status" |
|
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| |
|
167 | t.integer "user_id" |
|
179 | t.integer "user_id" |
|
168 | t.integer "problem_id" |
|
180 | t.integer "problem_id" |
|
169 | t.integer "submission_id" |
|
181 | t.integer "submission_id" |
|
170 | t.string "input_file_name" |
|
182 | t.string "input_file_name" |
|
171 | t.string "output_file_name" |
|
183 | t.string "output_file_name" |
|
172 | t.string "running_stat" |
|
184 | t.string "running_stat" |
|
173 | t.integer "status" |
|
185 | t.integer "status" |
|
174 | t.datetime "updated_at" |
|
186 | t.datetime "updated_at" |
|
175 | t.datetime "submitted_at" |
|
187 | t.datetime "submitted_at" |
|
176 | t.datetime "compiled_at" |
|
188 | t.datetime "compiled_at" |
|
177 | t.text "compiler_message" |
|
189 | t.text "compiler_message" |
|
178 | t.datetime "graded_at" |
|
190 | t.datetime "graded_at" |
|
179 | t.string "grader_comment" |
|
191 | t.string "grader_comment" |
|
180 | t.datetime "created_at" |
|
192 | t.datetime "created_at" |
|
181 | t.float "running_time" |
|
193 | t.float "running_time" |
|
182 | t.string "exit_status" |
|
194 | t.string "exit_status" |
|
183 | t.integer "memory_usage" |
|
195 | t.integer "memory_usage" |
|
184 | end |
|
196 | end |
|
185 |
|
197 | ||
|
186 | add_index "test_requests", ["user_id", "problem_id"], :name => "index_test_requests_on_user_id_and_problem_id" |
|
198 | add_index "test_requests", ["user_id", "problem_id"], :name => "index_test_requests_on_user_id_and_problem_id" |
|
187 |
|
199 | ||
|
188 | create_table "users", :force => true do |t| |
|
200 | create_table "users", :force => true do |t| |
|
189 | t.string "login", :limit => 50 |
|
201 | t.string "login", :limit => 50 |
|
190 | t.string "full_name" |
|
202 | t.string "full_name" |
|
191 | t.string "hashed_password" |
|
203 | t.string "hashed_password" |
|
192 | t.string "salt", :limit => 5 |
|
204 | t.string "salt", :limit => 5 |
|
193 | t.string "alias" |
|
205 | t.string "alias" |
|
194 | t.string "email" |
|
206 | t.string "email" |
|
195 | t.integer "site_id" |
|
207 | t.integer "site_id" |
|
196 | t.integer "country_id" |
|
208 | t.integer "country_id" |
|
197 | t.boolean "activated", :default => false |
|
209 | t.boolean "activated", :default => false |
|
198 | t.datetime "created_at" |
|
210 | t.datetime "created_at" |
|
199 | t.datetime "updated_at" |
|
211 | t.datetime "updated_at" |
|
200 | end |
|
212 | end |
|
201 |
|
213 | ||
|
202 | add_index "users", ["login"], :name => "index_users_on_login", :unique => true |
|
214 | add_index "users", ["login"], :name => "index_users_on_login", :unique => true |
|
203 |
|
215 | ||
|
204 | end |
|
216 | end |
@@ -6,129 +6,132 | |||||
|
6 |
|
6 | ||
|
7 | def initialize(problem) |
|
7 | def initialize(problem) |
|
8 | @problem = problem |
|
8 | @problem = problem |
|
9 | end |
|
9 | end |
|
10 |
|
10 | ||
|
11 | def import_from_file(tempfile, |
|
11 | def import_from_file(tempfile, |
|
12 | time_limit, |
|
12 | time_limit, |
|
13 | memory_limit, |
|
13 | memory_limit, |
|
14 | import_to_db=false) |
|
14 | import_to_db=false) |
|
15 |
|
15 | ||
|
16 | dirname = extract(tempfile) |
|
16 | dirname = extract(tempfile) |
|
17 | return false if not dirname |
|
17 | return false if not dirname |
|
18 | if not import_to_db |
|
18 | if not import_to_db |
|
19 | @log_msg = GraderScript.call_import_problem(@problem.name, |
|
19 | @log_msg = GraderScript.call_import_problem(@problem.name, |
|
20 | dirname, |
|
20 | dirname, |
|
21 | time_limit, |
|
21 | time_limit, |
|
22 | memory_limit) |
|
22 | memory_limit) |
|
23 | else |
|
23 | else |
|
24 | # Import test data to test pairs. |
|
24 | # Import test data to test pairs. |
|
25 |
|
25 | ||
|
26 | @problem.test_pairs.clear |
|
26 | @problem.test_pairs.clear |
|
27 | if import_test_pairs(dirname) |
|
27 | if import_test_pairs(dirname) |
|
28 | test_pair_count = TestPair.count :conditions => "problem_id = #{@problem.id}" |
|
28 | test_pair_count = TestPair.count :conditions => "problem_id = #{@problem.id}" |
|
29 | @log_msg = "Importing test pair successful. (#{test_pair_count} test pairs imported)" |
|
29 | @log_msg = "Importing test pair successful. (#{test_pair_count} test pairs imported)" |
|
30 | else |
|
30 | else |
|
31 | @log_msg = "Importing test pair failed. (0 test pairs imported)" |
|
31 | @log_msg = "Importing test pair failed. (0 test pairs imported)" |
|
32 | end |
|
32 | end |
|
33 | end |
|
33 | end |
|
34 |
|
34 | ||
|
35 | @log_msg << import_problem_description(dirname) |
|
35 | @log_msg << import_problem_description(dirname) |
|
36 |
|
36 | ||
|
37 | return true |
|
37 | return true |
|
38 | end |
|
38 | end |
|
39 |
|
39 | ||
|
40 | protected |
|
40 | protected |
|
41 |
|
41 | ||
|
42 | def self.long_ext(filename) |
|
42 | def self.long_ext(filename) |
|
43 | i = filename.index('.') |
|
43 | i = filename.index('.') |
|
44 | len = filename.length |
|
44 | len = filename.length |
|
45 | return filename.slice(i..len) |
|
45 | return filename.slice(i..len) |
|
46 | end |
|
46 | end |
|
47 |
|
47 | ||
|
48 | def extract(tempfile) |
|
48 | def extract(tempfile) |
|
49 | testdata_filename = save_testdata_file(tempfile) |
|
49 | testdata_filename = save_testdata_file(tempfile) |
|
50 | ext = TestdataImporter.long_ext(tempfile.original_filename) |
|
50 | ext = TestdataImporter.long_ext(tempfile.original_filename) |
|
51 |
|
51 | ||
|
52 | extract_dir = File.join(GraderScript.raw_dir, @problem.name) |
|
52 | extract_dir = File.join(GraderScript.raw_dir, @problem.name) |
|
53 | begin |
|
53 | begin |
|
54 | Dir.mkdir extract_dir |
|
54 | Dir.mkdir extract_dir |
|
55 | rescue Errno::EEXIST |
|
55 | rescue Errno::EEXIST |
|
56 | end |
|
56 | end |
|
57 |
|
57 | ||
|
58 | if ext=='.tar.gz' or ext=='.tgz' |
|
58 | if ext=='.tar.gz' or ext=='.tgz' |
|
59 | cmd = "tar -zxvf #{testdata_filename} -C #{extract_dir}" |
|
59 | cmd = "tar -zxvf #{testdata_filename} -C #{extract_dir}" |
|
60 | elsif ext=='.tar' |
|
60 | elsif ext=='.tar' |
|
61 | cmd = "tar -xvf #{testdata_filename} -C #{extract_dir}" |
|
61 | cmd = "tar -xvf #{testdata_filename} -C #{extract_dir}" |
|
62 | elsif ext=='.zip' |
|
62 | elsif ext=='.zip' |
|
63 | cmd = "unzip -o #{testdata_filename} -d #{extract_dir}" |
|
63 | cmd = "unzip -o #{testdata_filename} -d #{extract_dir}" |
|
64 | else |
|
64 | else |
|
65 | return nil |
|
65 | return nil |
|
66 | end |
|
66 | end |
|
67 |
|
67 | ||
|
68 | system(cmd) |
|
68 | system(cmd) |
|
69 |
|
69 | ||
|
70 | files = Dir["#{extract_dir}/**/*1*.in"] |
|
70 | files = Dir["#{extract_dir}/**/*1*.in"] |
|
71 | return nil if files.length==0 |
|
71 | return nil if files.length==0 |
|
72 |
|
72 | ||
|
73 | return File.dirname(files[0]) |
|
73 | return File.dirname(files[0]) |
|
74 | end |
|
74 | end |
|
75 |
|
75 | ||
|
76 | def save_testdata_file(tempfile) |
|
76 | def save_testdata_file(tempfile) |
|
77 | ext = TestdataImporter.long_ext(tempfile.original_filename) |
|
77 | ext = TestdataImporter.long_ext(tempfile.original_filename) |
|
78 | testdata_filename = File.join(Dir.tmpdir,"#{@problem.name}#{ext}") |
|
78 | testdata_filename = File.join(Dir.tmpdir,"#{@problem.name}#{ext}") |
|
79 |
|
79 | ||
|
80 | return nil if tempfile=="" |
|
80 | return nil if tempfile=="" |
|
81 |
|
81 | ||
|
82 | if tempfile.instance_of?(Tempfile) |
|
82 | if tempfile.instance_of?(Tempfile) |
|
83 | tempfile.close |
|
83 | tempfile.close |
|
84 | FileUtils.move(tempfile.path,testdata_filename) |
|
84 | FileUtils.move(tempfile.path,testdata_filename) |
|
85 | else |
|
85 | else |
|
86 | File.open(testdata_filename, "wb") do |f| |
|
86 | File.open(testdata_filename, "wb") do |f| |
|
87 | f.write(tempfile.read) |
|
87 | f.write(tempfile.read) |
|
88 | end |
|
88 | end |
|
89 | end |
|
89 | end |
|
90 |
|
90 | ||
|
91 | return testdata_filename |
|
91 | return testdata_filename |
|
92 | end |
|
92 | end |
|
93 |
|
93 | ||
|
94 | def import_test_pairs(dirname) |
|
94 | def import_test_pairs(dirname) |
|
95 | test_num = 1 |
|
95 | test_num = 1 |
|
96 | while FileTest.exists? "#{dirname}/#{test_num}.in" |
|
96 | while FileTest.exists? "#{dirname}/#{test_num}.in" |
|
97 | in_filename = "#{dirname}/#{test_num}.in" |
|
97 | in_filename = "#{dirname}/#{test_num}.in" |
|
98 | sol_filename = "#{dirname}/#{test_num}.sol" |
|
98 | sol_filename = "#{dirname}/#{test_num}.sol" |
|
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 | ||
|
107 | test_num += 1 |
|
110 | test_num += 1 |
|
108 | end |
|
111 | end |
|
109 | return test_num > 1 |
|
112 | return test_num > 1 |
|
110 | end |
|
113 | end |
|
111 |
|
114 | ||
|
112 | def import_problem_description(dirname) |
|
115 | def import_problem_description(dirname) |
|
113 | html_files = Dir["#{dirname}/*.html"] |
|
116 | html_files = Dir["#{dirname}/*.html"] |
|
114 | markdown_files = Dir["#{dirname}/*.md"] + Dir["#{dirname}/*.markdown"] |
|
117 | markdown_files = Dir["#{dirname}/*.md"] + Dir["#{dirname}/*.markdown"] |
|
115 | if (html_files.length != 0) or (markdown_files.length != 0) |
|
118 | if (html_files.length != 0) or (markdown_files.length != 0) |
|
116 | description = @problem.description || Description.new |
|
119 | description = @problem.description || Description.new |
|
117 |
|
120 | ||
|
118 | if html_files.length != 0 |
|
121 | if html_files.length != 0 |
|
119 | filename = html_files[0] |
|
122 | filename = html_files[0] |
|
120 | description.markdowned = false |
|
123 | description.markdowned = false |
|
121 | else |
|
124 | else |
|
122 | filename = markdown_files[0] |
|
125 | filename = markdown_files[0] |
|
123 | description.markdowned = true |
|
126 | description.markdowned = true |
|
124 | end |
|
127 | end |
|
125 |
|
128 | ||
|
126 | description.body = open(filename).read |
|
129 | description.body = open(filename).read |
|
127 | description.save |
|
130 | description.save |
|
128 | @problem.description = description |
|
131 | @problem.description = description |
|
129 | @problem.save |
|
132 | @problem.save |
|
130 | return "\nProblem description imported from #{filename}." |
|
133 | return "\nProblem description imported from #{filename}." |
|
131 | end |
|
134 | end |
|
132 | end |
|
135 | end |
|
133 |
|
136 | ||
|
134 | end |
|
137 | end |
You need to be logged in to leave comments.
Login now