Description:
added timeout related javascripts
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r228:9e664dd71888 - - 5 files changed: 91 inserted, 2 deleted
@@ -0,0 +1,7 | |||||
|
|
1 | + CodejomTimeout.timeouts = [ | ||
|
|
2 | + - @submission_timeouts.each_pair do |id, t| | ||
|
|
3 | + - if t!=nil | ||
|
|
4 | + = "{problem: #{id}, timeout: #{t}}," | ||
|
|
5 | + - else | ||
|
|
6 | + = "{problem: #{id}, timeout: null}," | ||
|
|
7 | + ]; |
@@ -0,0 +1,58 | |||||
|
|
1 | + var CodejomTimeout = { | ||
|
|
2 | + | ||
|
|
3 | + timeStarted: null, | ||
|
|
4 | + | ||
|
|
5 | + inputDataDuration: 5, // 5 minutes | ||
|
|
6 | + | ||
|
|
7 | + timeouts: [], | ||
|
|
8 | + | ||
|
|
9 | + updateProblemMessages: function() { | ||
|
|
10 | + CodejomTimeout.timeouts.each(function(data) { | ||
|
|
11 | + if(data.timeout==null) { | ||
|
|
12 | + $("problem-submission-form-" + data.problem).hide(); | ||
|
|
13 | + } else if(data.timeout==0) { | ||
|
|
14 | + $("problem-timing-message-" + data.problem).innerHTML = | ||
|
|
15 | + "The recent input data is expired. Please download a new one. You'll have 5 minute to submit."; | ||
|
|
16 | + $("problem-submission-form-" + data.problem).hide(); | ||
|
|
17 | + } else { | ||
|
|
18 | + $("problem-timing-message-" + data.problem).innerHTML = | ||
|
|
19 | + "You have about " + parseInt(data.timeout/60) + " minute(s) and " + parseInt(data.timeout % 60) + " second(s) to submit."; | ||
|
|
20 | + $("problem-submission-form-" + data.problem).show(); | ||
|
|
21 | + } | ||
|
|
22 | + }); | ||
|
|
23 | + }, | ||
|
|
24 | + | ||
|
|
25 | + refreshProblemMessages: function() { | ||
|
|
26 | + var timeElapsed = ((new Date()).getTime() - CodejomTimeout.timeStarted)/1000; | ||
|
|
27 | + // update timeout info | ||
|
|
28 | + CodejomTimeout.timeouts.each(function(data) { | ||
|
|
29 | + if(data.timeout > timeElapsed) { | ||
|
|
30 | + data.timeout -= timeElapsed; | ||
|
|
31 | + } else if(data.timeout > 0) { | ||
|
|
32 | + data.timeout = 0; | ||
|
|
33 | + } | ||
|
|
34 | + }); | ||
|
|
35 | + | ||
|
|
36 | + CodejomTimeout.updateProblemMessages(); | ||
|
|
37 | + CodejomTimeout.registerRefreshEvent(); | ||
|
|
38 | + }, | ||
|
|
39 | + | ||
|
|
40 | + registerRefreshEvent: function() { | ||
|
|
41 | + CodejomTimeout.timeStarted = (new Date()).getTime(), | ||
|
|
42 | + setTimeout(function () { | ||
|
|
43 | + CodejomTimeout.refreshProblemMessages(); | ||
|
|
44 | + }, 2700); | ||
|
|
45 | + }, | ||
|
|
46 | + | ||
|
|
47 | + updateTimeoutAfterDownloadClick: function(problem) { | ||
|
|
48 | + CodejomTimeout.timeouts | ||
|
|
49 | + .filter(function(data) { return data.problem==problem; }) | ||
|
|
50 | + .each(function(data) { | ||
|
|
51 | + if(data.timeout==0 || data.timeout==null) { | ||
|
|
52 | + // TODO: use value from rails app. | ||
|
|
53 | + data.timeout = CodejomTimeout.inputDataDuration * 60; | ||
|
|
54 | + } | ||
|
|
55 | + }); | ||
|
|
56 | + CodejomTimeout.updateProblemMessages(); | ||
|
|
57 | + }, | ||
|
|
58 | + }; |
@@ -83,345 +83,365 | |||||
|
83 | send_data(submission.source, |
|
83 | send_data(submission.source, |
|
84 | {:filename => submission.download_filename, |
|
84 | {:filename => submission.download_filename, |
|
85 | :type => 'text/plain'}) |
|
85 | :type => 'text/plain'}) |
|
86 | else |
|
86 | else |
|
87 | flash[:notice] = 'Error viewing source' |
|
87 | flash[:notice] = 'Error viewing source' |
|
88 | redirect_to :action => 'list' |
|
88 | redirect_to :action => 'list' |
|
89 | end |
|
89 | end |
|
90 | end |
|
90 | end |
|
91 |
|
91 | ||
|
92 | def compiler_msg |
|
92 | def compiler_msg |
|
93 | @submission = Submission.find(params[:id]) |
|
93 | @submission = Submission.find(params[:id]) |
|
94 | if @submission.user_id == session[:user_id] |
|
94 | if @submission.user_id == session[:user_id] |
|
95 | render :action => 'compiler_msg', :layout => 'empty' |
|
95 | render :action => 'compiler_msg', :layout => 'empty' |
|
96 | else |
|
96 | else |
|
97 | flash[:notice] = 'Error viewing source' |
|
97 | flash[:notice] = 'Error viewing source' |
|
98 | redirect_to :action => 'list' |
|
98 | redirect_to :action => 'list' |
|
99 | end |
|
99 | end |
|
100 | end |
|
100 | end |
|
101 |
|
101 | ||
|
102 | def submission |
|
102 | def submission |
|
103 | @user = User.find(session[:user_id]) |
|
103 | @user = User.find(session[:user_id]) |
|
104 | @problems = Problem.find_available_problems |
|
104 | @problems = Problem.find_available_problems |
|
105 | if params[:id]==nil |
|
105 | if params[:id]==nil |
|
106 | @problem = nil |
|
106 | @problem = nil |
|
107 | @submissions = nil |
|
107 | @submissions = nil |
|
108 | else |
|
108 | else |
|
109 | @problem = Problem.find_by_name(params[:id]) |
|
109 | @problem = Problem.find_by_name(params[:id]) |
|
110 | if not @problem.available |
|
110 | if not @problem.available |
|
111 | redirect_to :action => 'list' |
|
111 | redirect_to :action => 'list' |
|
112 | flash[:notice] = 'Error: submissions for that problem are not viewable.' |
|
112 | flash[:notice] = 'Error: submissions for that problem are not viewable.' |
|
113 | return |
|
113 | return |
|
114 | end |
|
114 | end |
|
115 | @submissions = Submission.find_all_by_user_problem(@user.id, @problem.id) |
|
115 | @submissions = Submission.find_all_by_user_problem(@user.id, @problem.id) |
|
116 | end |
|
116 | end |
|
117 | end |
|
117 | end |
|
118 |
|
118 | ||
|
119 | def result |
|
119 | def result |
|
120 | if !Configuration.show_grading_result |
|
120 | if !Configuration.show_grading_result |
|
121 | redirect_to :action => 'list' and return |
|
121 | redirect_to :action => 'list' and return |
|
122 | end |
|
122 | end |
|
123 | @user = User.find(session[:user_id]) |
|
123 | @user = User.find(session[:user_id]) |
|
124 | @submission = Submission.find(params[:id]) |
|
124 | @submission = Submission.find(params[:id]) |
|
125 | if @submission.user!=@user |
|
125 | if @submission.user!=@user |
|
126 | flash[:notice] = 'You are not allowed to view result of other users.' |
|
126 | flash[:notice] = 'You are not allowed to view result of other users.' |
|
127 | redirect_to :action => 'list' and return |
|
127 | redirect_to :action => 'list' and return |
|
128 | end |
|
128 | end |
|
129 | prepare_grading_result(@submission) |
|
129 | prepare_grading_result(@submission) |
|
130 | end |
|
130 | end |
|
131 |
|
131 | ||
|
132 | def load_output |
|
132 | def load_output |
|
133 | if !Configuration.show_grading_result or params[:num]==nil |
|
133 | if !Configuration.show_grading_result or params[:num]==nil |
|
134 | redirect_to :action => 'list' and return |
|
134 | redirect_to :action => 'list' and return |
|
135 | end |
|
135 | end |
|
136 | @user = User.find(session[:user_id]) |
|
136 | @user = User.find(session[:user_id]) |
|
137 | @submission = Submission.find(params[:id]) |
|
137 | @submission = Submission.find(params[:id]) |
|
138 | if @submission.user!=@user |
|
138 | if @submission.user!=@user |
|
139 | flash[:notice] = 'You are not allowed to view result of other users.' |
|
139 | flash[:notice] = 'You are not allowed to view result of other users.' |
|
140 | redirect_to :action => 'list' and return |
|
140 | redirect_to :action => 'list' and return |
|
141 | end |
|
141 | end |
|
142 | case_num = params[:num].to_i |
|
142 | case_num = params[:num].to_i |
|
143 | out_filename = output_filename(@user.login, |
|
143 | out_filename = output_filename(@user.login, |
|
144 | @submission.problem.name, |
|
144 | @submission.problem.name, |
|
145 | @submission.id, |
|
145 | @submission.id, |
|
146 | case_num) |
|
146 | case_num) |
|
147 | if !FileTest.exists?(out_filename) |
|
147 | if !FileTest.exists?(out_filename) |
|
148 | flash[:notice] = 'Output not found.' |
|
148 | flash[:notice] = 'Output not found.' |
|
149 | redirect_to :action => 'list' and return |
|
149 | redirect_to :action => 'list' and return |
|
150 | end |
|
150 | end |
|
151 |
|
151 | ||
|
152 | response.headers['Content-Type'] = "application/force-download" |
|
152 | response.headers['Content-Type'] = "application/force-download" |
|
153 | response.headers['Content-Disposition'] = "attachment; filename=\"output-#{case_num}.txt\"" |
|
153 | response.headers['Content-Disposition'] = "attachment; filename=\"output-#{case_num}.txt\"" |
|
154 | response.headers["X-Sendfile"] = out_filename |
|
154 | response.headers["X-Sendfile"] = out_filename |
|
155 | response.headers['Content-length'] = File.size(out_filename) |
|
155 | response.headers['Content-length'] = File.size(out_filename) |
|
156 | render :nothing => true |
|
156 | render :nothing => true |
|
157 | end |
|
157 | end |
|
158 |
|
158 | ||
|
159 | def error |
|
159 | def error |
|
160 | @user = User.find(session[:user_id]) |
|
160 | @user = User.find(session[:user_id]) |
|
161 | end |
|
161 | end |
|
162 |
|
162 | ||
|
163 | # announcement refreshing and hiding methods |
|
163 | # announcement refreshing and hiding methods |
|
164 |
|
164 | ||
|
165 | def announcements |
|
165 | def announcements |
|
166 | if params.has_key? 'recent' |
|
166 | if params.has_key? 'recent' |
|
167 | prepare_announcements(params[:recent]) |
|
167 | prepare_announcements(params[:recent]) |
|
168 | else |
|
168 | else |
|
169 | prepare_announcements |
|
169 | prepare_announcements |
|
170 | end |
|
170 | end |
|
171 | render(:partial => 'announcement', |
|
171 | render(:partial => 'announcement', |
|
172 | :collection => @announcements, |
|
172 | :collection => @announcements, |
|
173 | :locals => {:announcement_effect => true}) |
|
173 | :locals => {:announcement_effect => true}) |
|
174 | end |
|
174 | end |
|
175 |
|
175 | ||
|
176 | # |
|
176 | # |
|
177 | # actions for Code Jom |
|
177 | # actions for Code Jom |
|
178 | # |
|
178 | # |
|
179 | def download_input |
|
179 | def download_input |
|
180 | problem = Problem.find(params[:id]) |
|
180 | problem = Problem.find(params[:id]) |
|
181 | user = User.find(session[:user_id]) |
|
181 | user = User.find(session[:user_id]) |
|
182 | if user.can_request_new_test_pair_for? problem |
|
182 | if user.can_request_new_test_pair_for? problem |
|
183 | assignment = user.get_new_test_pair_assignment_for problem |
|
183 | assignment = user.get_new_test_pair_assignment_for problem |
|
184 | assignment.save |
|
184 | assignment.save |
|
185 |
|
185 | ||
|
186 | send_data(assignment.test_pair.input, |
|
186 | send_data(assignment.test_pair.input, |
|
187 | { :filename => "#{problem.name}-#{assignment.request_number}.in", |
|
187 | { :filename => "#{problem.name}-#{assignment.request_number}.in", |
|
188 | :type => 'text/plain' }) |
|
188 | :type => 'text/plain' }) |
|
189 | else |
|
189 | else |
|
190 | recent_assignment = user.get_recent_test_pair_assignment_for problem |
|
190 | recent_assignment = user.get_recent_test_pair_assignment_for problem |
|
191 | send_data(recent_assignment.test_pair.input, |
|
191 | send_data(recent_assignment.test_pair.input, |
|
192 | { :filename => "#{problem.name}-#{recent_assignment.request_number}.in", |
|
192 | { :filename => "#{problem.name}-#{recent_assignment.request_number}.in", |
|
193 | :type => 'text/plain' }) |
|
193 | :type => 'text/plain' }) |
|
194 | end |
|
194 | end |
|
195 | end |
|
195 | end |
|
196 |
|
196 | ||
|
197 | def submit_solution |
|
197 | def submit_solution |
|
198 | problem = Problem.find(params[:id]) |
|
198 | problem = Problem.find(params[:id]) |
|
199 | user = User.find(session[:user_id]) |
|
199 | user = User.find(session[:user_id]) |
|
200 | recent_assignment = user.get_recent_test_pair_assignment_for problem |
|
200 | recent_assignment = user.get_recent_test_pair_assignment_for problem |
|
201 |
|
201 | ||
|
202 | if recent_assignment == nil |
|
202 | if recent_assignment == nil |
|
203 | flash[:notice] = 'You have not requested for any input data for this problem. Please download an input first.' |
|
203 | flash[:notice] = 'You have not requested for any input data for this problem. Please download an input first.' |
|
204 | session[:current_problem_id] = problem.id |
|
204 | session[:current_problem_id] = problem.id |
|
205 | redirect_to :action => 'list' and return |
|
205 | redirect_to :action => 'list' and return |
|
206 | end |
|
206 | end |
|
207 |
|
207 | ||
|
208 | if recent_assignment.expired? |
|
208 | if recent_assignment.expired? |
|
209 | flash[:notice] = 'The current input is expired. Please download a new input data.' |
|
209 | flash[:notice] = 'The current input is expired. Please download a new input data.' |
|
210 | session[:current_problem_id] = problem.id |
|
210 | session[:current_problem_id] = problem.id |
|
211 | redirect_to :action => 'list' and return |
|
211 | redirect_to :action => 'list' and return |
|
212 | end |
|
212 | end |
|
213 |
|
213 | ||
|
214 | if recent_assignment.submitted |
|
214 | if recent_assignment.submitted |
|
215 | flash[:notice] = 'You have already submitted an incorrect solution for this input. Please download a new input data.' |
|
215 | flash[:notice] = 'You have already submitted an incorrect solution for this input. Please download a new input data.' |
|
216 | session[:current_problem_id] = problem.id |
|
216 | session[:current_problem_id] = problem.id |
|
217 | redirect_to :action => 'list' and return |
|
217 | redirect_to :action => 'list' and return |
|
218 | end |
|
218 | end |
|
219 |
|
219 | ||
|
220 | if params[:file] == nil |
|
220 | if params[:file] == nil |
|
221 | flash[:notice] = 'You have not submitted any output.' |
|
221 | flash[:notice] = 'You have not submitted any output.' |
|
222 | session[:current_problem_id] = problem.id |
|
222 | session[:current_problem_id] = problem.id |
|
223 | redirect_to :action => 'list' and return |
|
223 | redirect_to :action => 'list' and return |
|
224 | end |
|
224 | end |
|
225 |
|
225 | ||
|
226 | submitted_solution = params[:file].read |
|
226 | submitted_solution = params[:file].read |
|
227 | test_pair = recent_assignment.test_pair |
|
227 | test_pair = recent_assignment.test_pair |
|
228 | passed = test_pair.grade(submitted_solution) |
|
228 | passed = test_pair.grade(submitted_solution) |
|
229 | points = passed ? 100 : 0 |
|
229 | points = passed ? 100 : 0 |
|
230 | submission = Submission.new(:user => user, |
|
230 | submission = Submission.new(:user => user, |
|
231 | :problem => problem, |
|
231 | :problem => problem, |
|
232 | :source => submitted_solution, |
|
232 | :source => submitted_solution, |
|
233 | :source_filename => params['file'].original_filename, |
|
233 | :source_filename => params['file'].original_filename, |
|
234 | :language_id => 0, |
|
234 | :language_id => 0, |
|
235 | :submitted_at => Time.new.gmtime, |
|
235 | :submitted_at => Time.new.gmtime, |
|
236 | :graded_at => Time.new.gmtime, |
|
236 | :graded_at => Time.new.gmtime, |
|
237 | :points => points) |
|
237 | :points => points) |
|
238 | submission.save |
|
238 | submission.save |
|
239 | recent_assignment.submitted = true |
|
239 | recent_assignment.submitted = true |
|
240 | recent_assignment.save |
|
240 | recent_assignment.save |
|
241 |
|
241 | ||
|
242 | status = user.get_submission_status_for(problem) |
|
242 | status = user.get_submission_status_for(problem) |
|
243 | if status == nil |
|
243 | if status == nil |
|
244 | status = SubmissionStatus.new :user => user, :problem => problem, :submission_count => 0 |
|
244 | status = SubmissionStatus.new :user => user, :problem => problem, :submission_count => 0 |
|
245 | end |
|
245 | end |
|
246 |
|
246 | ||
|
247 | status.submission_count += 1 |
|
247 | status.submission_count += 1 |
|
248 | status.passed = passed |
|
248 | status.passed = passed |
|
249 | status.save |
|
249 | status.save |
|
250 |
|
250 | ||
|
251 | if passed |
|
251 | if passed |
|
252 | flash[:notice] = 'Correct solution.' |
|
252 | flash[:notice] = 'Correct solution.' |
|
253 | user.update_codejom_status |
|
253 | user.update_codejom_status |
|
254 | else |
|
254 | else |
|
255 | session[:current_problem_id] = problem.id |
|
255 | session[:current_problem_id] = problem.id |
|
256 | flash[:notice] = 'Incorrect solution.' |
|
256 | flash[:notice] = 'Incorrect solution.' |
|
257 | end |
|
257 | end |
|
258 | redirect_to :action => 'list' |
|
258 | redirect_to :action => 'list' |
|
259 | end |
|
259 | end |
|
260 |
|
260 | ||
|
261 | protected |
|
261 | protected |
|
262 |
|
262 | ||
|
263 | def prepare_announcements(recent=nil) |
|
263 | def prepare_announcements(recent=nil) |
|
264 | if Configuration.show_tasks_to?(@user) |
|
264 | if Configuration.show_tasks_to?(@user) |
|
265 | @announcements = Announcement.find_published(true) |
|
265 | @announcements = Announcement.find_published(true) |
|
266 | else |
|
266 | else |
|
267 | @announcements = Announcement.find_published |
|
267 | @announcements = Announcement.find_published |
|
268 | end |
|
268 | end |
|
269 | if recent!=nil |
|
269 | if recent!=nil |
|
270 | recent_id = recent.to_i |
|
270 | recent_id = recent.to_i |
|
271 | @announcements = @announcements.find_all { |a| a.id > recent_id } |
|
271 | @announcements = @announcements.find_all { |a| a.id > recent_id } |
|
272 | end |
|
272 | end |
|
273 | end |
|
273 | end |
|
274 |
|
274 | ||
|
|
275 | + def prepare_timeout_information(problems) | ||
|
|
276 | + @submission_timeouts = {} | ||
|
|
277 | + problems.each do |problem| | ||
|
|
278 | + assignment = @user.get_recent_test_pair_assignment_for(problem) | ||
|
|
279 | + if assignment == nil | ||
|
|
280 | + timeout = nil | ||
|
|
281 | + else | ||
|
|
282 | + if assignment.expired? | ||
|
|
283 | + timeout = 0 | ||
|
|
284 | + else | ||
|
|
285 | + timeout = assignment.created_at + TEST_ASSIGNMENT_EXPIRATION_DURATION - Time.new.gmtime | ||
|
|
286 | + end | ||
|
|
287 | + end | ||
|
|
288 | + @submission_timeouts[problem.id] = timeout | ||
|
|
289 | + end | ||
|
|
290 | + @submission_timeouts.each_pair {|k,v| puts "#{k} => #{v}"} | ||
|
|
291 | + end | ||
|
|
292 | + | ||
|
275 | def prepare_list_information |
|
293 | def prepare_list_information |
|
276 | @user = User.find(session[:user_id]) |
|
294 | @user = User.find(session[:user_id]) |
|
277 |
|
295 | ||
|
278 | all_problems = Problem.find_available_problems |
|
296 | all_problems = Problem.find_available_problems |
|
279 |
|
297 | ||
|
280 | passed = {} |
|
298 | passed = {} |
|
281 | sub_count = {} |
|
299 | sub_count = {} |
|
282 | @user.submission_statuses.each do |status| |
|
300 | @user.submission_statuses.each do |status| |
|
283 | if status.passed |
|
301 | if status.passed |
|
284 | passed[status.problem_id] = true |
|
302 | passed[status.problem_id] = true |
|
285 | end |
|
303 | end |
|
286 | sub_count[status.problem_id] = status.submission_count |
|
304 | sub_count[status.problem_id] = status.submission_count |
|
287 | end |
|
305 | end |
|
288 |
|
306 | ||
|
289 | if session.has_key? :current_problem_id |
|
307 | if session.has_key? :current_problem_id |
|
290 | @current_problem_id = session[:current_problem_id] |
|
308 | @current_problem_id = session[:current_problem_id] |
|
291 | session.delete(:current_problem_id) |
|
309 | session.delete(:current_problem_id) |
|
292 | else |
|
310 | else |
|
293 | @current_problem_id = nil |
|
311 | @current_problem_id = nil |
|
294 | end |
|
312 | end |
|
295 |
|
313 | ||
|
296 | @problems = all_problems.reject { |problem| passed.has_key? problem.id } |
|
314 | @problems = all_problems.reject { |problem| passed.has_key? problem.id } |
|
297 |
|
315 | ||
|
|
316 | + prepare_timeout_information(@problems) | ||
|
|
317 | + | ||
|
298 | @prob_submissions = Array.new |
|
318 | @prob_submissions = Array.new |
|
299 | @problems.each do |p| |
|
319 | @problems.each do |p| |
|
300 | if sub_count.has_key? p.id |
|
320 | if sub_count.has_key? p.id |
|
301 | @prob_submissions << { :count => sub_count[p.id] } |
|
321 | @prob_submissions << { :count => sub_count[p.id] } |
|
302 | else |
|
322 | else |
|
303 | @prob_submissions << { :count => 0 } |
|
323 | @prob_submissions << { :count => 0 } |
|
304 | end |
|
324 | end |
|
305 | end |
|
325 | end |
|
306 | prepare_announcements |
|
326 | prepare_announcements |
|
307 | end |
|
327 | end |
|
308 |
|
328 | ||
|
309 | def check_viewability |
|
329 | def check_viewability |
|
310 | @user = User.find(session[:user_id]) |
|
330 | @user = User.find(session[:user_id]) |
|
311 | if (!Configuration.show_tasks_to?(@user)) and |
|
331 | if (!Configuration.show_tasks_to?(@user)) and |
|
312 | ((action_name=='submission') or (action_name=='submit')) |
|
332 | ((action_name=='submission') or (action_name=='submit')) |
|
313 | redirect_to :action => 'list' and return |
|
333 | redirect_to :action => 'list' and return |
|
314 | end |
|
334 | end |
|
315 | end |
|
335 | end |
|
316 |
|
336 | ||
|
317 | def prepare_grading_result(submission) |
|
337 | def prepare_grading_result(submission) |
|
318 | if Configuration.task_grading_info.has_key? submission.problem.name |
|
338 | if Configuration.task_grading_info.has_key? submission.problem.name |
|
319 | grading_info = Configuration.task_grading_info[submission.problem.name] |
|
339 | grading_info = Configuration.task_grading_info[submission.problem.name] |
|
320 | else |
|
340 | else |
|
321 | # guess task info from problem.full_score |
|
341 | # guess task info from problem.full_score |
|
322 | cases = submission.problem.full_score / 10 |
|
342 | cases = submission.problem.full_score / 10 |
|
323 | grading_info = { |
|
343 | grading_info = { |
|
324 | 'testruns' => cases, |
|
344 | 'testruns' => cases, |
|
325 | 'testcases' => cases |
|
345 | 'testcases' => cases |
|
326 | } |
|
346 | } |
|
327 | end |
|
347 | end |
|
328 | @test_runs = [] |
|
348 | @test_runs = [] |
|
329 | if grading_info['testruns'].is_a? Integer |
|
349 | if grading_info['testruns'].is_a? Integer |
|
330 | trun_count = grading_info['testruns'] |
|
350 | trun_count = grading_info['testruns'] |
|
331 | trun_count.times do |i| |
|
351 | trun_count.times do |i| |
|
332 | @test_runs << [ read_grading_result(@user.login, |
|
352 | @test_runs << [ read_grading_result(@user.login, |
|
333 | submission.problem.name, |
|
353 | submission.problem.name, |
|
334 | submission.id, |
|
354 | submission.id, |
|
335 | i+1) ] |
|
355 | i+1) ] |
|
336 | end |
|
356 | end |
|
337 | else |
|
357 | else |
|
338 | grading_info['testruns'].keys.sort.each do |num| |
|
358 | grading_info['testruns'].keys.sort.each do |num| |
|
339 | run = [] |
|
359 | run = [] |
|
340 | testrun = grading_info['testruns'][num] |
|
360 | testrun = grading_info['testruns'][num] |
|
341 | testrun.each do |c| |
|
361 | testrun.each do |c| |
|
342 | run << read_grading_result(@user.login, |
|
362 | run << read_grading_result(@user.login, |
|
343 | submission.problem.name, |
|
363 | submission.problem.name, |
|
344 | submission.id, |
|
364 | submission.id, |
|
345 | c) |
|
365 | c) |
|
346 | end |
|
366 | end |
|
347 | @test_runs << run |
|
367 | @test_runs << run |
|
348 | end |
|
368 | end |
|
349 | end |
|
369 | end |
|
350 | end |
|
370 | end |
|
351 |
|
371 | ||
|
352 | def grading_result_dir(user_name, problem_name, submission_id, case_num) |
|
372 | def grading_result_dir(user_name, problem_name, submission_id, case_num) |
|
353 | return "#{GRADING_RESULT_DIR}/#{user_name}/#{problem_name}/#{submission_id}/test-result/#{case_num}" |
|
373 | return "#{GRADING_RESULT_DIR}/#{user_name}/#{problem_name}/#{submission_id}/test-result/#{case_num}" |
|
354 | end |
|
374 | end |
|
355 |
|
375 | ||
|
356 | def output_filename(user_name, problem_name, submission_id, case_num) |
|
376 | def output_filename(user_name, problem_name, submission_id, case_num) |
|
357 | dir = grading_result_dir(user_name,problem_name, submission_id, case_num) |
|
377 | dir = grading_result_dir(user_name,problem_name, submission_id, case_num) |
|
358 | return "#{dir}/output.txt" |
|
378 | return "#{dir}/output.txt" |
|
359 | end |
|
379 | end |
|
360 |
|
380 | ||
|
361 | def read_grading_result(user_name, problem_name, submission_id, case_num) |
|
381 | def read_grading_result(user_name, problem_name, submission_id, case_num) |
|
362 | dir = grading_result_dir(user_name,problem_name, submission_id, case_num) |
|
382 | dir = grading_result_dir(user_name,problem_name, submission_id, case_num) |
|
363 | result_file_name = "#{dir}/result" |
|
383 | result_file_name = "#{dir}/result" |
|
364 | if !FileTest.exists?(result_file_name) |
|
384 | if !FileTest.exists?(result_file_name) |
|
365 | return {:num => case_num, :msg => 'program did not run'} |
|
385 | return {:num => case_num, :msg => 'program did not run'} |
|
366 | else |
|
386 | else |
|
367 | results = File.open(result_file_name).readlines |
|
387 | results = File.open(result_file_name).readlines |
|
368 | run_stat = extract_running_stat(results) |
|
388 | run_stat = extract_running_stat(results) |
|
369 | output_filename = "#{dir}/output.txt" |
|
389 | output_filename = "#{dir}/output.txt" |
|
370 | if FileTest.exists?(output_filename) |
|
390 | if FileTest.exists?(output_filename) |
|
371 | output_file = true |
|
391 | output_file = true |
|
372 | output_size = File.size(output_filename) |
|
392 | output_size = File.size(output_filename) |
|
373 | else |
|
393 | else |
|
374 | output_file = false |
|
394 | output_file = false |
|
375 | output_size = 0 |
|
395 | output_size = 0 |
|
376 | end |
|
396 | end |
|
377 |
|
397 | ||
|
378 | return { |
|
398 | return { |
|
379 | :num => case_num, |
|
399 | :num => case_num, |
|
380 | :msg => results[0], |
|
400 | :msg => results[0], |
|
381 | :run_stat => run_stat, |
|
401 | :run_stat => run_stat, |
|
382 | :output => output_file, |
|
402 | :output => output_file, |
|
383 | :output_size => output_size |
|
403 | :output_size => output_size |
|
384 | } |
|
404 | } |
|
385 | end |
|
405 | end |
|
386 | end |
|
406 | end |
|
387 |
|
407 | ||
|
388 | # copied from grader/script/lib/test_request_helper.rb |
|
408 | # copied from grader/script/lib/test_request_helper.rb |
|
389 | def extract_running_stat(results) |
|
409 | def extract_running_stat(results) |
|
390 | running_stat_line = results[-1] |
|
410 | running_stat_line = results[-1] |
|
391 |
|
411 | ||
|
392 | # extract exit status line |
|
412 | # extract exit status line |
|
393 | run_stat = "" |
|
413 | run_stat = "" |
|
394 | if !(/[Cc]orrect/.match(results[0])) |
|
414 | if !(/[Cc]orrect/.match(results[0])) |
|
395 | run_stat = results[0].chomp |
|
415 | run_stat = results[0].chomp |
|
396 | else |
|
416 | else |
|
397 | run_stat = 'Program exited normally' |
|
417 | run_stat = 'Program exited normally' |
|
398 | end |
|
418 | end |
|
399 |
|
419 | ||
|
400 | logger.info "Stat line: #{running_stat_line}" |
|
420 | logger.info "Stat line: #{running_stat_line}" |
|
401 |
|
421 | ||
|
402 | # extract running time |
|
422 | # extract running time |
|
403 | if res = /r(.*)u(.*)s/.match(running_stat_line) |
|
423 | if res = /r(.*)u(.*)s/.match(running_stat_line) |
|
404 | seconds = (res[1].to_f + res[2].to_f) |
|
424 | seconds = (res[1].to_f + res[2].to_f) |
|
405 | time_stat = "Time used: #{seconds} sec." |
|
425 | time_stat = "Time used: #{seconds} sec." |
|
406 | else |
|
426 | else |
|
407 | seconds = nil |
|
427 | seconds = nil |
|
408 | time_stat = "Time used: n/a sec." |
|
428 | time_stat = "Time used: n/a sec." |
|
409 | end |
|
429 | end |
|
410 |
|
430 | ||
|
411 | # extract memory usage |
|
431 | # extract memory usage |
|
412 | if res = /s(.*)m/.match(running_stat_line) |
|
432 | if res = /s(.*)m/.match(running_stat_line) |
|
413 | memory_used = res[1].to_i |
|
433 | memory_used = res[1].to_i |
|
414 | else |
|
434 | else |
|
415 | memory_used = -1 |
|
435 | memory_used = -1 |
|
416 | end |
|
436 | end |
|
417 |
|
437 | ||
|
418 | return { |
|
438 | return { |
|
419 | :msg => "#{run_stat}\n#{time_stat}", |
|
439 | :msg => "#{run_stat}\n#{time_stat}", |
|
420 | :running_time => seconds, |
|
440 | :running_time => seconds, |
|
421 | :exit_status => run_stat, |
|
441 | :exit_status => run_stat, |
|
422 | :memory_usage => memory_used |
|
442 | :memory_usage => memory_used |
|
423 | } |
|
443 | } |
|
424 | end |
|
444 | end |
|
425 |
|
445 | ||
|
426 | end |
|
446 | end |
|
427 |
|
447 |
@@ -1,21 +1,21 | |||||
|
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 | .problem-form{:id => "problem-form-#{problem.id}"} |
|
2 | .problem-form{:id => "problem-form-#{problem.id}"} |
|
3 | - form_tag({ :action => 'download_input', :id => problem.id }, :method => :post) do |
|
3 | - form_tag({ :action => 'download_input', :id => problem.id }, :method => :post) do |
|
4 | %b Input: |
|
4 | %b Input: |
|
5 | - %input{:type => "submit", :value => "Download input"} |
|
5 | + %input{:type => "submit", :value => "Download input", :onclick => "CodejomTimeout.updateTimeoutAfterDownloadClick(#{problem.id}); return true;"} |
|
6 | %span{:id => "problem-timing-message-#{problem.id}"} |
|
6 | %span{:id => "problem-timing-message-#{problem.id}"} |
|
7 | = "After downloading, you have #{TEST_ASSIGNMENT_EXPIRATION_DURATION/60} minutes to submit." |
|
7 | = "After downloading, you have #{TEST_ASSIGNMENT_EXPIRATION_DURATION/60} minutes to submit." |
|
8 | %div{:id => "problem-submission-form-#{problem.id}"} |
|
8 | %div{:id => "problem-submission-form-#{problem.id}"} |
|
9 | - form_tag({ :action => 'submit_solution', :id => problem.id }, :method => :post, :multipart => true) do |
|
9 | - form_tag({ :action => 'submit_solution', :id => problem.id }, :method => :post, :multipart => true) do |
|
10 | %b Submit output: |
|
10 | %b Submit output: |
|
11 | %input{:type => "file", :name => "file"} |
|
11 | %input{:type => "file", :name => "file"} |
|
12 | %input{:type => "submit", :value => "Submit solution"} |
|
12 | %input{:type => "submit", :value => "Submit solution"} |
|
13 |
|
13 | ||
|
14 | .problem-description |
|
14 | .problem-description |
|
15 | - if problem.description!=nil |
|
15 | - if problem.description!=nil |
|
16 | - if problem.description.markdowned |
|
16 | - if problem.description.markdowned |
|
17 | = markdown(problem.description.body) |
|
17 | = markdown(problem.description.body) |
|
18 | - else |
|
18 | - else |
|
19 | = problem.description.body |
|
19 | = problem.description.body |
|
20 | - else |
|
20 | - else |
|
21 | (not available) |
|
21 | (not available) |
@@ -1,33 +1,37 | |||||
|
1 | - content_for :head do |
|
1 | - content_for :head do |
|
2 | = javascript_include_tag :defaults |
|
2 | = javascript_include_tag :defaults |
|
3 | = javascript_include_tag 'announcement_refresh.js' |
|
3 | = javascript_include_tag 'announcement_refresh.js' |
|
|
4 | + = javascript_include_tag 'codejom_timeout.js' | ||
|
4 |
|
5 | ||
|
5 | = user_title_bar(@user) |
|
6 | = user_title_bar(@user) |
|
6 |
|
7 | ||
|
7 | .announcementbox{:style => (@announcements.length==0 ? "display:none" : "")} |
|
8 | .announcementbox{:style => (@announcements.length==0 ? "display:none" : "")} |
|
8 | %span{:class => 'title'} |
|
9 | %span{:class => 'title'} |
|
9 | Announcements |
|
10 | Announcements |
|
10 | #announcementbox-body |
|
11 | #announcementbox-body |
|
11 | = render :partial => 'announcement', :collection => @announcements |
|
12 | = render :partial => 'announcement', :collection => @announcements |
|
12 |
|
13 | ||
|
13 | %hr/ |
|
14 | %hr/ |
|
14 |
|
15 | ||
|
15 | - if (Configuration.contest_mode?) and (@user.site!=nil) and (@user.site.started!=true) |
|
16 | - if (Configuration.contest_mode?) and (@user.site!=nil) and (@user.site.started!=true) |
|
16 | %p=t 'main.start_soon' |
|
17 | %p=t 'main.start_soon' |
|
17 |
|
18 | ||
|
18 | - if Configuration.show_tasks_to?(@user) |
|
19 | - if Configuration.show_tasks_to?(@user) |
|
19 | .problem-list |
|
20 | .problem-list |
|
20 | = render :partial => 'problem_title', :collection => @problems, :as => :problem |
|
21 | = render :partial => 'problem_title', :collection => @problems, :as => :problem |
|
21 | .problem-content |
|
22 | .problem-content |
|
22 | %span{:id => "problem-panel-filler", :style => (@current_problem_id!=nil) ? "display:none" : ""} |
|
23 | %span{:id => "problem-panel-filler", :style => (@current_problem_id!=nil) ? "display:none" : ""} |
|
23 | %b Welcome to Code Jom |
|
24 | %b Welcome to Code Jom |
|
24 | %br/ |
|
25 | %br/ |
|
25 | Choose problems from the list on the right. |
|
26 | Choose problems from the list on the right. |
|
26 | = render :partial => 'problem', :collection => @problems |
|
27 | = render :partial => 'problem', :collection => @problems |
|
27 |
|
28 | ||
|
28 | %br{:clear=>'both'}/ |
|
29 | %br{:clear=>'both'}/ |
|
29 | %hr/ |
|
30 | %hr/ |
|
30 |
|
31 | ||
|
31 | - :javascript |
|
32 | + %script{:type => "text/javascript"} |
|
32 | Announcement.registerRefreshEventTimer(); |
|
33 | Announcement.registerRefreshEventTimer(); |
|
|
34 | + = render :partial => 'submission_timeouts' | ||
|
|
35 | + CodejomTimeout.updateProblemMessages(); | ||
|
|
36 | + CodejomTimeout.registerRefreshEvent(); | ||
|
33 |
|
37 |
You need to be logged in to leave comments.
Login now