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
@@ -234,97 +234,97 | |||
|
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]) |
@@ -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