Description:
- fix syntax error
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r599:14a14eb28fed - - 1 file changed: 1 inserted, 0 deleted

@@ -381,104 +381,105
381 (SELECT u.id,COUNT(DISTINCT ip_address) as count,u.login,u.full_name
381 (SELECT u.id,COUNT(DISTINCT ip_address) as count,u.login,u.full_name
382 FROM logins l
382 FROM logins l
383 INNER JOIN users u ON l.user_id = u.id
383 INNER JOIN users u ON l.user_id = u.id
384 WHERE l.created_at >= ? and l.created_at <= ?
384 WHERE l.created_at >= ? and l.created_at <= ?
385 GROUP BY u.id
385 GROUP BY u.id
386 HAVING count > 1
386 HAVING count > 1
387 ) ml ON s.user_id = ml.id
387 ) ml ON s.user_id = ml.id
388 WHERE s.submitted_at >= ? and s.submitted_at <= ?
388 WHERE s.submitted_at >= ? and s.submitted_at <= ?
389 UNION
389 UNION
390 SELECT s.id,s.user_id,s.ip_address,s.submitted_at,s.problem_id
390 SELECT s.id,s.user_id,s.ip_address,s.submitted_at,s.problem_id
391 FROM submissions s INNER JOIN
391 FROM submissions s INNER JOIN
392 (SELECT l.ip_address,COUNT(DISTINCT u.id) as count
392 (SELECT l.ip_address,COUNT(DISTINCT u.id) as count
393 FROM logins l
393 FROM logins l
394 INNER JOIN users u ON l.user_id = u.id
394 INNER JOIN users u ON l.user_id = u.id
395 WHERE l.created_at >= ? and l.created_at <= ?
395 WHERE l.created_at >= ? and l.created_at <= ?
396 GROUP BY l.ip_address
396 GROUP BY l.ip_address
397 HAVING count > 1
397 HAVING count > 1
398 ) ml on ml.ip_address = s.ip_address
398 ) ml on ml.ip_address = s.ip_address
399 WHERE s.submitted_at >= ? and s.submitted_at <= ?
399 WHERE s.submitted_at >= ? and s.submitted_at <= ?
400 ORDER BY ip_address,submitted_at
400 ORDER BY ip_address,submitted_at
401 SQL
401 SQL
402 @subs = Submission.joins(:problem).find_by_sql([st,@since_time,@until_time,
402 @subs = Submission.joins(:problem).find_by_sql([st,@since_time,@until_time,
403 @since_time,@until_time,
403 @since_time,@until_time,
404 @since_time,@until_time,
404 @since_time,@until_time,
405 @since_time,@until_time])
405 @since_time,@until_time])
406
406
407 end
407 end
408
408
409 def cheat_scruntinize
409 def cheat_scruntinize
410 #convert date & time
410 #convert date & time
411 date_and_time = '%Y-%m-%d %H:%M'
411 date_and_time = '%Y-%m-%d %H:%M'
412 begin
412 begin
413 md = params[:since_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
413 md = params[:since_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
414 @since_time = Time.zone.local(md[1].to_i,md[2].to_i,md[3].to_i,md[4].to_i,md[5].to_i)
414 @since_time = Time.zone.local(md[1].to_i,md[2].to_i,md[3].to_i,md[4].to_i,md[5].to_i)
415 rescue
415 rescue
416 @since_time = Time.zone.now.ago( 90.minutes)
416 @since_time = Time.zone.now.ago( 90.minutes)
417 end
417 end
418 begin
418 begin
419 md = params[:until_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
419 md = params[:until_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
420 @until_time = Time.zone.local(md[1].to_i,md[2].to_i,md[3].to_i,md[4].to_i,md[5].to_i)
420 @until_time = Time.zone.local(md[1].to_i,md[2].to_i,md[3].to_i,md[4].to_i,md[5].to_i)
421 rescue
421 rescue
422 @until_time = Time.zone.now
422 @until_time = Time.zone.now
423 end
423 end
424
424
425 #convert sid
425 #convert sid
426 @sid = params[:SID].split(/[,\s]/) if params[:SID]
426 @sid = params[:SID].split(/[,\s]/) if params[:SID]
427 unless @sid and @sid.size > 0
427 unless @sid and @sid.size > 0
428 return
428 return
429 redirect_to actoin: :cheat_scruntinize
429 redirect_to actoin: :cheat_scruntinize
430 flash[:notice] = 'Please enter at least 1 student id'
430 flash[:notice] = 'Please enter at least 1 student id'
431 end
431 end
432 mark = Array.new(@sid.size,'?')
432 mark = Array.new(@sid.size,'?')
433 condition = "(u.login = " + mark.join(' OR u.login = ') + ')'
433 condition = "(u.login = " + mark.join(' OR u.login = ') + ')'
434
434
435 @st = <<-SQL
435 @st = <<-SQL
436 SELECT l.created_at as submitted_at ,-1 as id,u.login,u.full_name,l.ip_address,"" as problem_id,"" as points,l.user_id
436 SELECT l.created_at as submitted_at ,-1 as id,u.login,u.full_name,l.ip_address,"" as problem_id,"" as points,l.user_id
437 FROM logins l INNER JOIN users u on l.user_id = u.id
437 FROM logins l INNER JOIN users u on l.user_id = u.id
438 WHERE l.created_at >= ? AND l.created_at <= ? AND #{condition}
438 WHERE l.created_at >= ? AND l.created_at <= ? AND #{condition}
439 UNION
439 UNION
440 SELECT s.submitted_at,s.id,u.login,u.full_name,s.ip_address,s.problem_id,s.points,s.user_id
440 SELECT s.submitted_at,s.id,u.login,u.full_name,s.ip_address,s.problem_id,s.points,s.user_id
441 FROM submissions s INNER JOIN users u ON s.user_id = u.id
441 FROM submissions s INNER JOIN users u ON s.user_id = u.id
442 WHERE s.submitted_at >= ? AND s.submitted_at <= ? AND #{condition}
442 WHERE s.submitted_at >= ? AND s.submitted_at <= ? AND #{condition}
443 ORDER BY submitted_at
443 ORDER BY submitted_at
444 SQL
444 SQL
445
445
446 p = [@st,@since_time,@until_time] + @sid + [@since_time,@until_time] + @sid
446 p = [@st,@since_time,@until_time] + @sid + [@since_time,@until_time] + @sid
447 @logs = Submission.joins(:problem).find_by_sql(p)
447 @logs = Submission.joins(:problem).find_by_sql(p)
448
448
449
449
450
450
451
451
452
452
453 end
453 end
454
454
455 protected
455 protected
456
456
457 def calculate_max_score(problems, users,since_id,until_id, get_last_score = false)
457 def calculate_max_score(problems, users,since_id,until_id, get_last_score = false)
458 scorearray = Array.new
458 scorearray = Array.new
459 users.each do |u|
459 users.each do |u|
460 ustat = Array.new
460 ustat = Array.new
461 ustat[0] = u
461 ustat[0] = u
462 problems.each do |p|
462 problems.each do |p|
463 unless get_last_score
463 unless get_last_score
464 #get max score
464 #get max score
465 max_points = 0
465 max_points = 0
466 Submission.find_in_range_by_user_and_problem(u.id,p.id,since_id,until_id).each do |sub|
466 Submission.find_in_range_by_user_and_problem(u.id,p.id,since_id,until_id).each do |sub|
467 max_points = sub.points if sub and sub.points and (sub.points > max_points)
467 max_points = sub.points if sub and sub.points and (sub.points > max_points)
468 end
468 end
469 ustat << [(max_points.to_f*100/p.full_score).round, (max_points>=p.full_score)]
469 ustat << [(max_points.to_f*100/p.full_score).round, (max_points>=p.full_score)]
470 else
470 else
471 #get latest score
471 #get latest score
472 sub = Submission.find_last_by_user_and_problem(u.id,p.id)
472 sub = Submission.find_last_by_user_and_problem(u.id,p.id)
473 if (sub!=nil) and (sub.points!=nil) and p and p.full_score
473 if (sub!=nil) and (sub.points!=nil) and p and p.full_score
474 ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)]
474 ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)]
475 else
475 else
476 ustat << [0,false]
476 ustat << [0,false]
477 + end
477 end
478 end
478 end
479 end
479 scorearray << ustat
480 scorearray << ustat
480 end
481 end
481 return scorearray
482 return scorearray
482 end
483 end
483
484
484 end
485 end
You need to be logged in to leave comments. Login now