Description:
add authorization for show max score
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r595:ad86e593f5b0 - - 1 file changed: 1 inserted, 1 deleted
@@ -1,99 +1,99 | |||||
|
1 | class ReportController < ApplicationController |
|
1 | class ReportController < ApplicationController |
|
2 |
|
2 | ||
|
3 | - before_filter :admin_authorization, only: [:login_stat,:submission_stat, :stuck, :cheat_report, :cheat_scruntinize] |
|
3 | + before_filter :admin_authorization, only: [:login_stat,:submission_stat, :stuck, :cheat_report, :cheat_scruntinize, :show_max_score] |
|
4 |
|
4 | ||
|
5 | before_filter(only: [:problem_hof]) { |c| |
|
5 | before_filter(only: [:problem_hof]) { |c| |
|
6 | return false unless authenticate |
|
6 | return false unless authenticate |
|
7 |
|
7 | ||
|
8 | if GraderConfiguration["right.user_view_submission"] |
|
8 | if GraderConfiguration["right.user_view_submission"] |
|
9 | return true; |
|
9 | return true; |
|
10 | end |
|
10 | end |
|
11 |
|
11 | ||
|
12 | admin_authorization |
|
12 | admin_authorization |
|
13 | } |
|
13 | } |
|
14 |
|
14 | ||
|
15 | def max_score |
|
15 | def max_score |
|
16 | end |
|
16 | end |
|
17 |
|
17 | ||
|
18 | def show_max_score |
|
18 | def show_max_score |
|
19 | #process parameters |
|
19 | #process parameters |
|
20 | #problems |
|
20 | #problems |
|
21 | @problems = [] |
|
21 | @problems = [] |
|
22 | params[:problem_id].each do |id| |
|
22 | params[:problem_id].each do |id| |
|
23 | next unless id.strip != "" |
|
23 | next unless id.strip != "" |
|
24 | @problems << Problem.find(id.to_i) |
|
24 | @problems << Problem.find(id.to_i) |
|
25 | end |
|
25 | end |
|
26 |
|
26 | ||
|
27 | #users |
|
27 | #users |
|
28 | @users = if params[:user] == "all" then |
|
28 | @users = if params[:user] == "all" then |
|
29 | User.find(:all, :include => [:contests, :contest_stat]) |
|
29 | User.find(:all, :include => [:contests, :contest_stat]) |
|
30 | else |
|
30 | else |
|
31 | User.includes(:contests).includes(:contest_stat).where(enabled: true) |
|
31 | User.includes(:contests).includes(:contest_stat).where(enabled: true) |
|
32 | end |
|
32 | end |
|
33 |
|
33 | ||
|
34 | #set up range from param |
|
34 | #set up range from param |
|
35 | since_id = params.fetch(:min_id, 0).to_i |
|
35 | since_id = params.fetch(:min_id, 0).to_i |
|
36 | until_id = params.fetch(:max_id, 0).to_i |
|
36 | until_id = params.fetch(:max_id, 0).to_i |
|
37 |
|
37 | ||
|
38 | #get data |
|
38 | #get data |
|
39 | @scorearray = Array.new |
|
39 | @scorearray = Array.new |
|
40 | @users.each do |u| |
|
40 | @users.each do |u| |
|
41 | ustat = Array.new |
|
41 | ustat = Array.new |
|
42 | ustat[0] = u |
|
42 | ustat[0] = u |
|
43 | @problems.each do |p| |
|
43 | @problems.each do |p| |
|
44 | max_points = 0 |
|
44 | max_points = 0 |
|
45 | Submission.find_in_range_by_user_and_problem(u.id,p.id,since_id,until_id).each do |sub| |
|
45 | Submission.find_in_range_by_user_and_problem(u.id,p.id,since_id,until_id).each do |sub| |
|
46 | max_points = sub.points if sub and sub.points and (sub.points > max_points) |
|
46 | max_points = sub.points if sub and sub.points and (sub.points > max_points) |
|
47 | end |
|
47 | end |
|
48 | ustat << [(max_points.to_f*100/p.full_score).round, (max_points>=p.full_score)] |
|
48 | ustat << [(max_points.to_f*100/p.full_score).round, (max_points>=p.full_score)] |
|
49 | end |
|
49 | end |
|
50 | @scorearray << ustat |
|
50 | @scorearray << ustat |
|
51 | end |
|
51 | end |
|
52 |
|
52 | ||
|
53 | if params[:commit] == 'download csv' then |
|
53 | if params[:commit] == 'download csv' then |
|
54 | csv = gen_csv_from_scorearray(@scorearray,@problems) |
|
54 | csv = gen_csv_from_scorearray(@scorearray,@problems) |
|
55 | send_data csv, filename: 'max_score.csv' |
|
55 | send_data csv, filename: 'max_score.csv' |
|
56 | else |
|
56 | else |
|
57 | #render template: 'user_admin/user_stat' |
|
57 | #render template: 'user_admin/user_stat' |
|
58 | render 'max_score' |
|
58 | render 'max_score' |
|
59 | end |
|
59 | end |
|
60 |
|
60 | ||
|
61 | end |
|
61 | end |
|
62 |
|
62 | ||
|
63 | def score |
|
63 | def score |
|
64 | if params[:commit] == 'download csv' |
|
64 | if params[:commit] == 'download csv' |
|
65 | @problems = Problem.all |
|
65 | @problems = Problem.all |
|
66 | else |
|
66 | else |
|
67 | @problems = Problem.find_available_problems |
|
67 | @problems = Problem.find_available_problems |
|
68 | end |
|
68 | end |
|
69 | @users = User.includes(:contests, :contest_stat).where(enabled: true) #find(:all, :include => [:contests, :contest_stat]).where(enabled: true) |
|
69 | @users = User.includes(:contests, :contest_stat).where(enabled: true) #find(:all, :include => [:contests, :contest_stat]).where(enabled: true) |
|
70 | @scorearray = Array.new |
|
70 | @scorearray = Array.new |
|
71 | @users.each do |u| |
|
71 | @users.each do |u| |
|
72 | ustat = Array.new |
|
72 | ustat = Array.new |
|
73 | ustat[0] = u |
|
73 | ustat[0] = u |
|
74 | @problems.each do |p| |
|
74 | @problems.each do |p| |
|
75 | sub = Submission.find_last_by_user_and_problem(u.id,p.id) |
|
75 | sub = Submission.find_last_by_user_and_problem(u.id,p.id) |
|
76 | if (sub!=nil) and (sub.points!=nil) and p and p.full_score |
|
76 | if (sub!=nil) and (sub.points!=nil) and p and p.full_score |
|
77 | ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)] |
|
77 | ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)] |
|
78 | else |
|
78 | else |
|
79 | ustat << [0,false] |
|
79 | ustat << [0,false] |
|
80 | end |
|
80 | end |
|
81 | end |
|
81 | end |
|
82 | @scorearray << ustat |
|
82 | @scorearray << ustat |
|
83 | end |
|
83 | end |
|
84 | if params[:commit] == 'download csv' then |
|
84 | if params[:commit] == 'download csv' then |
|
85 | csv = gen_csv_from_scorearray(@scorearray,@problems) |
|
85 | csv = gen_csv_from_scorearray(@scorearray,@problems) |
|
86 | send_data csv, filename: 'last_score.csv' |
|
86 | send_data csv, filename: 'last_score.csv' |
|
87 | else |
|
87 | else |
|
88 | render template: 'user_admin/user_stat' |
|
88 | render template: 'user_admin/user_stat' |
|
89 | end |
|
89 | end |
|
90 |
|
90 | ||
|
91 | end |
|
91 | end |
|
92 |
|
92 | ||
|
93 | def login_stat |
|
93 | def login_stat |
|
94 | @logins = Array.new |
|
94 | @logins = Array.new |
|
95 |
|
95 | ||
|
96 | date_and_time = '%Y-%m-%d %H:%M' |
|
96 | date_and_time = '%Y-%m-%d %H:%M' |
|
97 | begin |
|
97 | begin |
|
98 | md = params[:since_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/) |
|
98 | md = params[:since_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/) |
|
99 | @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) |
|
99 | @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) |
You need to be logged in to leave comments.
Login now