Description:
saves and grades submission in standard mode
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r388:b5766b7ed3ec - - 2 files changed: 18 inserted, 6 deleted
@@ -1,199 +1,207 | |||||
|
1 | # coding: utf-8 |
|
1 | # coding: utf-8 |
|
2 | class MainController < ApplicationController |
|
2 | class MainController < ApplicationController |
|
3 |
|
3 | ||
|
4 | before_filter :authenticate, :except => [:index, :login] |
|
4 | before_filter :authenticate, :except => [:index, :login] |
|
5 | before_filter :check_viewability, :except => [:index, :login] |
|
5 | before_filter :check_viewability, :except => [:index, :login] |
|
6 |
|
6 | ||
|
7 | append_before_filter :confirm_and_update_start_time, |
|
7 | append_before_filter :confirm_and_update_start_time, |
|
8 | :except => [:index, |
|
8 | :except => [:index, |
|
9 | :login, |
|
9 | :login, |
|
10 | :confirm_contest_start] |
|
10 | :confirm_contest_start] |
|
11 |
|
11 | ||
|
12 | # to prevent log in box to be shown when user logged out of the |
|
12 | # to prevent log in box to be shown when user logged out of the |
|
13 | # system only in some tab |
|
13 | # system only in some tab |
|
14 | prepend_before_filter :reject_announcement_refresh_when_logged_out, |
|
14 | prepend_before_filter :reject_announcement_refresh_when_logged_out, |
|
15 | :only => [:announcements] |
|
15 | :only => [:announcements] |
|
16 |
|
16 | ||
|
17 | # COMMENTED OUT: filter in each action instead |
|
17 | # COMMENTED OUT: filter in each action instead |
|
18 | # before_filter :verify_time_limit, :only => [:submit] |
|
18 | # before_filter :verify_time_limit, :only => [:submit] |
|
19 |
|
19 | ||
|
20 | verify :method => :post, :only => [:submit], |
|
20 | verify :method => :post, :only => [:submit], |
|
21 | :redirect_to => { :action => :index } |
|
21 | :redirect_to => { :action => :index } |
|
22 |
|
22 | ||
|
23 | # COMMENT OUT: only need when having high load |
|
23 | # COMMENT OUT: only need when having high load |
|
24 | # caches_action :index, :login |
|
24 | # caches_action :index, :login |
|
25 |
|
25 | ||
|
26 | # NOTE: This method is not actually needed, 'config/routes.rb' has |
|
26 | # NOTE: This method is not actually needed, 'config/routes.rb' has |
|
27 | # assigned action login as a default action. |
|
27 | # assigned action login as a default action. |
|
28 | def index |
|
28 | def index |
|
29 | redirect_to :action => 'login' |
|
29 | redirect_to :action => 'login' |
|
30 | end |
|
30 | end |
|
31 |
|
31 | ||
|
32 | def login |
|
32 | def login |
|
33 | saved_notice = flash[:notice] |
|
33 | saved_notice = flash[:notice] |
|
34 | reset_session |
|
34 | reset_session |
|
35 | flash.now[:notice] = saved_notice |
|
35 | flash.now[:notice] = saved_notice |
|
36 |
|
36 | ||
|
37 | # EXPERIMENT: |
|
37 | # EXPERIMENT: |
|
38 | # Hide login if in single user mode and the url does not |
|
38 | # Hide login if in single user mode and the url does not |
|
39 | # explicitly specify /login |
|
39 | # explicitly specify /login |
|
40 | # |
|
40 | # |
|
41 | # logger.info "PATH: #{request.path}" |
|
41 | # logger.info "PATH: #{request.path}" |
|
42 | # if GraderConfiguration['system.single_user_mode'] and |
|
42 | # if GraderConfiguration['system.single_user_mode'] and |
|
43 | # request.path!='/main/login' |
|
43 | # request.path!='/main/login' |
|
44 | # @hidelogin = true |
|
44 | # @hidelogin = true |
|
45 | # end |
|
45 | # end |
|
46 |
|
46 | ||
|
47 | @announcements = Announcement.find_for_frontpage |
|
47 | @announcements = Announcement.find_for_frontpage |
|
48 | render :action => 'login', :layout => 'empty' |
|
48 | render :action => 'login', :layout => 'empty' |
|
49 | end |
|
49 | end |
|
50 |
|
50 | ||
|
51 | def list |
|
51 | def list |
|
52 | if session[:current_problem_id] |
|
52 | if session[:current_problem_id] |
|
53 | @current_problem = Problem.find(session[:current_problem_id]) |
|
53 | @current_problem = Problem.find(session[:current_problem_id]) |
|
54 | session[:current_problem_id] = nil |
|
54 | session[:current_problem_id] = nil |
|
55 | end |
|
55 | end |
|
56 | prepare_list_information |
|
56 | prepare_list_information |
|
57 | end |
|
57 | end |
|
58 |
|
58 | ||
|
59 | def help |
|
59 | def help |
|
60 | @user = User.find(session[:user_id]) |
|
60 | @user = User.find(session[:user_id]) |
|
61 | end |
|
61 | end |
|
62 |
|
62 | ||
|
63 | def submit |
|
63 | def submit |
|
64 | user = User.find(session[:user_id]) |
|
64 | user = User.find(session[:user_id]) |
|
65 |
|
65 | ||
|
66 | @submission = Submission.new |
|
66 | @submission = Submission.new |
|
67 | @current_problem = Problem.find(params[:submission][:problem_id]) |
|
67 | @current_problem = Problem.find(params[:submission][:problem_id]) |
|
68 |
|
68 | ||
|
69 | if !@current_problem |
|
69 | if !@current_problem |
|
70 | flash[:notice] = 'Error: คุณยังไม่ได้ระบุข้อที่ต้องการส่ง' |
|
70 | flash[:notice] = 'Error: คุณยังไม่ได้ระบุข้อที่ต้องการส่ง' |
|
71 | redirect_to :action => 'list' |
|
71 | redirect_to :action => 'list' |
|
72 | end |
|
72 | end |
|
73 |
|
73 | ||
|
74 | assignment = user.get_test_pair_assignment_for(@current_problem) |
|
74 | assignment = user.get_test_pair_assignment_for(@current_problem) |
|
75 | if !assignment |
|
75 | if !assignment |
|
76 | flash[:notice] = 'Error: คุณยังไม่ได้ดาวน์โหลดข้อมูลทดสอบ' |
|
76 | flash[:notice] = 'Error: คุณยังไม่ได้ดาวน์โหลดข้อมูลทดสอบ' |
|
77 | prepare_list_information |
|
77 | prepare_list_information |
|
78 | render :action => 'list' and return |
|
78 | render :action => 'list' and return |
|
79 | end |
|
79 | end |
|
80 | - if assignment.expired? |
|
80 | + if (assignment.expired?) and (!GraderConfiguration.standard_mode?) |
|
81 | flash[:notice] = 'Error: หมดเวลาส่งสำหรับข้อนี้' |
|
81 | flash[:notice] = 'Error: หมดเวลาส่งสำหรับข้อนี้' |
|
82 | prepare_list_information |
|
82 | prepare_list_information |
|
83 | render :action => 'list' and return |
|
83 | render :action => 'list' and return |
|
84 | end |
|
84 | end |
|
85 |
|
85 | ||
|
86 | @submission.problem = @current_problem |
|
86 | @submission.problem = @current_problem |
|
87 | @submission.user = user |
|
87 | @submission.user = user |
|
88 | @submission.language_id = 0 |
|
88 | @submission.language_id = 0 |
|
89 | if (params['file']) and (params['file']!='') |
|
89 | if (params['file']) and (params['file']!='') |
|
90 | @submission.source = params['file'].read |
|
90 | @submission.source = params['file'].read |
|
91 | @submission.source_filename = params['file'].original_filename |
|
91 | @submission.source_filename = params['file'].original_filename |
|
92 | end |
|
92 | end |
|
93 | if (params['output_file']) and (params['output_file']!='') |
|
93 | if (params['output_file']) and (params['output_file']!='') |
|
94 | @submission.output = params['output_file'].read |
|
94 | @submission.output = params['output_file'].read |
|
95 | end |
|
95 | end |
|
96 | @submission.submitted_at = Time.new.gmtime |
|
96 | @submission.submitted_at = Time.new.gmtime |
|
97 |
|
97 | ||
|
98 | if GraderConfiguration.time_limit_mode? and user.contest_finished? |
|
98 | if GraderConfiguration.time_limit_mode? and user.contest_finished? |
|
99 | @submission.errors.add(:base,"The contest is over.") |
|
99 | @submission.errors.add(:base,"The contest is over.") |
|
100 | prepare_list_information |
|
100 | prepare_list_information |
|
101 | render :action => 'list' and return |
|
101 | render :action => 'list' and return |
|
102 | end |
|
102 | end |
|
103 |
|
103 | ||
|
|
104 | + if GraderConfiguration.standard_mode? | ||
|
|
105 | + test_pair = assignment.test_pair | ||
|
|
106 | + result = test_pair.grade(@submission.output) | ||
|
|
107 | + @submission.points = result[:score]*100 / result[:full_score] | ||
|
|
108 | + @submission.grader_comment = result[:msg] | ||
|
|
109 | + @submission.graded_at = Time.now.gmtime | ||
|
|
110 | + end | ||
|
|
111 | + | ||
|
104 | if @submission.valid? |
|
112 | if @submission.valid? |
|
105 | if @submission.save == false |
|
113 | if @submission.save == false |
|
106 | flash[:notice] = 'Error saving your submission' |
|
114 | flash[:notice] = 'Error saving your submission' |
|
107 | elsif Task.create(:submission_id => @submission.id, |
|
115 | elsif Task.create(:submission_id => @submission.id, |
|
108 | :status => Task::STATUS_INQUEUE) == false |
|
116 | :status => Task::STATUS_INQUEUE) == false |
|
109 | flash[:notice] = 'Error adding your submission to task queue' |
|
117 | flash[:notice] = 'Error adding your submission to task queue' |
|
110 | else |
|
118 | else |
|
111 | flash[:notice] = 'จัดเก็บคำตอบและโปรแกรมที่คุณส่งเรียบร้อย' |
|
119 | flash[:notice] = 'จัดเก็บคำตอบและโปรแกรมที่คุณส่งเรียบร้อย' |
|
112 | end |
|
120 | end |
|
113 | else |
|
121 | else |
|
114 | prepare_list_information |
|
122 | prepare_list_information |
|
115 | render :action => 'list' and return |
|
123 | render :action => 'list' and return |
|
116 | end |
|
124 | end |
|
117 |
|
125 | ||
|
118 | if @current_problem |
|
126 | if @current_problem |
|
119 | session[:current_problem_id] = @current_problem.id |
|
127 | session[:current_problem_id] = @current_problem.id |
|
120 | end |
|
128 | end |
|
121 | redirect_to :action => 'list' |
|
129 | redirect_to :action => 'list' |
|
122 | end |
|
130 | end |
|
123 |
|
131 | ||
|
124 | def source |
|
132 | def source |
|
125 | submission = Submission.find(params[:id]) |
|
133 | submission = Submission.find(params[:id]) |
|
126 | if ((submission.user_id == session[:user_id]) and |
|
134 | if ((submission.user_id == session[:user_id]) and |
|
127 | (submission.problem != nil) and |
|
135 | (submission.problem != nil) and |
|
128 | (submission.problem.available)) |
|
136 | (submission.problem.available)) |
|
129 | send_data(submission.source, |
|
137 | send_data(submission.source, |
|
130 | {:filename => submission.download_filename, |
|
138 | {:filename => submission.download_filename, |
|
131 | :type => 'text/plain'}) |
|
139 | :type => 'text/plain'}) |
|
132 | else |
|
140 | else |
|
133 | flash[:notice] = 'Error viewing source' |
|
141 | flash[:notice] = 'Error viewing source' |
|
134 | redirect_to :action => 'list' |
|
142 | redirect_to :action => 'list' |
|
135 | end |
|
143 | end |
|
136 | end |
|
144 | end |
|
137 |
|
145 | ||
|
138 | def compiler_msg |
|
146 | def compiler_msg |
|
139 | @submission = Submission.find(params[:id]) |
|
147 | @submission = Submission.find(params[:id]) |
|
140 | if @submission.user_id == session[:user_id] |
|
148 | if @submission.user_id == session[:user_id] |
|
141 | render :action => 'compiler_msg', :layout => 'empty' |
|
149 | render :action => 'compiler_msg', :layout => 'empty' |
|
142 | else |
|
150 | else |
|
143 | flash[:notice] = 'Error viewing source' |
|
151 | flash[:notice] = 'Error viewing source' |
|
144 | redirect_to :action => 'list' |
|
152 | redirect_to :action => 'list' |
|
145 | end |
|
153 | end |
|
146 | end |
|
154 | end |
|
147 |
|
155 | ||
|
148 | def submission |
|
156 | def submission |
|
149 | @user = User.find(session[:user_id]) |
|
157 | @user = User.find(session[:user_id]) |
|
150 | @problems = @user.available_problems |
|
158 | @problems = @user.available_problems |
|
151 | if params[:id]==nil |
|
159 | if params[:id]==nil |
|
152 | @problem = nil |
|
160 | @problem = nil |
|
153 | @submissions = nil |
|
161 | @submissions = nil |
|
154 | else |
|
162 | else |
|
155 | @problem = Problem.find_by_name(params[:id]) |
|
163 | @problem = Problem.find_by_name(params[:id]) |
|
156 | if not @problem.available |
|
164 | if not @problem.available |
|
157 | redirect_to :action => 'list' |
|
165 | redirect_to :action => 'list' |
|
158 | flash[:notice] = 'Error: submissions for that problem are not viewable.' |
|
166 | flash[:notice] = 'Error: submissions for that problem are not viewable.' |
|
159 | return |
|
167 | return |
|
160 | end |
|
168 | end |
|
161 | @submissions = Submission.find_all_by_user_problem(@user.id, @problem.id) |
|
169 | @submissions = Submission.find_all_by_user_problem(@user.id, @problem.id) |
|
162 | end |
|
170 | end |
|
163 | end |
|
171 | end |
|
164 |
|
172 | ||
|
165 | def result |
|
173 | def result |
|
166 | if !GraderConfiguration.show_grading_result |
|
174 | if !GraderConfiguration.show_grading_result |
|
167 | redirect_to :action => 'list' and return |
|
175 | redirect_to :action => 'list' and return |
|
168 | end |
|
176 | end |
|
169 | @user = User.find(session[:user_id]) |
|
177 | @user = User.find(session[:user_id]) |
|
170 | @submission = Submission.find(params[:id]) |
|
178 | @submission = Submission.find(params[:id]) |
|
171 | if @submission.user!=@user |
|
179 | if @submission.user!=@user |
|
172 | flash[:notice] = 'You are not allowed to view result of other users.' |
|
180 | flash[:notice] = 'You are not allowed to view result of other users.' |
|
173 | redirect_to :action => 'list' and return |
|
181 | redirect_to :action => 'list' and return |
|
174 | end |
|
182 | end |
|
175 | prepare_grading_result(@submission) |
|
183 | prepare_grading_result(@submission) |
|
176 | end |
|
184 | end |
|
177 |
|
185 | ||
|
178 | def load_output |
|
186 | def load_output |
|
179 | if !GraderConfiguration.show_grading_result or params[:num]==nil |
|
187 | if !GraderConfiguration.show_grading_result or params[:num]==nil |
|
180 | redirect_to :action => 'list' and return |
|
188 | redirect_to :action => 'list' and return |
|
181 | end |
|
189 | end |
|
182 | @user = User.find(session[:user_id]) |
|
190 | @user = User.find(session[:user_id]) |
|
183 | @submission = Submission.find(params[:id]) |
|
191 | @submission = Submission.find(params[:id]) |
|
184 | if @submission.user!=@user |
|
192 | if @submission.user!=@user |
|
185 | flash[:notice] = 'You are not allowed to view result of other users.' |
|
193 | flash[:notice] = 'You are not allowed to view result of other users.' |
|
186 | redirect_to :action => 'list' and return |
|
194 | redirect_to :action => 'list' and return |
|
187 | end |
|
195 | end |
|
188 | case_num = params[:num].to_i |
|
196 | case_num = params[:num].to_i |
|
189 | out_filename = output_filename(@user.login, |
|
197 | out_filename = output_filename(@user.login, |
|
190 | @submission.problem.name, |
|
198 | @submission.problem.name, |
|
191 | @submission.id, |
|
199 | @submission.id, |
|
192 | case_num) |
|
200 | case_num) |
|
193 | if !FileTest.exists?(out_filename) |
|
201 | if !FileTest.exists?(out_filename) |
|
194 | flash[:notice] = 'Output not found.' |
|
202 | flash[:notice] = 'Output not found.' |
|
195 | redirect_to :action => 'list' and return |
|
203 | redirect_to :action => 'list' and return |
|
196 | end |
|
204 | end |
|
197 |
|
205 | ||
|
198 | if defined?(USE_APACHE_XSENDFILE) and USE_APACHE_XSENDFILE |
|
206 | if defined?(USE_APACHE_XSENDFILE) and USE_APACHE_XSENDFILE |
|
199 | response.headers['Content-Type'] = "application/force-download" |
|
207 | response.headers['Content-Type'] = "application/force-download" |
@@ -221,199 +229,203 | |||||
|
221 | render(:partial => 'announcement', |
|
229 | render(:partial => 'announcement', |
|
222 | :collection => @announcements, |
|
230 | :collection => @announcements, |
|
223 | :locals => {:announcement_effect => true}) |
|
231 | :locals => {:announcement_effect => true}) |
|
224 | end |
|
232 | end |
|
225 |
|
233 | ||
|
226 | def confirm_contest_start |
|
234 | def confirm_contest_start |
|
227 | user = User.find(session[:user_id]) |
|
235 | user = User.find(session[:user_id]) |
|
228 | if request.method == 'POST' |
|
236 | if request.method == 'POST' |
|
229 | user.update_start_time |
|
237 | user.update_start_time |
|
230 | redirect_to :action => 'list' |
|
238 | redirect_to :action => 'list' |
|
231 | else |
|
239 | else |
|
232 | @contests = user.contests |
|
240 | @contests = user.contests |
|
233 | @user = user |
|
241 | @user = user |
|
234 | end |
|
242 | end |
|
235 | end |
|
243 | end |
|
236 |
|
244 | ||
|
237 | # thailandoi contests |
|
245 | # thailandoi contests |
|
238 |
|
246 | ||
|
239 | def verifying_testcase |
|
247 | def verifying_testcase |
|
240 | problem = Problem.find(params[:id]) |
|
248 | problem = Problem.find(params[:id]) |
|
241 | if !problem.available |
|
249 | if !problem.available |
|
242 | flash[:notice] = 'Error: problem is not available' |
|
250 | flash[:notice] = 'Error: problem is not available' |
|
243 | redirect_to :action => 'list' |
|
251 | redirect_to :action => 'list' |
|
244 | else |
|
252 | else |
|
245 | test_pair = TestPair.get_for(problem, false) |
|
253 | test_pair = TestPair.get_for(problem, false) |
|
246 | send_data(test_pair.input, |
|
254 | send_data(test_pair.input, |
|
247 | {:filename => problem.name + '-verifying-input.txt', |
|
255 | {:filename => problem.name + '-verifying-input.txt', |
|
248 | :type => 'text/plain'}) |
|
256 | :type => 'text/plain'}) |
|
249 | end |
|
257 | end |
|
250 | end |
|
258 | end |
|
251 |
|
259 | ||
|
252 | def testcase |
|
260 | def testcase |
|
253 | problem = Problem.find(params[:id]) |
|
261 | problem = Problem.find(params[:id]) |
|
254 | if !problem.available |
|
262 | if !problem.available |
|
255 | flash[:notice] = 'Error: problem is not available' |
|
263 | flash[:notice] = 'Error: problem is not available' |
|
256 | redirect_to :action => 'list' |
|
264 | redirect_to :action => 'list' |
|
257 | else |
|
265 | else |
|
258 | test_pair = TestPair.get_for(problem, true) |
|
266 | test_pair = TestPair.get_for(problem, true) |
|
259 |
|
267 | ||
|
260 | user = User.find(session[:user_id]) |
|
268 | user = User.find(session[:user_id]) |
|
261 | assignment = user.get_test_pair_assignment_for(problem) |
|
269 | assignment = user.get_test_pair_assignment_for(problem) |
|
262 |
|
270 | ||
|
263 | if !assignment |
|
271 | if !assignment |
|
264 | assignment = TestPairAssignment.create_for(user, problem, test_pair) |
|
272 | assignment = TestPairAssignment.create_for(user, problem, test_pair) |
|
265 | assignment.save |
|
273 | assignment.save |
|
266 | end |
|
274 | end |
|
267 |
|
275 | ||
|
268 | send_data(test_pair.input, |
|
276 | send_data(test_pair.input, |
|
269 | {:filename => problem.name + '-input.txt', |
|
277 | {:filename => problem.name + '-input.txt', |
|
270 | :type => 'text/plain'}) |
|
278 | :type => 'text/plain'}) |
|
271 | end |
|
279 | end |
|
272 | end |
|
280 | end |
|
273 |
|
281 | ||
|
274 | def verifying_submit |
|
282 | def verifying_submit |
|
275 | user = User.find(session[:user_id]) |
|
283 | user = User.find(session[:user_id]) |
|
276 | problem_id = params[:id] |
|
284 | problem_id = params[:id] |
|
277 | problem = Problem.find(problem_id) |
|
285 | problem = Problem.find(problem_id) |
|
278 |
|
286 | ||
|
279 | if !problem or !problem.available |
|
287 | if !problem or !problem.available |
|
280 | flash[:notice] = 'Error: problem is not available' |
|
288 | flash[:notice] = 'Error: problem is not available' |
|
281 | redirect_to :action => 'list' and return |
|
289 | redirect_to :action => 'list' and return |
|
282 | end |
|
290 | end |
|
283 |
|
291 | ||
|
284 | @current_problem = problem |
|
292 | @current_problem = problem |
|
285 | test_pair = TestPair.get_for(problem, false) |
|
293 | test_pair = TestPair.get_for(problem, false) |
|
286 | if (params['output_file']) and (params['output_file']!='') |
|
294 | if (params['output_file']) and (params['output_file']!='') |
|
287 | output = params['output_file'].read |
|
295 | output = params['output_file'].read |
|
288 |
|
296 | ||
|
289 | @grading_result = test_pair.grade(output) |
|
297 | @grading_result = test_pair.grade(output) |
|
290 | prepare_list_information |
|
298 | prepare_list_information |
|
291 | render :action => 'list' and return |
|
299 | render :action => 'list' and return |
|
292 | else |
|
300 | else |
|
293 | flash[:notice] = 'Error: output file errors' |
|
301 | flash[:notice] = 'Error: output file errors' |
|
294 | prepare_list_information |
|
302 | prepare_list_information |
|
295 | render :action => 'list' and return |
|
303 | render :action => 'list' and return |
|
296 | end |
|
304 | end |
|
297 | end |
|
305 | end |
|
298 |
|
306 | ||
|
299 | protected |
|
307 | protected |
|
300 |
|
308 | ||
|
301 | def prepare_announcements(recent=nil) |
|
309 | def prepare_announcements(recent=nil) |
|
302 | if GraderConfiguration.show_tasks_to?(@user) |
|
310 | if GraderConfiguration.show_tasks_to?(@user) |
|
303 | @announcements = Announcement.find_published(true) |
|
311 | @announcements = Announcement.find_published(true) |
|
304 | else |
|
312 | else |
|
305 | @announcements = Announcement.find_published |
|
313 | @announcements = Announcement.find_published |
|
306 | end |
|
314 | end |
|
307 | if recent!=nil |
|
315 | if recent!=nil |
|
308 | recent_id = recent.to_i |
|
316 | recent_id = recent.to_i |
|
309 | @announcements = @announcements.find_all { |a| a.id > recent_id } |
|
317 | @announcements = @announcements.find_all { |a| a.id > recent_id } |
|
310 | end |
|
318 | end |
|
311 | end |
|
319 | end |
|
312 |
|
320 | ||
|
313 | def prepare_timeout_information(problems) |
|
321 | def prepare_timeout_information(problems) |
|
314 | @submission_timeouts = {} |
|
322 | @submission_timeouts = {} |
|
315 | problems.each do |problem| |
|
323 | problems.each do |problem| |
|
316 | assignment = @user.get_test_pair_assignment_for(problem) |
|
324 | assignment = @user.get_test_pair_assignment_for(problem) |
|
317 | - if assignment == nil |
|
325 | + if GraderConfiguration.standard_mode? |
|
318 | timeout = nil |
|
326 | timeout = nil |
|
319 | else |
|
327 | else |
|
320 | - if (assignment.expired?) or (assignment.submitted) |
|
328 | + if assignment == nil |
|
321 |
- timeout = |
|
329 | + timeout = nil |
|
322 | else |
|
330 | else |
|
323 | - timeout = assignment.created_at + TEST_ASSIGNMENT_EXPIRATION_DURATION - Time.new.gmtime |
|
331 | + if (assignment.expired?) or (assignment.submitted) |
|
|
332 | + timeout = 0 | ||
|
|
333 | + else | ||
|
|
334 | + timeout = assignment.created_at + TEST_ASSIGNMENT_EXPIRATION_DURATION - Time.new.gmtime | ||
|
|
335 | + end | ||
|
324 | end |
|
336 | end |
|
325 | end |
|
337 | end |
|
326 | @submission_timeouts[problem.id] = timeout |
|
338 | @submission_timeouts[problem.id] = timeout |
|
327 | end |
|
339 | end |
|
328 | end |
|
340 | end |
|
329 |
|
341 | ||
|
330 | def prepare_list_information |
|
342 | def prepare_list_information |
|
331 | @user = User.find(session[:user_id]) |
|
343 | @user = User.find(session[:user_id]) |
|
332 | if not GraderConfiguration.multicontests? |
|
344 | if not GraderConfiguration.multicontests? |
|
333 | @problems = @user.available_problems |
|
345 | @problems = @user.available_problems |
|
334 | else |
|
346 | else |
|
335 | @contest_problems = @user.available_problems_group_by_contests |
|
347 | @contest_problems = @user.available_problems_group_by_contests |
|
336 | @problems = @user.available_problems |
|
348 | @problems = @user.available_problems |
|
337 | end |
|
349 | end |
|
338 | @prob_submissions = {} |
|
350 | @prob_submissions = {} |
|
339 | @problems.each do |p| |
|
351 | @problems.each do |p| |
|
340 | sub = Submission.find_last_by_user_and_problem(@user.id,p.id) |
|
352 | sub = Submission.find_last_by_user_and_problem(@user.id,p.id) |
|
341 | if sub!=nil |
|
353 | if sub!=nil |
|
342 | @prob_submissions[p.id] = { :count => sub.number, :submission => sub } |
|
354 | @prob_submissions[p.id] = { :count => sub.number, :submission => sub } |
|
343 | else |
|
355 | else |
|
344 | @prob_submissions[p.id] = { :count => 0, :submission => nil } |
|
356 | @prob_submissions[p.id] = { :count => 0, :submission => nil } |
|
345 | end |
|
357 | end |
|
346 | end |
|
358 | end |
|
347 | prepare_announcements |
|
359 | prepare_announcements |
|
348 | prepare_timeout_information(@problems) |
|
360 | prepare_timeout_information(@problems) |
|
349 | end |
|
361 | end |
|
350 |
|
362 | ||
|
351 | def check_viewability |
|
363 | def check_viewability |
|
352 | @user = User.find(session[:user_id]) |
|
364 | @user = User.find(session[:user_id]) |
|
353 | if (!GraderConfiguration.show_tasks_to?(@user)) and |
|
365 | if (!GraderConfiguration.show_tasks_to?(@user)) and |
|
354 | ((action_name=='submission') or (action_name=='submit')) |
|
366 | ((action_name=='submission') or (action_name=='submit')) |
|
355 | redirect_to :action => 'list' and return |
|
367 | redirect_to :action => 'list' and return |
|
356 | end |
|
368 | end |
|
357 | end |
|
369 | end |
|
358 |
|
370 | ||
|
359 | def prepare_grading_result(submission) |
|
371 | def prepare_grading_result(submission) |
|
360 | if GraderConfiguration.task_grading_info.has_key? submission.problem.name |
|
372 | if GraderConfiguration.task_grading_info.has_key? submission.problem.name |
|
361 | grading_info = GraderConfiguration.task_grading_info[submission.problem.name] |
|
373 | grading_info = GraderConfiguration.task_grading_info[submission.problem.name] |
|
362 | else |
|
374 | else |
|
363 | # guess task info from problem.full_score |
|
375 | # guess task info from problem.full_score |
|
364 | cases = submission.problem.full_score / 10 |
|
376 | cases = submission.problem.full_score / 10 |
|
365 | grading_info = { |
|
377 | grading_info = { |
|
366 | 'testruns' => cases, |
|
378 | 'testruns' => cases, |
|
367 | 'testcases' => cases |
|
379 | 'testcases' => cases |
|
368 | } |
|
380 | } |
|
369 | end |
|
381 | end |
|
370 | @test_runs = [] |
|
382 | @test_runs = [] |
|
371 | if grading_info['testruns'].is_a? Integer |
|
383 | if grading_info['testruns'].is_a? Integer |
|
372 | trun_count = grading_info['testruns'] |
|
384 | trun_count = grading_info['testruns'] |
|
373 | trun_count.times do |i| |
|
385 | trun_count.times do |i| |
|
374 | @test_runs << [ read_grading_result(@user.login, |
|
386 | @test_runs << [ read_grading_result(@user.login, |
|
375 | submission.problem.name, |
|
387 | submission.problem.name, |
|
376 | submission.id, |
|
388 | submission.id, |
|
377 | i+1) ] |
|
389 | i+1) ] |
|
378 | end |
|
390 | end |
|
379 | else |
|
391 | else |
|
380 | grading_info['testruns'].keys.sort.each do |num| |
|
392 | grading_info['testruns'].keys.sort.each do |num| |
|
381 | run = [] |
|
393 | run = [] |
|
382 | testrun = grading_info['testruns'][num] |
|
394 | testrun = grading_info['testruns'][num] |
|
383 | testrun.each do |c| |
|
395 | testrun.each do |c| |
|
384 | run << read_grading_result(@user.login, |
|
396 | run << read_grading_result(@user.login, |
|
385 | submission.problem.name, |
|
397 | submission.problem.name, |
|
386 | submission.id, |
|
398 | submission.id, |
|
387 | c) |
|
399 | c) |
|
388 | end |
|
400 | end |
|
389 | @test_runs << run |
|
401 | @test_runs << run |
|
390 | end |
|
402 | end |
|
391 | end |
|
403 | end |
|
392 | end |
|
404 | end |
|
393 |
|
405 | ||
|
394 | def grading_result_dir(user_name, problem_name, submission_id, case_num) |
|
406 | def grading_result_dir(user_name, problem_name, submission_id, case_num) |
|
395 | return "#{GRADING_RESULT_DIR}/#{user_name}/#{problem_name}/#{submission_id}/test-result/#{case_num}" |
|
407 | return "#{GRADING_RESULT_DIR}/#{user_name}/#{problem_name}/#{submission_id}/test-result/#{case_num}" |
|
396 | end |
|
408 | end |
|
397 |
|
409 | ||
|
398 | def output_filename(user_name, problem_name, submission_id, case_num) |
|
410 | def output_filename(user_name, problem_name, submission_id, case_num) |
|
399 | dir = grading_result_dir(user_name,problem_name, submission_id, case_num) |
|
411 | dir = grading_result_dir(user_name,problem_name, submission_id, case_num) |
|
400 | return "#{dir}/output.txt" |
|
412 | return "#{dir}/output.txt" |
|
401 | end |
|
413 | end |
|
402 |
|
414 | ||
|
403 | def read_grading_result(user_name, problem_name, submission_id, case_num) |
|
415 | def read_grading_result(user_name, problem_name, submission_id, case_num) |
|
404 | dir = grading_result_dir(user_name,problem_name, submission_id, case_num) |
|
416 | dir = grading_result_dir(user_name,problem_name, submission_id, case_num) |
|
405 | result_file_name = "#{dir}/result" |
|
417 | result_file_name = "#{dir}/result" |
|
406 | if !FileTest.exists?(result_file_name) |
|
418 | if !FileTest.exists?(result_file_name) |
|
407 | return {:num => case_num, :msg => 'program did not run'} |
|
419 | return {:num => case_num, :msg => 'program did not run'} |
|
408 | else |
|
420 | else |
|
409 | results = File.open(result_file_name).readlines |
|
421 | results = File.open(result_file_name).readlines |
|
410 | run_stat = extract_running_stat(results) |
|
422 | run_stat = extract_running_stat(results) |
|
411 | output_filename = "#{dir}/output.txt" |
|
423 | output_filename = "#{dir}/output.txt" |
|
412 | if FileTest.exists?(output_filename) |
|
424 | if FileTest.exists?(output_filename) |
|
413 | output_file = true |
|
425 | output_file = true |
|
414 | output_size = File.size(output_filename) |
|
426 | output_size = File.size(output_filename) |
|
415 | else |
|
427 | else |
|
416 | output_file = false |
|
428 | output_file = false |
|
417 | output_size = 0 |
|
429 | output_size = 0 |
|
418 | end |
|
430 | end |
|
419 |
|
431 |
@@ -1,38 +1,38 | |||||
|
1 | <% selected_problem_id = @current_problem ? @current_problem.id : -1 %> |
|
1 | <% selected_problem_id = @current_problem ? @current_problem.id : -1 %> |
|
2 | <div class="submitbox"> |
|
2 | <div class="submitbox"> |
|
3 | <b>Problem:</b> <%= select 'submission', 'problem_id', |
|
3 | <b>Problem:</b> <%= select 'submission', 'problem_id', |
|
4 | [['กรุณาเลือกข้อที่ต้องการส่งหรือทดสอบ','-1']] + |
|
4 | [['กรุณาเลือกข้อที่ต้องการส่งหรือทดสอบ','-1']] + |
|
5 | @problems.collect {|p| [p.full_name, p.id]}, |
|
5 | @problems.collect {|p| [p.full_name, p.id]}, |
|
6 | { :selected => selected_problem_id }, |
|
6 | { :selected => selected_problem_id }, |
|
7 | { :onchange => 'TOIContest.problemSelectClick()' } %> |
|
7 | { :onchange => 'TOIContest.problemSelectClick()' } %> |
|
8 | </div> |
|
8 | </div> |
|
9 |
|
9 | ||
|
10 | <% @problems.each do |problem| %> |
|
10 | <% @problems.each do |problem| %> |
|
11 | <div class="submission-submit-divs" id="submission_submit_div_<%= problem.id %>_id" style="display: none;"> |
|
11 | <div class="submission-submit-divs" id="submission_submit_div_<%= problem.id %>_id" style="display: none;"> |
|
12 | <div style="border: 1px solid #c0c0c0; padding: 5px; margin: 5px 0 5px 0;"> |
|
12 | <div style="border: 1px solid #c0c0c0; padding: 5px; margin: 5px 0 5px 0;"> |
|
13 | <b><%= problem.full_name %>: ข้อมูลสำหรับตรวจสอบ</b> (สามารถดาวน์โหลดและส่งกี่ครั้งก็ได้,ไม่มีคะแนน): |
|
13 | <b><%= problem.full_name %>: ข้อมูลสำหรับตรวจสอบ</b> (สามารถดาวน์โหลดและส่งกี่ครั้งก็ได้,ไม่มีคะแนน): |
|
14 | <%= link_to 'ดาวน์โหลด input', :action => 'verifying_testcase', :id => problem.id %> |
|
14 | <%= link_to 'ดาวน์โหลด input', :action => 'verifying_testcase', :id => problem.id %> |
|
15 | <% if @current_problem and @current_problem.id == problem.id %> |
|
15 | <% if @current_problem and @current_problem.id == problem.id %> |
|
16 | <% if @grading_result %> |
|
16 | <% if @grading_result %> |
|
17 | | <b>ผลการตรวจ:</b> <%= "#{@grading_result[:score]}/#{@grading_result[:full_score]} [#{@grading_result[:msg]}]" %> |
|
17 | | <b>ผลการตรวจ:</b> <%= "#{@grading_result[:score]}/#{@grading_result[:full_score]} [#{@grading_result[:msg]}]" %> |
|
18 | <% end %> |
|
18 | <% end %> |
|
19 | <% end %> |
|
19 | <% end %> |
|
20 | <%= form_tag({:controller => 'main', :action => 'verifying_submit', :id => problem.id}, {:method => 'post', :multipart => true }) do %> |
|
20 | <%= form_tag({:controller => 'main', :action => 'verifying_submit', :id => problem.id}, {:method => 'post', :multipart => true }) do %> |
|
21 | ส่งคำตอบของข้อมูลสำหรับตรวจสอบ: |
|
21 | ส่งคำตอบของข้อมูลสำหรับตรวจสอบ: |
|
22 | <%= file_field_tag 'output_file' %> |
|
22 | <%= file_field_tag 'output_file' %> |
|
23 | <%= submit_tag 'Submit' %> |
|
23 | <%= submit_tag 'Submit' %> |
|
24 | <% end %> |
|
24 | <% end %> |
|
25 | </div> |
|
25 | </div> |
|
26 | <div style="border: 1px solid #c0c0c0; padding: 5px; margin: 5px 0 5px 0;"> |
|
26 | <div style="border: 1px solid #c0c0c0; padding: 5px; margin: 5px 0 5px 0;"> |
|
27 | <b><%= problem.full_name %>: ข้อมูลทดสอบจริง</b> (ส่งกี่ครั้งก็ได้ภายในเวลา 5 นาทีหลังดาวน์โหลด): |
|
27 | <b><%= problem.full_name %>: ข้อมูลทดสอบจริง</b> (ส่งกี่ครั้งก็ได้ภายในเวลา 5 นาทีหลังดาวน์โหลด): |
|
28 | <%= link_to 'ดาวน์โหลด input และเริ่มจับเวลา', { :action => 'testcase', :id => problem.id}, { :onclick => "return TOIContest.confirmDownload(#{problem.id})" } %> |
|
28 | <%= link_to 'ดาวน์โหลด input และเริ่มจับเวลา', { :action => 'testcase', :id => problem.id}, { :onclick => "return TOIContest.confirmDownload(#{problem.id})" } %> |
|
29 | <span id="submission_time_left_<%= problem.id %>_id"></span> |
|
29 | <span id="submission_time_left_<%= problem.id %>_id"></span> |
|
30 | <%= form_tag({:controller => 'main', :action => 'submit'}, {:method => 'post', :multipart => true, :id => "submission_form_#{problem.id}_id" }) do %> |
|
30 | <%= form_tag({:controller => 'main', :action => 'submit'}, {:method => 'post', :multipart => true, :id => "submission_form_#{problem.id}_id" }) do %> |
|
31 | <%= hidden_field_tag 'submission[problem_id]', problem.id %> |
|
31 | <%= hidden_field_tag 'submission[problem_id]', problem.id %> |
|
32 | ข้อมูลส่งออก: <%= file_field_tag 'output_file' %> |
|
32 | ข้อมูลส่งออก: <%= file_field_tag 'output_file' %> |
|
33 |
- โปรแกรม |
|
33 | + โปรแกรมของคุณ: <%= file_field_tag 'file' %> |
|
34 | <%= submit_tag 'Submit' %> |
|
34 | <%= submit_tag 'Submit' %> |
|
35 | <% end %> |
|
35 | <% end %> |
|
36 | </div> |
|
36 | </div> |
|
37 | </div> |
|
37 | </div> |
|
38 | <% end %> |
|
38 | <% end %> |
You need to be logged in to leave comments.
Login now