Description:
add authorization for show max score
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r595:ad86e593f5b0 - - 1 file changed: 1 inserted, 1 deleted

@@ -1,195 +1,195
1 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 5 before_filter(only: [:problem_hof]) { |c|
6 6 return false unless authenticate
7 7
8 8 if GraderConfiguration["right.user_view_submission"]
9 9 return true;
10 10 end
11 11
12 12 admin_authorization
13 13 }
14 14
15 15 def max_score
16 16 end
17 17
18 18 def show_max_score
19 19 #process parameters
20 20 #problems
21 21 @problems = []
22 22 params[:problem_id].each do |id|
23 23 next unless id.strip != ""
24 24 @problems << Problem.find(id.to_i)
25 25 end
26 26
27 27 #users
28 28 @users = if params[:user] == "all" then
29 29 User.find(:all, :include => [:contests, :contest_stat])
30 30 else
31 31 User.includes(:contests).includes(:contest_stat).where(enabled: true)
32 32 end
33 33
34 34 #set up range from param
35 35 since_id = params.fetch(:min_id, 0).to_i
36 36 until_id = params.fetch(:max_id, 0).to_i
37 37
38 38 #get data
39 39 @scorearray = Array.new
40 40 @users.each do |u|
41 41 ustat = Array.new
42 42 ustat[0] = u
43 43 @problems.each do |p|
44 44 max_points = 0
45 45 Submission.find_in_range_by_user_and_problem(u.id,p.id,since_id,until_id).each do |sub|
46 46 max_points = sub.points if sub and sub.points and (sub.points > max_points)
47 47 end
48 48 ustat << [(max_points.to_f*100/p.full_score).round, (max_points>=p.full_score)]
49 49 end
50 50 @scorearray << ustat
51 51 end
52 52
53 53 if params[:commit] == 'download csv' then
54 54 csv = gen_csv_from_scorearray(@scorearray,@problems)
55 55 send_data csv, filename: 'max_score.csv'
56 56 else
57 57 #render template: 'user_admin/user_stat'
58 58 render 'max_score'
59 59 end
60 60
61 61 end
62 62
63 63 def score
64 64 if params[:commit] == 'download csv'
65 65 @problems = Problem.all
66 66 else
67 67 @problems = Problem.find_available_problems
68 68 end
69 69 @users = User.includes(:contests, :contest_stat).where(enabled: true) #find(:all, :include => [:contests, :contest_stat]).where(enabled: true)
70 70 @scorearray = Array.new
71 71 @users.each do |u|
72 72 ustat = Array.new
73 73 ustat[0] = u
74 74 @problems.each do |p|
75 75 sub = Submission.find_last_by_user_and_problem(u.id,p.id)
76 76 if (sub!=nil) and (sub.points!=nil) and p and p.full_score
77 77 ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)]
78 78 else
79 79 ustat << [0,false]
80 80 end
81 81 end
82 82 @scorearray << ustat
83 83 end
84 84 if params[:commit] == 'download csv' then
85 85 csv = gen_csv_from_scorearray(@scorearray,@problems)
86 86 send_data csv, filename: 'last_score.csv'
87 87 else
88 88 render template: 'user_admin/user_stat'
89 89 end
90 90
91 91 end
92 92
93 93 def login_stat
94 94 @logins = Array.new
95 95
96 96 date_and_time = '%Y-%m-%d %H:%M'
97 97 begin
98 98 md = params[:since_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
99 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)
100 100 rescue
101 101 @since_time = DateTime.new(1000,1,1)
102 102 end
103 103 begin
104 104 md = params[:until_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
105 105 @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)
106 106 rescue
107 107 @until_time = DateTime.new(3000,1,1)
108 108 end
109 109
110 110 User.all.each do |user|
111 111 @logins << { id: user.id,
112 112 login: user.login,
113 113 full_name: user.full_name,
114 114 count: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?",
115 115 user.id,@since_time,@until_time)
116 116 .count(:id),
117 117 min: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?",
118 118 user.id,@since_time,@until_time)
119 119 .minimum(:created_at),
120 120 max: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?",
121 121 user.id,@since_time,@until_time)
122 122 .maximum(:created_at),
123 123 ip: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?",
124 124 user.id,@since_time,@until_time)
125 125 .select(:ip_address).uniq
126 126
127 127 }
128 128 end
129 129 end
130 130
131 131 def submission_stat
132 132
133 133 date_and_time = '%Y-%m-%d %H:%M'
134 134 begin
135 135 @since_time = DateTime.strptime(params[:since_datetime],date_and_time)
136 136 rescue
137 137 @since_time = DateTime.new(1000,1,1)
138 138 end
139 139 begin
140 140 @until_time = DateTime.strptime(params[:until_datetime],date_and_time)
141 141 rescue
142 142 @until_time = DateTime.new(3000,1,1)
143 143 end
144 144
145 145 @submissions = {}
146 146
147 147 User.find_each do |user|
148 148 @submissions[user.id] = { login: user.login, full_name: user.full_name, count: 0, sub: { } }
149 149 end
150 150
151 151 Submission.where("submitted_at >= ? AND submitted_at <= ?",@since_time,@until_time).find_each do |s|
152 152 if @submissions[s.user_id]
153 153 if not @submissions[s.user_id][:sub].has_key?(s.problem_id)
154 154 a = Problem.find_by_id(s.problem_id)
155 155 @submissions[s.user_id][:sub][s.problem_id] =
156 156 { prob_name: (a ? a.full_name : '(NULL)'),
157 157 sub_ids: [s.id] }
158 158 else
159 159 @submissions[s.user_id][:sub][s.problem_id][:sub_ids] << s.id
160 160 end
161 161 @submissions[s.user_id][:count] += 1
162 162 end
163 163 end
164 164 end
165 165
166 166 def problem_hof
167 167 # gen problem list
168 168 @user = User.find(session[:user_id])
169 169 @problems = @user.available_problems
170 170
171 171 # get selected problems or the default
172 172 if params[:id]
173 173 begin
174 174 @problem = Problem.available.find(params[:id])
175 175 rescue
176 176 redirect_to action: :problem_hof
177 177 flash[:notice] = 'Error: submissions for that problem are not viewable.'
178 178 return
179 179 end
180 180 end
181 181
182 182 return unless @problem
183 183
184 184 @by_lang = {} #aggregrate by language
185 185
186 186 range =65
187 187 @histogram = { data: Array.new(range,0), summary: {} }
188 188 @summary = {count: 0, solve: 0, attempt: 0}
189 189 user = Hash.new(0)
190 190 Submission.where(problem_id: @problem.id).find_each do |sub|
191 191 #histogram
192 192 d = (DateTime.now.in_time_zone - sub.submitted_at) / 24 / 60 / 60
193 193 @histogram[:data][d.to_i] += 1 if d < range
194 194
195 195 next unless sub.points
You need to be logged in to leave comments. Login now