Description:
added time out check for code jom submissions
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r242:803c8843ad9b - - 3 files changed: 18 inserted, 4 deleted

@@ -135,118 +135,127
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 #
179 #
180 # actions for Code Jom
180 # actions for Code Jom
181 #
181 #
182 def download_input
182 def download_input
183 + user = User.find(session[:user_id])
184 +
185 + if Configuration.time_limit_mode? and user.contest_finished?
186 + redirect_to :action => 'list' and return
187 + end
188 +
183 problem = Problem.find(params[:id])
189 problem = Problem.find(params[:id])
184 - user = User.find(session[:user_id])
185 if user.can_request_new_test_pair_for? problem
190 if user.can_request_new_test_pair_for? problem
186 assignment = user.get_new_test_pair_assignment_for problem
191 assignment = user.get_new_test_pair_assignment_for problem
187 assignment.save
192 assignment.save
188
193
189 send_data(assignment.test_pair.input,
194 send_data(assignment.test_pair.input,
190 { :filename => "#{problem.name}-#{assignment.request_number}.in",
195 { :filename => "#{problem.name}-#{assignment.request_number}.in",
191 :type => 'text/plain' })
196 :type => 'text/plain' })
192 else
197 else
193 recent_assignment = user.get_recent_test_pair_assignment_for problem
198 recent_assignment = user.get_recent_test_pair_assignment_for problem
194 send_data(recent_assignment.test_pair.input,
199 send_data(recent_assignment.test_pair.input,
195 { :filename => "#{problem.name}-#{recent_assignment.request_number}.in",
200 { :filename => "#{problem.name}-#{recent_assignment.request_number}.in",
196 :type => 'text/plain' })
201 :type => 'text/plain' })
197 end
202 end
198 end
203 end
199
204
200 def submit_solution
205 def submit_solution
201 problem = Problem.find(params[:id])
206 problem = Problem.find(params[:id])
202 user = User.find(session[:user_id])
207 user = User.find(session[:user_id])
203 recent_assignment = user.get_recent_test_pair_assignment_for problem
208 recent_assignment = user.get_recent_test_pair_assignment_for problem
204
209
210 + if Configuration.time_limit_mode? and user.contest_finished?
211 + redirect_to :action => 'list' and return
212 + end
213 +
205 if recent_assignment == nil
214 if recent_assignment == nil
206 flash[:notice] = 'You have not requested for any input data for this problem. Please download an input first.'
215 flash[:notice] = 'You have not requested for any input data for this problem. Please download an input first.'
207 session[:current_problem_id] = problem.id
216 session[:current_problem_id] = problem.id
208 redirect_to :action => 'list' and return
217 redirect_to :action => 'list' and return
209 end
218 end
210
219
211 if recent_assignment.expired?
220 if recent_assignment.expired?
212 flash[:notice] = 'The current input is expired. Please download a new input data.'
221 flash[:notice] = 'The current input is expired. Please download a new input data.'
213 session[:current_problem_id] = problem.id
222 session[:current_problem_id] = problem.id
214 redirect_to :action => 'list' and return
223 redirect_to :action => 'list' and return
215 end
224 end
216
225
217 if recent_assignment.submitted
226 if recent_assignment.submitted
218 flash[:notice] = 'You have already submitted an incorrect solution for this input. Please download a new input data.'
227 flash[:notice] = 'You have already submitted an incorrect solution for this input. Please download a new input data.'
219 session[:current_problem_id] = problem.id
228 session[:current_problem_id] = problem.id
220 redirect_to :action => 'list' and return
229 redirect_to :action => 'list' and return
221 end
230 end
222
231
223 if params[:file] == nil
232 if params[:file] == nil
224 flash[:notice] = 'You have not submitted any output.'
233 flash[:notice] = 'You have not submitted any output.'
225 session[:current_problem_id] = problem.id
234 session[:current_problem_id] = problem.id
226 redirect_to :action => 'list' and return
235 redirect_to :action => 'list' and return
227 end
236 end
228
237
229 submitted_solution = params[:file].read
238 submitted_solution = params[:file].read
230 test_pair = recent_assignment.test_pair
239 test_pair = recent_assignment.test_pair
231 passed = test_pair.grade(submitted_solution)
240 passed = test_pair.grade(submitted_solution)
232 points = passed ? 100 : 0
241 points = passed ? 100 : 0
233 submission = Submission.new(:user => user,
242 submission = Submission.new(:user => user,
234 :problem => problem,
243 :problem => problem,
235 :source => submitted_solution,
244 :source => submitted_solution,
236 :source_filename => params['file'].original_filename,
245 :source_filename => params['file'].original_filename,
237 :language_id => 0,
246 :language_id => 0,
238 :submitted_at => Time.new.gmtime,
247 :submitted_at => Time.new.gmtime,
239 :graded_at => Time.new.gmtime,
248 :graded_at => Time.new.gmtime,
240 :points => points)
249 :points => points)
241 submission.save
250 submission.save
242 recent_assignment.submitted = true
251 recent_assignment.submitted = true
243 recent_assignment.save
252 recent_assignment.save
244
253
245 status = user.get_submission_status_for(problem)
254 status = user.get_submission_status_for(problem)
246 if status == nil
255 if status == nil
247 status = SubmissionStatus.new :user => user, :problem => problem, :submission_count => 0
256 status = SubmissionStatus.new :user => user, :problem => problem, :submission_count => 0
248 end
257 end
249
258
250 status.submission_count += 1
259 status.submission_count += 1
251 status.passed = passed
260 status.passed = passed
252 status.save
261 status.save
@@ -1,21 +1,26
1 .problem-panel{:id => "problem-panel-#{problem.id}", :style => "#{(problem.id != @current_problem_id) ? "display:none" : ""}"}
1 .problem-panel{:id => "problem-panel-#{problem.id}", :style => "#{(problem.id != @current_problem_id) ? "display:none" : ""}"}
2 + - if (not Configuration.time_limit_mode?) or (not @user.contest_finished?)
2 .problem-form{:id => "problem-form-#{problem.id}"}
3 .problem-form{:id => "problem-form-#{problem.id}"}
3 - form_tag({ :action => 'download_input', :id => problem.id }, :method => :post) do
4 - form_tag({ :action => 'download_input', :id => problem.id }, :method => :post) do
4 %b Input:
5 %b Input:
5 %input{:type => "submit", :value => "Download input", :onclick => "CodejomTimeout.updateTimeoutAfterDownloadClick(#{problem.id}); return true;"}
6 %input{:type => "submit", :value => "Download input", :onclick => "CodejomTimeout.updateTimeoutAfterDownloadClick(#{problem.id}); return true;"}
6 %span{:id => "problem-timing-message-#{problem.id}"}
7 %span{:id => "problem-timing-message-#{problem.id}"}
7 = "After downloading, you have #{TEST_ASSIGNMENT_EXPIRATION_DURATION/60} minutes to submit."
8 = "After downloading, you have #{TEST_ASSIGNMENT_EXPIRATION_DURATION/60} minutes to submit."
8 %div{:id => "problem-submission-form-#{problem.id}"}
9 %div{:id => "problem-submission-form-#{problem.id}"}
9 - form_tag({ :action => 'submit_solution', :id => problem.id }, :method => :post, :multipart => true) do
10 - form_tag({ :action => 'submit_solution', :id => problem.id }, :method => :post, :multipart => true) do
10 %b Submit output:
11 %b Submit output:
11 %input{:type => "file", :name => "file"}
12 %input{:type => "file", :name => "file"}
12 %input{:type => "submit", :value => "Submit solution"}
13 %input{:type => "submit", :value => "Submit solution"}
14 + - else
15 + .problem-form
16 + %p
17 + The contest is over, you can view the tasks, but you can no longer submit.
13
18
14 .problem-description
19 .problem-description
15 - if problem.description!=nil
20 - if problem.description!=nil
16 - if problem.description.markdowned
21 - if problem.description.markdowned
17 ~ markdown(problem.description.body)
22 ~ markdown(problem.description.body)
18 - else
23 - else
19 = problem.description.body
24 = problem.description.body
20 - else
25 - else
21 (not available)
26 (not available)
@@ -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 => 20100126170609) do
12 + ActiveRecord::Schema.define(:version => 20100129041917) 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 "codejom_statuses", :force => true do |t|
25 create_table "codejom_statuses", :force => true do |t|
26 t.integer "user_id"
26 t.integer "user_id"
27 t.boolean "alive"
27 t.boolean "alive"
28 t.integer "num_problems_passed"
28 t.integer "num_problems_passed"
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 "configurations", :force => true do |t|
33 create_table "configurations", :force => true do |t|
34 t.string "key"
34 t.string "key"
35 t.string "value_type"
35 t.string "value_type"
36 t.string "value"
36 t.string "value"
37 t.datetime "created_at"
37 t.datetime "created_at"
38 t.datetime "updated_at"
38 t.datetime "updated_at"
39 t.text "description"
39 t.text "description"
40 end
40 end
41
41
42 create_table "countries", :force => true do |t|
42 create_table "countries", :force => true do |t|
43 t.string "name"
43 t.string "name"
44 t.datetime "created_at"
44 t.datetime "created_at"
45 t.datetime "updated_at"
45 t.datetime "updated_at"
46 end
46 end
47
47
48 create_table "descriptions", :force => true do |t|
48 create_table "descriptions", :force => true do |t|
49 t.text "body"
49 t.text "body"
50 t.boolean "markdowned"
50 t.boolean "markdowned"
51 t.datetime "created_at"
51 t.datetime "created_at"
52 t.datetime "updated_at"
52 t.datetime "updated_at"
53 end
53 end
54
54
55 create_table "grader_processes", :force => true do |t|
55 create_table "grader_processes", :force => true do |t|
56 t.string "host", :limit => 20
56 t.string "host", :limit => 20
57 t.integer "pid"
57 t.integer "pid"
58 t.string "mode"
58 t.string "mode"
59 t.boolean "active"
59 t.boolean "active"
60 t.datetime "created_at"
60 t.datetime "created_at"
@@ -141,98 +141,98
141 create_table "submission_statuses", :force => true do |t|
141 create_table "submission_statuses", :force => true do |t|
142 t.integer "user_id"
142 t.integer "user_id"
143 t.integer "problem_id"
143 t.integer "problem_id"
144 t.boolean "passed"
144 t.boolean "passed"
145 t.integer "submission_count"
145 t.integer "submission_count"
146 t.datetime "created_at"
146 t.datetime "created_at"
147 t.datetime "updated_at"
147 t.datetime "updated_at"
148 end
148 end
149
149
150 create_table "submissions", :force => true do |t|
150 create_table "submissions", :force => true do |t|
151 t.integer "user_id"
151 t.integer "user_id"
152 t.integer "problem_id"
152 t.integer "problem_id"
153 t.integer "language_id"
153 t.integer "language_id"
154 t.text "source"
154 t.text "source"
155 t.binary "binary"
155 t.binary "binary"
156 t.datetime "submitted_at"
156 t.datetime "submitted_at"
157 t.datetime "compiled_at"
157 t.datetime "compiled_at"
158 t.text "compiler_message"
158 t.text "compiler_message"
159 t.datetime "graded_at"
159 t.datetime "graded_at"
160 t.integer "points"
160 t.integer "points"
161 t.text "grader_comment"
161 t.text "grader_comment"
162 t.integer "number"
162 t.integer "number"
163 t.string "source_filename"
163 t.string "source_filename"
164 end
164 end
165
165
166 add_index "submissions", ["user_id", "problem_id", "number"], :name => "index_submissions_on_user_id_and_problem_id_and_number", :unique => true
166 add_index "submissions", ["user_id", "problem_id", "number"], :name => "index_submissions_on_user_id_and_problem_id_and_number", :unique => true
167 add_index "submissions", ["user_id", "problem_id"], :name => "index_submissions_on_user_id_and_problem_id"
167 add_index "submissions", ["user_id", "problem_id"], :name => "index_submissions_on_user_id_and_problem_id"
168
168
169 create_table "tasks", :force => true do |t|
169 create_table "tasks", :force => true do |t|
170 t.integer "submission_id"
170 t.integer "submission_id"
171 t.datetime "created_at"
171 t.datetime "created_at"
172 t.integer "status"
172 t.integer "status"
173 t.datetime "updated_at"
173 t.datetime "updated_at"
174 end
174 end
175
175
176 create_table "test_pair_assignments", :force => true do |t|
176 create_table "test_pair_assignments", :force => true do |t|
177 t.integer "user_id"
177 t.integer "user_id"
178 t.integer "problem_id"
178 t.integer "problem_id"
179 t.integer "test_pair_id"
179 t.integer "test_pair_id"
180 t.integer "test_pair_number"
180 t.integer "test_pair_number"
181 t.integer "request_number"
181 t.integer "request_number"
182 t.datetime "created_at"
182 t.datetime "created_at"
183 t.datetime "updated_at"
183 t.datetime "updated_at"
184 t.boolean "submitted"
184 t.boolean "submitted"
185 end
185 end
186
186
187 create_table "test_pairs", :force => true do |t|
187 create_table "test_pairs", :force => true do |t|
188 t.integer "problem_id"
188 t.integer "problem_id"
189 - t.text "input"
189 + t.text "input", :limit => 16777215
190 - t.text "solution"
190 + t.text "solution", :limit => 16777215
191 t.datetime "created_at"
191 t.datetime "created_at"
192 t.datetime "updated_at"
192 t.datetime "updated_at"
193 t.integer "number"
193 t.integer "number"
194 end
194 end
195
195
196 create_table "test_requests", :force => true do |t|
196 create_table "test_requests", :force => true do |t|
197 t.integer "user_id"
197 t.integer "user_id"
198 t.integer "problem_id"
198 t.integer "problem_id"
199 t.integer "submission_id"
199 t.integer "submission_id"
200 t.string "input_file_name"
200 t.string "input_file_name"
201 t.string "output_file_name"
201 t.string "output_file_name"
202 t.string "running_stat"
202 t.string "running_stat"
203 t.integer "status"
203 t.integer "status"
204 t.datetime "updated_at"
204 t.datetime "updated_at"
205 t.datetime "submitted_at"
205 t.datetime "submitted_at"
206 t.datetime "compiled_at"
206 t.datetime "compiled_at"
207 t.text "compiler_message"
207 t.text "compiler_message"
208 t.datetime "graded_at"
208 t.datetime "graded_at"
209 t.string "grader_comment"
209 t.string "grader_comment"
210 t.datetime "created_at"
210 t.datetime "created_at"
211 t.float "running_time"
211 t.float "running_time"
212 t.string "exit_status"
212 t.string "exit_status"
213 t.integer "memory_usage"
213 t.integer "memory_usage"
214 end
214 end
215
215
216 add_index "test_requests", ["user_id", "problem_id"], :name => "index_test_requests_on_user_id_and_problem_id"
216 add_index "test_requests", ["user_id", "problem_id"], :name => "index_test_requests_on_user_id_and_problem_id"
217
217
218 create_table "user_contest_stats", :force => true do |t|
218 create_table "user_contest_stats", :force => true do |t|
219 t.integer "user_id"
219 t.integer "user_id"
220 t.datetime "started_at"
220 t.datetime "started_at"
221 t.datetime "created_at"
221 t.datetime "created_at"
222 t.datetime "updated_at"
222 t.datetime "updated_at"
223 end
223 end
224
224
225 create_table "users", :force => true do |t|
225 create_table "users", :force => true do |t|
226 t.string "login", :limit => 50
226 t.string "login", :limit => 50
227 t.string "full_name"
227 t.string "full_name"
228 t.string "hashed_password"
228 t.string "hashed_password"
229 t.string "salt", :limit => 5
229 t.string "salt", :limit => 5
230 t.string "alias"
230 t.string "alias"
231 t.string "email"
231 t.string "email"
232 t.integer "site_id"
232 t.integer "site_id"
233 t.integer "country_id"
233 t.integer "country_id"
234 t.boolean "activated", :default => false
234 t.boolean "activated", :default => false
235 t.datetime "created_at"
235 t.datetime "created_at"
236 t.datetime "updated_at"
236 t.datetime "updated_at"
237 t.string "member1_full_name"
237 t.string "member1_full_name"
238 t.string "member2_full_name"
238 t.string "member2_full_name"
You need to be logged in to leave comments. Login now