Description:
fix display bugs in corrent score
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r782:97cd56a5f1d8 - - 3 files changed: 5 inserted, 4 deleted

@@ -420,96 +420,97
420 #convert date & time
420 #convert date & time
421 date_and_time = '%Y-%m-%d %H:%M'
421 date_and_time = '%Y-%m-%d %H:%M'
422 begin
422 begin
423 md = params[:since_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
423 md = params[:since_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
424 @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)
424 @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)
425 rescue
425 rescue
426 @since_time = Time.zone.now.ago( 90.minutes)
426 @since_time = Time.zone.now.ago( 90.minutes)
427 end
427 end
428 begin
428 begin
429 md = params[:until_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
429 md = params[:until_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
430 @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)
430 @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)
431 rescue
431 rescue
432 @until_time = Time.zone.now
432 @until_time = Time.zone.now
433 end
433 end
434
434
435 #convert sid
435 #convert sid
436 @sid = params[:SID].split(/[,\s]/) if params[:SID]
436 @sid = params[:SID].split(/[,\s]/) if params[:SID]
437 unless @sid and @sid.size > 0
437 unless @sid and @sid.size > 0
438 return
438 return
439 redirect_to actoin: :cheat_scruntinize
439 redirect_to actoin: :cheat_scruntinize
440 flash[:notice] = 'Please enter at least 1 student id'
440 flash[:notice] = 'Please enter at least 1 student id'
441 end
441 end
442 mark = Array.new(@sid.size,'?')
442 mark = Array.new(@sid.size,'?')
443 condition = "(u.login = " + mark.join(' OR u.login = ') + ')'
443 condition = "(u.login = " + mark.join(' OR u.login = ') + ')'
444
444
445 @st = <<-SQL
445 @st = <<-SQL
446 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
446 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
447 FROM logins l INNER JOIN users u on l.user_id = u.id
447 FROM logins l INNER JOIN users u on l.user_id = u.id
448 WHERE l.created_at >= ? AND l.created_at <= ? AND #{condition}
448 WHERE l.created_at >= ? AND l.created_at <= ? AND #{condition}
449 UNION
449 UNION
450 SELECT s.submitted_at,s.id,u.login,u.full_name,s.ip_address,s.problem_id,s.points,s.user_id
450 SELECT s.submitted_at,s.id,u.login,u.full_name,s.ip_address,s.problem_id,s.points,s.user_id
451 FROM submissions s INNER JOIN users u ON s.user_id = u.id
451 FROM submissions s INNER JOIN users u ON s.user_id = u.id
452 WHERE s.submitted_at >= ? AND s.submitted_at <= ? AND #{condition}
452 WHERE s.submitted_at >= ? AND s.submitted_at <= ? AND #{condition}
453 ORDER BY submitted_at
453 ORDER BY submitted_at
454 SQL
454 SQL
455
455
456 p = [@st,@since_time,@until_time] + @sid + [@since_time,@until_time] + @sid
456 p = [@st,@since_time,@until_time] + @sid + [@since_time,@until_time] + @sid
457 @logs = Submission.joins(:problem).find_by_sql(p)
457 @logs = Submission.joins(:problem).find_by_sql(p)
458
458
459
459
460
460
461
461
462
462
463 end
463 end
464
464
465 protected
465 protected
466
466
467 def calculate_max_score(problems, users,since_id,until_id, get_last_score = false)
467 def calculate_max_score(problems, users,since_id,until_id, get_last_score = false)
468 + #score[i] = user #i's user stat where i is the index (not id)
468 scorearray = Array.new
469 scorearray = Array.new
469 users.each do |u|
470 users.each do |u|
470 ustat = Array.new
471 ustat = Array.new
471 ustat[0] = u
472 ustat[0] = u
472 problems.each do |p|
473 problems.each do |p|
473 unless get_last_score
474 unless get_last_score
474 #get max score
475 #get max score
475 max_points = 0
476 max_points = 0
476 Submission.find_in_range_by_user_and_problem(u.id,p.id,since_id,until_id).each do |sub|
477 Submission.find_in_range_by_user_and_problem(u.id,p.id,since_id,until_id).each do |sub|
477 max_points = sub.points if sub and sub.points and (sub.points > max_points)
478 max_points = sub.points if sub and sub.points and (sub.points > max_points)
478 end
479 end
479 ustat << [(max_points.to_f*100/p.full_score).round, (max_points>=p.full_score)]
480 ustat << [(max_points.to_f*100/p.full_score).round, (max_points>=p.full_score)]
480 else
481 else
481 #get latest score
482 #get latest score
482 sub = Submission.find_last_by_user_and_problem(u.id,p.id)
483 sub = Submission.find_last_by_user_and_problem(u.id,p.id)
483 if (sub!=nil) and (sub.points!=nil) and p and p.full_score
484 if (sub!=nil) and (sub.points!=nil) and p and p.full_score
484 ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)]
485 ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)]
485 else
486 else
486 ustat << [0,false]
487 ustat << [0,false]
487 end
488 end
488 end
489 end
489 end
490 end
490 scorearray << ustat
491 scorearray << ustat
491 end
492 end
492 return scorearray
493 return scorearray
493 end
494 end
494
495
495 def gen_csv_from_scorearray(scorearray,problem)
496 def gen_csv_from_scorearray(scorearray,problem)
496 CSV.generate do |csv|
497 CSV.generate do |csv|
497 #add header
498 #add header
498 header = ['User','Name', 'Activated?', 'Logged in', 'Contest']
499 header = ['User','Name', 'Activated?', 'Logged in', 'Contest']
499 problem.each { |p| header << p.name }
500 problem.each { |p| header << p.name }
500 header += ['Total','Passed']
501 header += ['Total','Passed']
501 csv << header
502 csv << header
502 #add data
503 #add data
503 scorearray.each do |sc|
504 scorearray.each do |sc|
504 total = num_passed = 0
505 total = num_passed = 0
505 row = Array.new
506 row = Array.new
506 sc.each_index do |i|
507 sc.each_index do |i|
507 if i == 0
508 if i == 0
508 row << sc[i].login
509 row << sc[i].login
509 row << sc[i].full_name
510 row << sc[i].full_name
510 row << sc[i].activated
511 row << sc[i].activated
511 row << (sc[i].try(:contest_stat).try(:started_at)!=nil ? 'yes' : 'no')
512 row << (sc[i].try(:contest_stat).try(:started_at)!=nil ? 'yes' : 'no')
512 row << sc[i].contests.collect {|c| c.name}.join(', ')
513 row << sc[i].contests.collect {|c| c.name}.join(', ')
513 else
514 else
514 row << sc[i][0]
515 row << sc[i][0]
515 total += sc[i][0]
516 total += sc[i][0]
@@ -1,65 +1,65
1 %table.table.sortable.table-striped.table-bordered.table-condensed
1 %table.table.sortable.table-striped.table-bordered.table-condensed
2 %thead
2 %thead
3 %tr
3 %tr
4 %th Login
4 %th Login
5 %th Name
5 %th Name
6 / %th Activated?
6 / %th Activated?
7 / %th Logged_in
7 / %th Logged_in
8 / %th Contest(s)
8 / %th Contest(s)
9 %th Remark
9 %th Remark
10 - @problems.each do |p|
10 - @problems.each do |p|
11 %th.text-right= p.name.gsub('_',' ')
11 %th.text-right= p.name.gsub('_',' ')
12 %th.text-right Total
12 %th.text-right Total
13 %th.text-right Passed
13 %th.text-right Passed
14 %tbody
14 %tbody
15 - - sum = Array.new(@scorearray[0].count,0)
15 + - sum = Array.new(@problems.count,0)
16 - - nonzero = Array.new(@scorearray[0].count,0)
16 + - nonzero = Array.new(@problems.count,0)
17 - - full = Array.new(@scorearray[0].count,0)
17 + - full = Array.new(@problems.count,0)
18 - @scorearray.each do |sc|
18 - @scorearray.each do |sc|
19 %tr
19 %tr
20 - total,num_passed = 0,0
20 - total,num_passed = 0,0
21 - sc.each_index do |i|
21 - sc.each_index do |i|
22 - if i == 0
22 - if i == 0
23 %td= link_to sc[i].login, stat_user_path(sc[i])
23 %td= link_to sc[i].login, stat_user_path(sc[i])
24 %td= sc[i].full_name
24 %td= sc[i].full_name
25 / %td= sc[i].activated
25 / %td= sc[i].activated
26 / %td= sc[i].try(:contest_stat).try(:started_at) ? 'yes' : 'no'
26 / %td= sc[i].try(:contest_stat).try(:started_at) ? 'yes' : 'no'
27 / %td= sc[i].contests.collect {|c| c.name}.join(', ')
27 / %td= sc[i].contests.collect {|c| c.name}.join(', ')
28 %td= sc[i].remark
28 %td= sc[i].remark
29 - else
29 - else
30 %td.text-right= sc[i][0]
30 %td.text-right= sc[i][0]
31 - total += sc[i][0]
31 - total += sc[i][0]
32 - num_passed += 1 if sc[i][1]
32 - num_passed += 1 if sc[i][1]
33 - sum[i] += sc[i][0]
33 - sum[i] += sc[i][0]
34 - nonzero[i] += 1 if sc[i][0] > 0
34 - nonzero[i] += 1 if sc[i][0] > 0
35 - full[i] += 1 if sc[i][1]
35 - full[i] += 1 if sc[i][1]
36 %td.text-right= total
36 %td.text-right= total
37 %td.text-right= num_passed
37 %td.text-right= num_passed
38 %tfoot
38 %tfoot
39 %tr
39 %tr
40 %td Summation
40 %td Summation
41 %td
41 %td
42 %td
42 %td
43 - sum.each.with_index do |s,i|
43 - sum.each.with_index do |s,i|
44 - next if i == 0
44 - next if i == 0
45 %td.text-right= number_with_delimiter(s)
45 %td.text-right= number_with_delimiter(s)
46 %td
46 %td
47 %td
47 %td
48 %tr
48 %tr
49 %td partial solver
49 %td partial solver
50 %td
50 %td
51 %td
51 %td
52 - nonzero.each.with_index do |s,i|
52 - nonzero.each.with_index do |s,i|
53 - next if i == 0
53 - next if i == 0
54 %td.text-right= number_with_delimiter(s)
54 %td.text-right= number_with_delimiter(s)
55 %td
55 %td
56 %td
56 %td
57 %tr
57 %tr
58 %td Full solver
58 %td Full solver
59 %td
59 %td
60 %td
60 %td
61 - full.each.with_index do |s,i|
61 - full.each.with_index do |s,i|
62 - next if i == 0
62 - next if i == 0
63 %td.text-right= number_with_delimiter(s)
63 %td.text-right= number_with_delimiter(s)
64 %td
64 %td
65 %td
65 %td
@@ -1,11 +1,11
1 .container-fluid
1 .container-fluid
2 %h1 Current Score
2 %h1 Current Score
3 = form_tag current_score_report_path, method: 'get' do
3 = form_tag current_score_report_path, method: 'get' do
4 Show only users from this group
4 Show only users from this group
5 - = select_tag "group_id", options_from_collection_for_select( Group.all, 'id','name',params[:group_name]), id: 'group_name',class: 'select2'
5 + = select_tag "group_id", options_from_collection_for_select( Group.all, 'id','name',params[:group_id]), id: 'group_name',class: 'select2', style: 'width: 20em';
6 = submit_tag 'Apply',class: 'btn btn-default'
6 = submit_tag 'Apply',class: 'btn btn-default'
7
7
8 %br
8 %br
9
9
10
10
11 = render "score_table"
11 = render "score_table"
You need to be logged in to leave comments. Login now