Description:
added options to enable test-pair import
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r212:e6f50b45f902 - - 3 files changed: 24 inserted, 7 deleted

@@ -54,140 +54,152
54 def quick_create
54 def quick_create
55 @problem = Problem.new(params[:problem])
55 @problem = Problem.new(params[:problem])
56 @problem.full_name = @problem.name if @problem.full_name == ''
56 @problem.full_name = @problem.name if @problem.full_name == ''
57 @problem.full_score = 100
57 @problem.full_score = 100
58 @problem.available = false
58 @problem.available = false
59 @problem.test_allowed = true
59 @problem.test_allowed = true
60 @problem.output_only = false
60 @problem.output_only = false
61 @problem.date_added = Time.new
61 @problem.date_added = Time.new
62 if @problem.save
62 if @problem.save
63 flash[:notice] = 'Problem was successfully created.'
63 flash[:notice] = 'Problem was successfully created.'
64 redirect_to :action => 'list'
64 redirect_to :action => 'list'
65 else
65 else
66 flash[:notice] = 'Error saving problem'
66 flash[:notice] = 'Error saving problem'
67 redirect_to :action => 'list'
67 redirect_to :action => 'list'
68 end
68 end
69 end
69 end
70
70
71 def edit
71 def edit
72 @problem = Problem.find(params[:id])
72 @problem = Problem.find(params[:id])
73 @description = @problem.description
73 @description = @problem.description
74 end
74 end
75
75
76 def update
76 def update
77 @problem = Problem.find(params[:id])
77 @problem = Problem.find(params[:id])
78 @description = @problem.description
78 @description = @problem.description
79 if @description == nil and params[:description][:body]!=''
79 if @description == nil and params[:description][:body]!=''
80 @description = Description.new(params[:description])
80 @description = Description.new(params[:description])
81 if !@description.save
81 if !@description.save
82 flash[:notice] = 'Error saving description'
82 flash[:notice] = 'Error saving description'
83 render :action => 'edit' and return
83 render :action => 'edit' and return
84 end
84 end
85 @problem.description = @description
85 @problem.description = @description
86 elsif @description!=nil
86 elsif @description!=nil
87 if !@description.update_attributes(params[:description])
87 if !@description.update_attributes(params[:description])
88 flash[:notice] = 'Error saving description'
88 flash[:notice] = 'Error saving description'
89 render :action => 'edit' and return
89 render :action => 'edit' and return
90 end
90 end
91 end
91 end
92 if @problem.update_attributes(params[:problem])
92 if @problem.update_attributes(params[:problem])
93 flash[:notice] = 'Problem was successfully updated.'
93 flash[:notice] = 'Problem was successfully updated.'
94 redirect_to :action => 'show', :id => @problem
94 redirect_to :action => 'show', :id => @problem
95 else
95 else
96 render :action => 'edit'
96 render :action => 'edit'
97 end
97 end
98 end
98 end
99
99
100 def destroy
100 def destroy
101 Problem.find(params[:id]).destroy
101 Problem.find(params[:id]).destroy
102 redirect_to :action => 'list'
102 redirect_to :action => 'list'
103 end
103 end
104
104
105 def toggle
105 def toggle
106 @problem = Problem.find(params[:id])
106 @problem = Problem.find(params[:id])
107 @problem.available = !(@problem.available)
107 @problem.available = !(@problem.available)
108 @problem.save
108 @problem.save
109 end
109 end
110
110
111 def turn_all_off
111 def turn_all_off
112 Problem.find(:all,
112 Problem.find(:all,
113 :conditions => "available = 1").each do |problem|
113 :conditions => "available = 1").each do |problem|
114 problem.available = false
114 problem.available = false
115 problem.save
115 problem.save
116 end
116 end
117 redirect_to :action => 'list'
117 redirect_to :action => 'list'
118 end
118 end
119
119
120 def turn_all_on
120 def turn_all_on
121 Problem.find(:all,
121 Problem.find(:all,
122 :conditions => "available = 0").each do |problem|
122 :conditions => "available = 0").each do |problem|
123 problem.available = true
123 problem.available = true
124 problem.save
124 problem.save
125 end
125 end
126 redirect_to :action => 'list'
126 redirect_to :action => 'list'
127 end
127 end
128
128
129 def stat
129 def stat
130 @problem = Problem.find(params[:id])
130 @problem = Problem.find(params[:id])
131 if !@problem.available
131 if !@problem.available
132 redirect_to :controller => 'main', :action => 'list'
132 redirect_to :controller => 'main', :action => 'list'
133 else
133 else
134 @submissions = Submission.find_all_last_by_problem(params[:id])
134 @submissions = Submission.find_all_last_by_problem(params[:id])
135 end
135 end
136 end
136 end
137
137
138 def manage
138 def manage
139 @problems = Problem.find(:all, :order => 'date_added DESC')
139 @problems = Problem.find(:all, :order => 'date_added DESC')
140 end
140 end
141
141
142 def do_manage
142 def do_manage
143 if params.has_key? 'change_date_added'
143 if params.has_key? 'change_date_added'
144 change_date_added
144 change_date_added
145 end
145 end
146 redirect_to :action => 'manage'
146 redirect_to :action => 'manage'
147 end
147 end
148
148
149 def import
149 def import
150 + @allow_test_pair_import = allow_test_pair_import?
150 end
151 end
151
152
152 def do_import
153 def do_import
153 old_problem = Problem.find_by_name(params[:name])
154 old_problem = Problem.find_by_name(params[:name])
155 + if !allow_test_pair_import? and params.has_key? :import_to_db
156 + params.delete :import_to_db
157 + end
154 @problem, import_log = Problem.create_from_import_form_params(params,
158 @problem, import_log = Problem.create_from_import_form_params(params,
155 old_problem)
159 old_problem)
156
160
157 if @problem.errors.length != 0
161 if @problem.errors.length != 0
158 render :action => 'import' and return
162 render :action => 'import' and return
159 end
163 end
160
164
161 if old_problem!=nil
165 if old_problem!=nil
162 flash[:notice] = "The test data has been replaced for problem #{@problem.name}"
166 flash[:notice] = "The test data has been replaced for problem #{@problem.name}"
163 end
167 end
164 @log = import_log
168 @log = import_log
165 end
169 end
166
170
167 ##################################
171 ##################################
168 protected
172 protected
169
173
174 + def allow_test_pair_import?
175 + if defined? ALLOW_TEST_PAIR_IMPORT
176 + return ALLOW_TEST_PAIR_IMPORT
177 + else
178 + return false
179 + end
180 + end
181 +
170 def change_date_added
182 def change_date_added
171 problems = get_problems_from_params
183 problems = get_problems_from_params
172 year = params[:date_added][:year].to_i
184 year = params[:date_added][:year].to_i
173 month = params[:date_added][:month].to_i
185 month = params[:date_added][:month].to_i
174 day = params[:date_added][:day].to_i
186 day = params[:date_added][:day].to_i
175 date = Date.new(year,month,day)
187 date = Date.new(year,month,day)
176 problems.each do |p|
188 problems.each do |p|
177 p.date_added = date
189 p.date_added = date
178 p.save
190 p.save
179 end
191 end
180 end
192 end
181
193
182 def get_problems_from_params
194 def get_problems_from_params
183 problems = []
195 problems = []
184 params.keys.each do |k|
196 params.keys.each do |k|
185 if k.index('prob-')==0
197 if k.index('prob-')==0
186 name, id = k.split('-')
198 name, id = k.split('-')
187 problems << Problem.find(id)
199 problems << Problem.find(id)
188 end
200 end
189 end
201 end
190 problems
202 problems
191 end
203 end
192
204
193 end
205 end
@@ -1,58 +1,59
1 - content_for :head do
1 - content_for :head do
2 = stylesheet_link_tag 'problems'
2 = stylesheet_link_tag 'problems'
3 = javascript_include_tag :defaults
3 = javascript_include_tag :defaults
4
4
5 %h1 Import problems
5 %h1 Import problems
6
6
7 %p= link_to '[Back to problem list]', :action => 'list'
7 %p= link_to '[Back to problem list]', :action => 'list'
8
8
9 - if @problem and @problem.errors
9 - if @problem and @problem.errors
10 =error_messages_for 'problem'
10 =error_messages_for 'problem'
11
11
12 - form_tag({:action => 'do_import'}, :multipart => true) do
12 - form_tag({:action => 'do_import'}, :multipart => true) do
13 .submitbox
13 .submitbox
14 %table
14 %table
15 %tr
15 %tr
16 %td Name:
16 %td Name:
17 %td= text_field_tag 'name'
17 %td= text_field_tag 'name'
18 %tr
18 %tr
19 %td Full name:
19 %td Full name:
20 %td
20 %td
21 = text_field_tag 'full_name'
21 = text_field_tag 'full_name'
22 %span{:class => 'help'} Leave blank to use the same value as the name above.
22 %span{:class => 'help'} Leave blank to use the same value as the name above.
23 %tr
23 %tr
24 %td Testdata file:
24 %td Testdata file:
25 %td= file_field_tag 'file'
25 %td= file_field_tag 'file'
26 %tr
26 %tr
27 %td
27 %td
28 %td
28 %td
29 %span{:class => 'help'}
29 %span{:class => 'help'}
30 In .zip, .tgz, tar.gz, .tar format.
30 In .zip, .tgz, tar.gz, .tar format.
31 It should includes inputs (e.g., 1.in, 2a.in, 2b.in)
31 It should includes inputs (e.g., 1.in, 2a.in, 2b.in)
32 and solutions (e.g., 1.sol, 2a.sol, 2b.sol).
32 and solutions (e.g., 1.sol, 2a.sol, 2b.sol).
33 %br/
33 %br/
34 You may put task description in *.html for raw html
34 You may put task description in *.html for raw html
35 and *.md or *.markdown for markdown.
35 and *.md or *.markdown for markdown.
36 - %tr
36 + - if @allow_test_pair_import
37 - %td
37 + %tr
38 - %td
38 + %td
39 - = check_box_tag 'import_to_db'
39 + %td
40 - Import test data to database (for a test-pair task)
40 + = check_box_tag 'import_to_db'
41 + Import test data to database (for a test-pair task)
41 %tr
42 %tr
42 %td Time limit:
43 %td Time limit:
43 %td
44 %td
44 = text_field_tag 'time_limit'
45 = text_field_tag 'time_limit'
45 %span{:class => 'help'} In seconds. Leave blank to use 1 sec.
46 %span{:class => 'help'} In seconds. Leave blank to use 1 sec.
46 %tr
47 %tr
47 %td Memory limit:
48 %td Memory limit:
48 %td
49 %td
49 = text_field_tag 'memory_limit'
50 = text_field_tag 'memory_limit'
50 %span{:class => 'help'} In MB. Leave blank to use 32MB.
51 %span{:class => 'help'} In MB. Leave blank to use 32MB.
51 %tr
52 %tr
52 %td
53 %td
53 %td= submit_tag 'Import problem'
54 %td= submit_tag 'Import problem'
54
55
55 - if @log
56 - if @log
56 %h3 Import log
57 %h3 Import log
57 %pre.import-log
58 %pre.import-log
58 = @log
59 = @log
@@ -1,101 +1,105
1 # Be sure to restart your web server when you modify this file.
1 # Be sure to restart your web server when you modify this file.
2
2
3 # Uncomment below to force Rails into production mode when
3 # Uncomment below to force Rails into production mode when
4 # you don't control web/app server and can't set it the proper way
4 # you don't control web/app server and can't set it the proper way
5 # ENV['RAILS_ENV'] ||= 'production'
5 # ENV['RAILS_ENV'] ||= 'production'
6
6
7 # Specifies gem version of Rails to use when vendor/rails is not present
7 # Specifies gem version of Rails to use when vendor/rails is not present
8 RAILS_GEM_VERSION = '2.3.4' unless defined? RAILS_GEM_VERSION
8 RAILS_GEM_VERSION = '2.3.4' unless defined? RAILS_GEM_VERSION
9
9
10 # Bootstrap the Rails environment, frameworks, and default configuration
10 # Bootstrap the Rails environment, frameworks, and default configuration
11 require File.join(File.dirname(__FILE__), 'boot')
11 require File.join(File.dirname(__FILE__), 'boot')
12
12
13 Rails::Initializer.run do |config|
13 Rails::Initializer.run do |config|
14 # Settings in config/environments/* take precedence over those specified here
14 # Settings in config/environments/* take precedence over those specified here
15
15
16 # Skip frameworks you're not going to use (only works if using vendor/rails)
16 # Skip frameworks you're not going to use (only works if using vendor/rails)
17 # config.frameworks -= [ :action_web_service, :action_mailer ]
17 # config.frameworks -= [ :action_web_service, :action_mailer ]
18
18
19 # Only load the plugins named here, by default all plugins in vendor/plugins are loaded
19 # Only load the plugins named here, by default all plugins in vendor/plugins are loaded
20 # config.plugins = %W( exception_notification ssl_requirement )
20 # config.plugins = %W( exception_notification ssl_requirement )
21
21
22 # Add additional load paths for your own custom dirs
22 # Add additional load paths for your own custom dirs
23 # config.load_paths += %W( #{RAILS_ROOT}/extras )
23 # config.load_paths += %W( #{RAILS_ROOT}/extras )
24
24
25 # Force all environments to use the same logger level
25 # Force all environments to use the same logger level
26 # (by default production uses :info, the others :debug)
26 # (by default production uses :info, the others :debug)
27 # config.log_level = :debug
27 # config.log_level = :debug
28
28
29 # Use the database for sessions instead of the file system
29 # Use the database for sessions instead of the file system
30 # (create the session table with 'rake db:sessions:create')
30 # (create the session table with 'rake db:sessions:create')
31 config.action_controller.session_store = :active_record_store
31 config.action_controller.session_store = :active_record_store
32
32
33 # Use SQL instead of Active Record's schema dumper when creating the test database.
33 # Use SQL instead of Active Record's schema dumper when creating the test database.
34 # This is necessary if your schema can't be completely dumped by the schema dumper,
34 # This is necessary if your schema can't be completely dumped by the schema dumper,
35 # like if you have constraints or database-specific column types
35 # like if you have constraints or database-specific column types
36 # config.active_record.schema_format = :sql
36 # config.active_record.schema_format = :sql
37
37
38 # Activate observers that should always be running
38 # Activate observers that should always be running
39 # config.active_record.observers = :cacher, :garbage_collector
39 # config.active_record.observers = :cacher, :garbage_collector
40
40
41 # Make Active Record use UTC-base instead of local time
41 # Make Active Record use UTC-base instead of local time
42 config.time_zone = 'UTC'
42 config.time_zone = 'UTC'
43
43
44 # Setting locales
44 # Setting locales
45 config.i18n.default_locale = 'en'
45 config.i18n.default_locale = 'en'
46
46
47 # See Rails::Configuration for more options
47 # See Rails::Configuration for more options
48
48
49 # -------------
49 # -------------
50 # Required gems
50 # Required gems
51 # -------------
51 # -------------
52 config.gem "haml"
52 config.gem "haml"
53 config.gem "tmail"
53 config.gem "tmail"
54 config.gem "rdiscount", :lib => "rdiscount"
54 config.gem "rdiscount", :lib => "rdiscount"
55
55
56 # NOTES on rspec: if you wan to test with rspec, you have to install
56 # NOTES on rspec: if you wan to test with rspec, you have to install
57 # rspec yourself, just call: [sudo] gem install rspec-rails
57 # rspec yourself, just call: [sudo] gem install rspec-rails
58
58
59 end
59 end
60
60
61 # Add new inflection rules using the following format
61 # Add new inflection rules using the following format
62 # (all these examples are active by default):
62 # (all these examples are active by default):
63 # Inflector.inflections do |inflect|
63 # Inflector.inflections do |inflect|
64 # inflect.plural /^(ox)$/i, '\1en'
64 # inflect.plural /^(ox)$/i, '\1en'
65 # inflect.singular /^(ox)en/i, '\1'
65 # inflect.singular /^(ox)en/i, '\1'
66 # inflect.irregular 'person', 'people'
66 # inflect.irregular 'person', 'people'
67 # inflect.uncountable %w( fish sheep )
67 # inflect.uncountable %w( fish sheep )
68 # end
68 # end
69
69
70 # Add new mime types for use in respond_to blocks:
70 # Add new mime types for use in respond_to blocks:
71 # Mime::Type.register "text/richtext", :rtf
71 # Mime::Type.register "text/richtext", :rtf
72 # Mime::Type.register "application/x-mobile", :mobile
72 # Mime::Type.register "application/x-mobile", :mobile
73
73
74 # Include your application configuration below
74 # Include your application configuration below
75
75
76 # If you want to manage graders through web interface, set the path to
76 # If you want to manage graders through web interface, set the path to
77 # the grader directory below. This dir is where raw, ev, ev-exam,
77 # the grader directory below. This dir is where raw, ev, ev-exam,
78 # scripts reside. All grader scripts will be in
78 # scripts reside. All grader scripts will be in
79 # #{GRADER_ROOT_DIR}/scripts.
79 # #{GRADER_ROOT_DIR}/scripts.
80 GRADER_ROOT_DIR = ''
80 GRADER_ROOT_DIR = ''
81
81
82 # These are where inputs and outputs of test requests are stored
82 # These are where inputs and outputs of test requests are stored
83 TEST_REQUEST_INPUT_FILE_DIR = RAILS_ROOT + '/data/test_request/input'
83 TEST_REQUEST_INPUT_FILE_DIR = RAILS_ROOT + '/data/test_request/input'
84 TEST_REQUEST_OUTPUT_FILE_DIR = RAILS_ROOT + '/data/test_request/output'
84 TEST_REQUEST_OUTPUT_FILE_DIR = RAILS_ROOT + '/data/test_request/output'
85
85
86 # To use ANALYSIS MODE, provide the testcases/testruns breakdown,
86 # To use ANALYSIS MODE, provide the testcases/testruns breakdown,
87 # and the directory of the grading result (usually in judge's dir).
87 # and the directory of the grading result (usually in judge's dir).
88 TASK_GRADING_INFO_FILENAME = RAILS_ROOT + '/config/tasks.yml'
88 TASK_GRADING_INFO_FILENAME = RAILS_ROOT + '/config/tasks.yml'
89
89
90 # TODO: change this to where results are kept.
90 # TODO: change this to where results are kept.
91 GRADING_RESULT_DIR = 'RESULT-DIR'
91 GRADING_RESULT_DIR = 'RESULT-DIR'
92
92
93 - # Uncomment so that configuration is read only once when the server is loaded
93 + # Change this to allow importing testdata into database as test-pairs.
94 - # Configuration.enable_caching
94 + # This is mainly for Code Jom contest.
95 + ALLOW_TEST_PAIR_IMPORT = false
95
96
96 # Uncomment so that the system validates user e-mails
97 # Uncomment so that the system validates user e-mails
97 # VALIDATE_USER_EMAILS = true
98 # VALIDATE_USER_EMAILS = true
98
99
99 # Uncomment so that Apache X-Sendfile is used when delivering files
100 # Uncomment so that Apache X-Sendfile is used when delivering files
100 # (e.g., in /tasks/view).
101 # (e.g., in /tasks/view).
101 # USE_APACHE_XSENDFILE = true
102 # USE_APACHE_XSENDFILE = true
103 +
104 + # Uncomment so that configuration is read only once when the server is loaded
105 + # Configuration.enable_caching
You need to be logged in to leave comments. Login now