Description:
added test_pair model
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r209:491c30075d87 - - 6 files changed: 47 inserted, 1 deleted
@@ -0,0 +1,15 | |||||
|
|
1 | + class CreateTestPairs < ActiveRecord::Migration | ||
|
|
2 | + def self.up | ||
|
|
3 | + create_table :test_pairs do |t| | ||
|
|
4 | + t.integer :problem_id | ||
|
|
5 | + t.text :input | ||
|
|
6 | + t.text :solution | ||
|
|
7 | + | ||
|
|
8 | + t.timestamps | ||
|
|
9 | + end | ||
|
|
10 | + end | ||
|
|
11 | + | ||
|
|
12 | + def self.down | ||
|
|
13 | + drop_table :test_pairs | ||
|
|
14 | + end | ||
|
|
15 | + end |
@@ -0,0 +1,11 | |||||
|
|
1 | + # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html | ||
|
|
2 | + | ||
|
|
3 | + one: | ||
|
|
4 | + problem_id: 1 | ||
|
|
5 | + input: MyText | ||
|
|
6 | + solution: MyText | ||
|
|
7 | + | ||
|
|
8 | + two: | ||
|
|
9 | + problem_id: 1 | ||
|
|
10 | + input: MyText | ||
|
|
11 | + solution: MyText |
@@ -0,0 +1,8 | |||||
|
|
1 | + require 'test_helper' | ||
|
|
2 | + | ||
|
|
3 | + class TestPairTest < ActiveSupport::TestCase | ||
|
|
4 | + # Replace this with your real tests. | ||
|
|
5 | + test "the truth" do | ||
|
|
6 | + assert true | ||
|
|
7 | + end | ||
|
|
8 | + end |
@@ -1,51 +1,52 | |||||
|
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 | ||
|
4 |
|
5 | ||
|
5 | validates_presence_of :name |
|
6 | validates_presence_of :name |
|
6 | validates_format_of :name, :with => /^\w+$/ |
|
7 | validates_format_of :name, :with => /^\w+$/ |
|
7 | validates_presence_of :full_name |
|
8 | validates_presence_of :full_name |
|
8 |
|
9 | ||
|
9 | DEFAULT_TIME_LIMIT = 1 |
|
10 | DEFAULT_TIME_LIMIT = 1 |
|
10 | DEFAULT_MEMORY_LIMIT = 32 |
|
11 | DEFAULT_MEMORY_LIMIT = 32 |
|
11 |
|
12 | ||
|
12 | def self.find_available_problems |
|
13 | def self.find_available_problems |
|
13 | find(:all, :conditions => {:available => true}, :order => "date_added DESC") |
|
14 | find(:all, :conditions => {:available => true}, :order => "date_added DESC") |
|
14 | end |
|
15 | end |
|
15 |
|
16 | ||
|
16 | def self.new_from_import_form_params(params) |
|
17 | def self.new_from_import_form_params(params) |
|
17 | problem = Problem.new |
|
18 | problem = Problem.new |
|
18 | import_params = Problem.extract_params_and_check(params, problem) |
|
19 | import_params = Problem.extract_params_and_check(params, problem) |
|
19 |
|
20 | ||
|
20 | if not problem.valid? |
|
21 | if not problem.valid? |
|
21 | return problem |
|
22 | return problem |
|
22 | end |
|
23 | end |
|
23 |
|
24 | ||
|
24 | importer = TestdataImporter.new |
|
25 | importer = TestdataImporter.new |
|
25 |
|
26 | ||
|
26 | if not importer.import_from_file(problem.name, |
|
27 | if not importer.import_from_file(problem.name, |
|
27 | import_params[:file], |
|
28 | import_params[:file], |
|
28 | import_params[:time_limit], |
|
29 | import_params[:time_limit], |
|
29 | import_params[:memory_limit]) |
|
30 | import_params[:memory_limit]) |
|
30 | problem.errors.add_to_base('Import error.') |
|
31 | problem.errors.add_to_base('Import error.') |
|
31 | end |
|
32 | end |
|
32 |
|
33 | ||
|
33 | problem.full_score = 100 |
|
34 | problem.full_score = 100 |
|
34 | problem.date_added = Time.new |
|
35 | problem.date_added = Time.new |
|
35 | problem.test_allowed = true |
|
36 | problem.test_allowed = true |
|
36 | problem.output_only = false |
|
37 | problem.output_only = false |
|
37 | problem.available = false |
|
38 | problem.available = false |
|
38 | return problem, importer.log_msg |
|
39 | return problem, importer.log_msg |
|
39 | end |
|
40 | end |
|
40 |
|
41 | ||
|
41 | protected |
|
42 | protected |
|
42 |
|
43 | ||
|
43 | def self.to_i_or_default(st, default) |
|
44 | def self.to_i_or_default(st, default) |
|
44 | if st!='' |
|
45 | if st!='' |
|
45 | st.to_i |
|
46 | st.to_i |
|
46 | else |
|
47 | else |
|
47 | default |
|
48 | default |
|
48 | end |
|
49 | end |
|
49 | end |
|
50 | end |
|
50 |
|
51 | ||
|
51 | def self.extract_params_and_check(params, problem) |
|
52 | def self.extract_params_and_check(params, problem) |
@@ -1,60 +1,60 | |||||
|
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 => 20 |
|
12 | + ActiveRecord::Schema.define(:version => 20100113094740) 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| |
@@ -110,87 +110,95 | |||||
|
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_pairs", :force => true do |t| | ||
|
|
159 | + t.integer "problem_id" | ||
|
|
160 | + t.text "input" | ||
|
|
161 | + t.text "solution" | ||
|
|
162 | + t.datetime "created_at" | ||
|
|
163 | + t.datetime "updated_at" | ||
|
|
164 | + end | ||
|
|
165 | + | ||
|
158 | create_table "test_requests", :force => true do |t| |
|
166 | create_table "test_requests", :force => true do |t| |
|
159 | t.integer "user_id" |
|
167 | t.integer "user_id" |
|
160 | t.integer "problem_id" |
|
168 | t.integer "problem_id" |
|
161 | t.integer "submission_id" |
|
169 | t.integer "submission_id" |
|
162 | t.string "input_file_name" |
|
170 | t.string "input_file_name" |
|
163 | t.string "output_file_name" |
|
171 | t.string "output_file_name" |
|
164 | t.string "running_stat" |
|
172 | t.string "running_stat" |
|
165 | t.integer "status" |
|
173 | t.integer "status" |
|
166 | t.datetime "updated_at" |
|
174 | t.datetime "updated_at" |
|
167 | t.datetime "submitted_at" |
|
175 | t.datetime "submitted_at" |
|
168 | t.datetime "compiled_at" |
|
176 | t.datetime "compiled_at" |
|
169 | t.text "compiler_message" |
|
177 | t.text "compiler_message" |
|
170 | t.datetime "graded_at" |
|
178 | t.datetime "graded_at" |
|
171 | t.string "grader_comment" |
|
179 | t.string "grader_comment" |
|
172 | t.datetime "created_at" |
|
180 | t.datetime "created_at" |
|
173 | t.float "running_time" |
|
181 | t.float "running_time" |
|
174 | t.string "exit_status" |
|
182 | t.string "exit_status" |
|
175 | t.integer "memory_usage" |
|
183 | t.integer "memory_usage" |
|
176 | end |
|
184 | end |
|
177 |
|
185 | ||
|
178 | add_index "test_requests", ["user_id", "problem_id"], :name => "index_test_requests_on_user_id_and_problem_id" |
|
186 | add_index "test_requests", ["user_id", "problem_id"], :name => "index_test_requests_on_user_id_and_problem_id" |
|
179 |
|
187 | ||
|
180 | create_table "users", :force => true do |t| |
|
188 | create_table "users", :force => true do |t| |
|
181 | t.string "login", :limit => 50 |
|
189 | t.string "login", :limit => 50 |
|
182 | t.string "full_name" |
|
190 | t.string "full_name" |
|
183 | t.string "hashed_password" |
|
191 | t.string "hashed_password" |
|
184 | t.string "salt", :limit => 5 |
|
192 | t.string "salt", :limit => 5 |
|
185 | t.string "alias" |
|
193 | t.string "alias" |
|
186 | t.string "email" |
|
194 | t.string "email" |
|
187 | t.integer "site_id" |
|
195 | t.integer "site_id" |
|
188 | t.integer "country_id" |
|
196 | t.integer "country_id" |
|
189 | t.boolean "activated", :default => false |
|
197 | t.boolean "activated", :default => false |
|
190 | t.datetime "created_at" |
|
198 | t.datetime "created_at" |
|
191 | t.datetime "updated_at" |
|
199 | t.datetime "updated_at" |
|
192 | end |
|
200 | end |
|
193 |
|
201 | ||
|
194 | add_index "users", ["login"], :name => "index_users_on_login", :unique => true |
|
202 | add_index "users", ["login"], :name => "index_users_on_login", :unique => true |
|
195 |
|
203 | ||
|
196 | end |
|
204 | end |
You need to be logged in to leave comments.
Login now