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

r614:20f955456e9b - - 1 file changed: 2 inserted, 2 deleted

@@ -7,98 +7,98
7 before_filter :admin_authorization, only: [:login_stat,:submission_stat, :stuck, :cheat_report, :cheat_scruntinize, :show_max_score]
7 before_filter :admin_authorization, only: [:login_stat,:submission_stat, :stuck, :cheat_report, :cheat_scruntinize, :show_max_score]
8
8
9 before_filter(only: [:problem_hof]) { |c|
9 before_filter(only: [:problem_hof]) { |c|
10 return false unless authenticate
10 return false unless authenticate
11
11
12 if GraderConfiguration["right.user_view_submission"]
12 if GraderConfiguration["right.user_view_submission"]
13 return true;
13 return true;
14 end
14 end
15
15
16 admin_authorization
16 admin_authorization
17 }
17 }
18
18
19 def max_score
19 def max_score
20 end
20 end
21
21
22 def current_score
22 def current_score
23 @problems = Problem.find_available_problems
23 @problems = Problem.find_available_problems
24 @users = User.includes(:contests).includes(:contest_stat).where(enabled: true)
24 @users = User.includes(:contests).includes(:contest_stat).where(enabled: true)
25 @scorearray = calculate_max_score(@problems, @users,0,0,true)
25 @scorearray = calculate_max_score(@problems, @users,0,0,true)
26
26
27 #rencer accordingly
27 #rencer accordingly
28 if params[:button] == 'download' then
28 if params[:button] == 'download' then
29 csv = gen_csv_from_scorearray(@scorearray,@problems)
29 csv = gen_csv_from_scorearray(@scorearray,@problems)
30 send_data csv, filename: 'max_score.csv'
30 send_data csv, filename: 'max_score.csv'
31 else
31 else
32 #render template: 'user_admin/user_stat'
32 #render template: 'user_admin/user_stat'
33 render 'current_score'
33 render 'current_score'
34 end
34 end
35 end
35 end
36
36
37 def show_max_score
37 def show_max_score
38 #process parameters
38 #process parameters
39 #problems
39 #problems
40 @problems = []
40 @problems = []
41 params[:problem_id].each do |id|
41 params[:problem_id].each do |id|
42 next unless id.strip != ""
42 next unless id.strip != ""
43 pid = Problem.find_by_id(id.to_i)
43 pid = Problem.find_by_id(id.to_i)
44 @problems << pid if pid
44 @problems << pid if pid
45 end
45 end
46
46
47 #users
47 #users
48 @users = if params[:user] == "all" then
48 @users = if params[:user] == "all" then
49 User.find(:all, :include => [:contests, :contest_stat])
49 User.find(:all, :include => [:contests, :contest_stat])
50 else
50 else
51 User.includes(:contests).includes(:contest_stat).where(enabled: true)
51 User.includes(:contests).includes(:contest_stat).where(enabled: true)
52 end
52 end
53
53
54 #set up range from param
54 #set up range from param
55 - since_id = params.fetch(:min_id, 0).to_i
55 + since_id = params.fetch(:from_id, 0).to_i
56 - until_id = params.fetch(:max_id, 0).to_i
56 + until_id = params.fetch(:to_id, 0).to_i
57
57
58 #calculate the routine
58 #calculate the routine
59 @scorearray = calculate_max_score(@problems, @users,since_id,until_id)
59 @scorearray = calculate_max_score(@problems, @users,since_id,until_id)
60
60
61 #rencer accordingly
61 #rencer accordingly
62 if params[:button] == 'download' then
62 if params[:button] == 'download' then
63 csv = gen_csv_from_scorearray(@scorearray,@problems)
63 csv = gen_csv_from_scorearray(@scorearray,@problems)
64 send_data csv, filename: 'max_score.csv'
64 send_data csv, filename: 'max_score.csv'
65 else
65 else
66 #render template: 'user_admin/user_stat'
66 #render template: 'user_admin/user_stat'
67 render 'max_score'
67 render 'max_score'
68 end
68 end
69
69
70 end
70 end
71
71
72 def score
72 def score
73 if params[:commit] == 'download csv'
73 if params[:commit] == 'download csv'
74 @problems = Problem.all
74 @problems = Problem.all
75 else
75 else
76 @problems = Problem.find_available_problems
76 @problems = Problem.find_available_problems
77 end
77 end
78 @users = User.includes(:contests, :contest_stat).where(enabled: true) #find(:all, :include => [:contests, :contest_stat]).where(enabled: true)
78 @users = User.includes(:contests, :contest_stat).where(enabled: true) #find(:all, :include => [:contests, :contest_stat]).where(enabled: true)
79 @scorearray = Array.new
79 @scorearray = Array.new
80 @users.each do |u|
80 @users.each do |u|
81 ustat = Array.new
81 ustat = Array.new
82 ustat[0] = u
82 ustat[0] = u
83 @problems.each do |p|
83 @problems.each do |p|
84 sub = Submission.find_last_by_user_and_problem(u.id,p.id)
84 sub = Submission.find_last_by_user_and_problem(u.id,p.id)
85 if (sub!=nil) and (sub.points!=nil) and p and p.full_score
85 if (sub!=nil) and (sub.points!=nil) and p and p.full_score
86 ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)]
86 ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)]
87 else
87 else
88 ustat << [0,false]
88 ustat << [0,false]
89 end
89 end
90 end
90 end
91 @scorearray << ustat
91 @scorearray << ustat
92 end
92 end
93 if params[:commit] == 'download csv' then
93 if params[:commit] == 'download csv' then
94 csv = gen_csv_from_scorearray(@scorearray,@problems)
94 csv = gen_csv_from_scorearray(@scorearray,@problems)
95 send_data csv, filename: 'last_score.csv'
95 send_data csv, filename: 'last_score.csv'
96 else
96 else
97 render template: 'user_admin/user_stat'
97 render template: 'user_admin/user_stat'
98 end
98 end
99
99
100 end
100 end
101
101
102 def login_stat
102 def login_stat
103 @logins = Array.new
103 @logins = Array.new
104
104
You need to be logged in to leave comments. Login now