Description:
fixed timeout bug for wrong submission (thanks to @dtinth), and js bugs occurring in IE
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r232:f00dec11b375 - - 2 files changed: 6 inserted, 2 deleted
@@ -186,193 +186,193 | |||||
|
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) |
|
275 | def prepare_timeout_information(problems) |
|
276 | @submission_timeouts = {} |
|
276 | @submission_timeouts = {} |
|
277 | problems.each do |problem| |
|
277 | problems.each do |problem| |
|
278 | assignment = @user.get_recent_test_pair_assignment_for(problem) |
|
278 | assignment = @user.get_recent_test_pair_assignment_for(problem) |
|
279 | if assignment == nil |
|
279 | if assignment == nil |
|
280 | timeout = nil |
|
280 | timeout = nil |
|
281 | else |
|
281 | else |
|
282 | - if assignment.expired? |
|
282 | + if (assignment.expired?) or (assignment.submitted) |
|
283 | timeout = 0 |
|
283 | timeout = 0 |
|
284 | else |
|
284 | else |
|
285 | timeout = assignment.created_at + TEST_ASSIGNMENT_EXPIRATION_DURATION - Time.new.gmtime |
|
285 | timeout = assignment.created_at + TEST_ASSIGNMENT_EXPIRATION_DURATION - Time.new.gmtime |
|
286 | end |
|
286 | end |
|
287 | end |
|
287 | end |
|
288 | @submission_timeouts[problem.id] = timeout |
|
288 | @submission_timeouts[problem.id] = timeout |
|
289 | end |
|
289 | end |
|
290 | @submission_timeouts.each_pair {|k,v| puts "#{k} => #{v}"} |
|
290 | @submission_timeouts.each_pair {|k,v| puts "#{k} => #{v}"} |
|
291 | end |
|
291 | end |
|
292 |
|
292 | ||
|
293 | def prepare_list_information |
|
293 | def prepare_list_information |
|
294 | @user = User.find(session[:user_id]) |
|
294 | @user = User.find(session[:user_id]) |
|
295 |
|
295 | ||
|
296 | all_problems = Problem.find_available_problems |
|
296 | all_problems = Problem.find_available_problems |
|
297 |
|
297 | ||
|
298 | passed = {} |
|
298 | passed = {} |
|
299 | sub_count = {} |
|
299 | sub_count = {} |
|
300 | @user.submission_statuses.each do |status| |
|
300 | @user.submission_statuses.each do |status| |
|
301 | if status.passed |
|
301 | if status.passed |
|
302 | passed[status.problem_id] = true |
|
302 | passed[status.problem_id] = true |
|
303 | end |
|
303 | end |
|
304 | sub_count[status.problem_id] = status.submission_count |
|
304 | sub_count[status.problem_id] = status.submission_count |
|
305 | end |
|
305 | end |
|
306 |
|
306 | ||
|
307 | if session.has_key? :current_problem_id |
|
307 | if session.has_key? :current_problem_id |
|
308 | @current_problem_id = session[:current_problem_id] |
|
308 | @current_problem_id = session[:current_problem_id] |
|
309 | session.delete(:current_problem_id) |
|
309 | session.delete(:current_problem_id) |
|
310 | else |
|
310 | else |
|
311 | @current_problem_id = nil |
|
311 | @current_problem_id = nil |
|
312 | end |
|
312 | end |
|
313 |
|
313 | ||
|
314 | @problems = all_problems.reject { |problem| passed.has_key? problem.id } |
|
314 | @problems = all_problems.reject { |problem| passed.has_key? problem.id } |
|
315 |
|
315 | ||
|
316 | prepare_timeout_information(@problems) |
|
316 | prepare_timeout_information(@problems) |
|
317 |
|
317 | ||
|
318 | @prob_submissions = Array.new |
|
318 | @prob_submissions = Array.new |
|
319 | @problems.each do |p| |
|
319 | @problems.each do |p| |
|
320 | if sub_count.has_key? p.id |
|
320 | if sub_count.has_key? p.id |
|
321 | @prob_submissions << { :count => sub_count[p.id] } |
|
321 | @prob_submissions << { :count => sub_count[p.id] } |
|
322 | else |
|
322 | else |
|
323 | @prob_submissions << { :count => 0 } |
|
323 | @prob_submissions << { :count => 0 } |
|
324 | end |
|
324 | end |
|
325 | end |
|
325 | end |
|
326 | prepare_announcements |
|
326 | prepare_announcements |
|
327 | end |
|
327 | end |
|
328 |
|
328 | ||
|
329 | def check_viewability |
|
329 | def check_viewability |
|
330 | @user = User.find(session[:user_id]) |
|
330 | @user = User.find(session[:user_id]) |
|
331 | if (!Configuration.show_tasks_to?(@user)) and |
|
331 | if (!Configuration.show_tasks_to?(@user)) and |
|
332 | ((action_name=='submission') or (action_name=='submit')) |
|
332 | ((action_name=='submission') or (action_name=='submit')) |
|
333 | redirect_to :action => 'list' and return |
|
333 | redirect_to :action => 'list' and return |
|
334 | end |
|
334 | end |
|
335 | end |
|
335 | end |
|
336 |
|
336 | ||
|
337 | def prepare_grading_result(submission) |
|
337 | def prepare_grading_result(submission) |
|
338 | if Configuration.task_grading_info.has_key? submission.problem.name |
|
338 | if Configuration.task_grading_info.has_key? submission.problem.name |
|
339 | grading_info = Configuration.task_grading_info[submission.problem.name] |
|
339 | grading_info = Configuration.task_grading_info[submission.problem.name] |
|
340 | else |
|
340 | else |
|
341 | # guess task info from problem.full_score |
|
341 | # guess task info from problem.full_score |
|
342 | cases = submission.problem.full_score / 10 |
|
342 | cases = submission.problem.full_score / 10 |
|
343 | grading_info = { |
|
343 | grading_info = { |
|
344 | 'testruns' => cases, |
|
344 | 'testruns' => cases, |
|
345 | 'testcases' => cases |
|
345 | 'testcases' => cases |
|
346 | } |
|
346 | } |
|
347 | end |
|
347 | end |
|
348 | @test_runs = [] |
|
348 | @test_runs = [] |
|
349 | if grading_info['testruns'].is_a? Integer |
|
349 | if grading_info['testruns'].is_a? Integer |
|
350 | trun_count = grading_info['testruns'] |
|
350 | trun_count = grading_info['testruns'] |
|
351 | trun_count.times do |i| |
|
351 | trun_count.times do |i| |
|
352 | @test_runs << [ read_grading_result(@user.login, |
|
352 | @test_runs << [ read_grading_result(@user.login, |
|
353 | submission.problem.name, |
|
353 | submission.problem.name, |
|
354 | submission.id, |
|
354 | submission.id, |
|
355 | i+1) ] |
|
355 | i+1) ] |
|
356 | end |
|
356 | end |
|
357 | else |
|
357 | else |
|
358 | grading_info['testruns'].keys.sort.each do |num| |
|
358 | grading_info['testruns'].keys.sort.each do |num| |
|
359 | run = [] |
|
359 | run = [] |
|
360 | testrun = grading_info['testruns'][num] |
|
360 | testrun = grading_info['testruns'][num] |
|
361 | testrun.each do |c| |
|
361 | testrun.each do |c| |
|
362 | run << read_grading_result(@user.login, |
|
362 | run << read_grading_result(@user.login, |
|
363 | submission.problem.name, |
|
363 | submission.problem.name, |
|
364 | submission.id, |
|
364 | submission.id, |
|
365 | c) |
|
365 | c) |
|
366 | end |
|
366 | end |
|
367 | @test_runs << run |
|
367 | @test_runs << run |
|
368 | end |
|
368 | end |
|
369 | end |
|
369 | end |
|
370 | end |
|
370 | end |
|
371 |
|
371 | ||
|
372 | 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) |
|
373 | 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}" |
|
374 | end |
|
374 | end |
|
375 |
|
375 | ||
|
376 | def output_filename(user_name, problem_name, submission_id, case_num) |
|
376 | def output_filename(user_name, problem_name, submission_id, case_num) |
|
377 | 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) |
|
378 | return "#{dir}/output.txt" |
|
378 | return "#{dir}/output.txt" |
@@ -1,58 +1,62 | |||||
|
1 | var CodejomTimeout = { |
|
1 | var CodejomTimeout = { |
|
2 |
|
2 | ||
|
3 | timeStarted: null, |
|
3 | timeStarted: null, |
|
4 |
|
4 | ||
|
5 | inputDataDuration: 5, // 5 minutes |
|
5 | inputDataDuration: 5, // 5 minutes |
|
6 |
|
6 | ||
|
7 | timeouts: [], |
|
7 | timeouts: [], |
|
8 |
|
8 | ||
|
9 | updateProblemMessages: function() { |
|
9 | updateProblemMessages: function() { |
|
10 | CodejomTimeout.timeouts.each(function(data) { |
|
10 | CodejomTimeout.timeouts.each(function(data) { |
|
|
11 | + if(data==null) | ||
|
|
12 | + return; | ||
|
11 | if(data.timeout==null) { |
|
13 | if(data.timeout==null) { |
|
12 | $("problem-submission-form-" + data.problem).hide(); |
|
14 | $("problem-submission-form-" + data.problem).hide(); |
|
13 | } else if(data.timeout==0) { |
|
15 | } else if(data.timeout==0) { |
|
14 | $("problem-timing-message-" + data.problem).innerHTML = |
|
16 | $("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."; |
|
17 | "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(); |
|
18 | $("problem-submission-form-" + data.problem).hide(); |
|
17 | } else { |
|
19 | } else { |
|
18 | $("problem-timing-message-" + data.problem).innerHTML = |
|
20 | $("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."; |
|
21 | "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(); |
|
22 | $("problem-submission-form-" + data.problem).show(); |
|
21 | } |
|
23 | } |
|
22 | }); |
|
24 | }); |
|
23 | }, |
|
25 | }, |
|
24 |
|
26 | ||
|
25 | refreshProblemMessages: function() { |
|
27 | refreshProblemMessages: function() { |
|
26 | var timeElapsed = ((new Date()).getTime() - CodejomTimeout.timeStarted)/1000; |
|
28 | var timeElapsed = ((new Date()).getTime() - CodejomTimeout.timeStarted)/1000; |
|
27 | // update timeout info |
|
29 | // update timeout info |
|
28 | CodejomTimeout.timeouts.each(function(data) { |
|
30 | CodejomTimeout.timeouts.each(function(data) { |
|
|
31 | + if(data==null) | ||
|
|
32 | + return; | ||
|
29 | if(data.timeout > timeElapsed) { |
|
33 | if(data.timeout > timeElapsed) { |
|
30 | data.timeout -= timeElapsed; |
|
34 | data.timeout -= timeElapsed; |
|
31 | } else if(data.timeout > 0) { |
|
35 | } else if(data.timeout > 0) { |
|
32 | data.timeout = 0; |
|
36 | data.timeout = 0; |
|
33 | } |
|
37 | } |
|
34 | }); |
|
38 | }); |
|
35 |
|
39 | ||
|
36 | CodejomTimeout.updateProblemMessages(); |
|
40 | CodejomTimeout.updateProblemMessages(); |
|
37 | CodejomTimeout.registerRefreshEvent(); |
|
41 | CodejomTimeout.registerRefreshEvent(); |
|
38 | }, |
|
42 | }, |
|
39 |
|
43 | ||
|
40 | registerRefreshEvent: function() { |
|
44 | registerRefreshEvent: function() { |
|
41 | CodejomTimeout.timeStarted = (new Date()).getTime(), |
|
45 | CodejomTimeout.timeStarted = (new Date()).getTime(), |
|
42 | setTimeout(function () { |
|
46 | setTimeout(function () { |
|
43 | CodejomTimeout.refreshProblemMessages(); |
|
47 | CodejomTimeout.refreshProblemMessages(); |
|
44 | }, 2700); |
|
48 | }, 2700); |
|
45 | }, |
|
49 | }, |
|
46 |
|
50 | ||
|
47 | updateTimeoutAfterDownloadClick: function(problem) { |
|
51 | updateTimeoutAfterDownloadClick: function(problem) { |
|
48 | CodejomTimeout.timeouts |
|
52 | CodejomTimeout.timeouts |
|
49 | - .filter(function(data) { return data.problem==problem; }) |
|
53 | + .filter(function(data) { return (data!=null) && (data.problem==problem); }) |
|
50 | .each(function(data) { |
|
54 | .each(function(data) { |
|
51 | if(data.timeout==0 || data.timeout==null) { |
|
55 | if(data.timeout==0 || data.timeout==null) { |
|
52 | // TODO: use value from rails app. |
|
56 | // TODO: use value from rails app. |
|
53 | data.timeout = CodejomTimeout.inputDataDuration * 60; |
|
57 | data.timeout = CodejomTimeout.inputDataDuration * 60; |
|
54 | } |
|
58 | } |
|
55 | }); |
|
59 | }); |
|
56 | CodejomTimeout.updateProblemMessages(); |
|
60 | CodejomTimeout.updateProblemMessages(); |
|
57 | }, |
|
61 | }, |
|
58 | }; |
|
62 | }; |
You need to be logged in to leave comments.
Login now