Description:
fixed timeout bug for wrong submission (thanks to @dtinth), and js bugs occurring in IE
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r232:f00dec11b375 - - 2 files changed: 6 inserted, 2 deleted

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