Description:
- update 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

r594:ad5ce58ac280 - - 4 files changed: 71 inserted, 19 deleted

new file 100644
@@ -1,443 +1,452
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]
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 show_max_score
15 + def max_score
16 end
16 end
17
17
18 - def get_max_score
18 + def show_max_score
19 - #process list of problems
19 + #process parameters
20 + #problems
21 + @problems = []
22 + params[:problem_id].each do |id|
23 + next unless id.strip != ""
24 + @problems << Problem.find(id.to_i)
25 + end
20
26
21 - #process submission range
27 + #users
22 - if params[:commit] == 'download csv'
28 + @users = if params[:user] == "all" then
23 - @problems = Problem.all
29 + User.find(:all, :include => [:contests, :contest_stat])
24 - else
30 + else
25 - @problems = Problem.find_available_problems
31 + User.includes(:contests).includes(:contest_stat).where(enabled: true)
26 - end
32 + end
27 - @users = User.find(:all, :include => [:contests, :contest_stat])
33 +
34 + #set up range from param
35 + since_id = params.fetch(:min_id, 0).to_i
36 + until_id = params.fetch(:max_id, 0).to_i
37 +
38 + #get data
28 @scorearray = Array.new
39 @scorearray = Array.new
29 - #set up range from param
30 - since_id = params.fetch(:since_id, 0).to_i
31 - until_id = params.fetch(:until_id, 0).to_i
32 @users.each do |u|
40 @users.each do |u|
33 ustat = Array.new
41 ustat = Array.new
34 ustat[0] = u
42 ustat[0] = u
35 @problems.each do |p|
43 @problems.each do |p|
36 max_points = 0
44 max_points = 0
37 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|
38 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)
39 end
47 end
40 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)]
41 end
49 end
42 @scorearray << ustat
50 @scorearray << ustat
43 end
51 end
44
52
45 if params[:commit] == 'download csv' then
53 if params[:commit] == 'download csv' then
46 csv = gen_csv_from_scorearray(@scorearray,@problems)
54 csv = gen_csv_from_scorearray(@scorearray,@problems)
47 send_data csv, filename: 'max_score.csv'
55 send_data csv, filename: 'max_score.csv'
48 else
56 else
49 - render template: 'user_admin/user_stat'
57 + #render template: 'user_admin/user_stat'
58 + render 'max_score'
50 end
59 end
51
60
52 end
61 end
53
62
54 def score
63 def score
55 if params[:commit] == 'download csv'
64 if params[:commit] == 'download csv'
56 @problems = Problem.all
65 @problems = Problem.all
57 else
66 else
58 @problems = Problem.find_available_problems
67 @problems = Problem.find_available_problems
59 end
68 end
60 @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)
61 @scorearray = Array.new
70 @scorearray = Array.new
62 @users.each do |u|
71 @users.each do |u|
63 ustat = Array.new
72 ustat = Array.new
64 ustat[0] = u
73 ustat[0] = u
65 @problems.each do |p|
74 @problems.each do |p|
66 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)
67 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
68 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)]
69 else
78 else
70 ustat << [0,false]
79 ustat << [0,false]
71 end
80 end
72 end
81 end
73 @scorearray << ustat
82 @scorearray << ustat
74 end
83 end
75 if params[:commit] == 'download csv' then
84 if params[:commit] == 'download csv' then
76 csv = gen_csv_from_scorearray(@scorearray,@problems)
85 csv = gen_csv_from_scorearray(@scorearray,@problems)
77 send_data csv, filename: 'last_score.csv'
86 send_data csv, filename: 'last_score.csv'
78 else
87 else
79 render template: 'user_admin/user_stat'
88 render template: 'user_admin/user_stat'
80 end
89 end
81
90
82 end
91 end
83
92
84 def login_stat
93 def login_stat
85 @logins = Array.new
94 @logins = Array.new
86
95
87 date_and_time = '%Y-%m-%d %H:%M'
96 date_and_time = '%Y-%m-%d %H:%M'
88 begin
97 begin
89 md = params[:since_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
98 md = params[:since_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
90 @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)
91 rescue
100 rescue
92 @since_time = DateTime.new(1000,1,1)
101 @since_time = DateTime.new(1000,1,1)
93 end
102 end
94 begin
103 begin
95 md = params[:until_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
104 md = params[:until_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
96 @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)
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)
97 rescue
106 rescue
98 @until_time = DateTime.new(3000,1,1)
107 @until_time = DateTime.new(3000,1,1)
99 end
108 end
100
109
101 User.all.each do |user|
110 User.all.each do |user|
102 @logins << { id: user.id,
111 @logins << { id: user.id,
103 login: user.login,
112 login: user.login,
104 full_name: user.full_name,
113 full_name: user.full_name,
105 count: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?",
114 count: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?",
106 user.id,@since_time,@until_time)
115 user.id,@since_time,@until_time)
107 .count(:id),
116 .count(:id),
108 min: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?",
117 min: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?",
109 user.id,@since_time,@until_time)
118 user.id,@since_time,@until_time)
110 .minimum(:created_at),
119 .minimum(:created_at),
111 max: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?",
120 max: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?",
112 user.id,@since_time,@until_time)
121 user.id,@since_time,@until_time)
113 .maximum(:created_at),
122 .maximum(:created_at),
114 ip: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?",
123 ip: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?",
115 user.id,@since_time,@until_time)
124 user.id,@since_time,@until_time)
116 .select(:ip_address).uniq
125 .select(:ip_address).uniq
117
126
118 }
127 }
119 end
128 end
120 end
129 end
121
130
122 def submission_stat
131 def submission_stat
123
132
124 date_and_time = '%Y-%m-%d %H:%M'
133 date_and_time = '%Y-%m-%d %H:%M'
125 begin
134 begin
126 @since_time = DateTime.strptime(params[:since_datetime],date_and_time)
135 @since_time = DateTime.strptime(params[:since_datetime],date_and_time)
127 rescue
136 rescue
128 @since_time = DateTime.new(1000,1,1)
137 @since_time = DateTime.new(1000,1,1)
129 end
138 end
130 begin
139 begin
131 @until_time = DateTime.strptime(params[:until_datetime],date_and_time)
140 @until_time = DateTime.strptime(params[:until_datetime],date_and_time)
132 rescue
141 rescue
133 @until_time = DateTime.new(3000,1,1)
142 @until_time = DateTime.new(3000,1,1)
134 end
143 end
135
144
136 @submissions = {}
145 @submissions = {}
137
146
138 User.find_each do |user|
147 User.find_each do |user|
139 @submissions[user.id] = { login: user.login, full_name: user.full_name, count: 0, sub: { } }
148 @submissions[user.id] = { login: user.login, full_name: user.full_name, count: 0, sub: { } }
140 end
149 end
141
150
142 Submission.where("submitted_at >= ? AND submitted_at <= ?",@since_time,@until_time).find_each do |s|
151 Submission.where("submitted_at >= ? AND submitted_at <= ?",@since_time,@until_time).find_each do |s|
143 if @submissions[s.user_id]
152 if @submissions[s.user_id]
144 if not @submissions[s.user_id][:sub].has_key?(s.problem_id)
153 if not @submissions[s.user_id][:sub].has_key?(s.problem_id)
145 a = Problem.find_by_id(s.problem_id)
154 a = Problem.find_by_id(s.problem_id)
146 @submissions[s.user_id][:sub][s.problem_id] =
155 @submissions[s.user_id][:sub][s.problem_id] =
147 { prob_name: (a ? a.full_name : '(NULL)'),
156 { prob_name: (a ? a.full_name : '(NULL)'),
148 sub_ids: [s.id] }
157 sub_ids: [s.id] }
149 else
158 else
150 @submissions[s.user_id][:sub][s.problem_id][:sub_ids] << s.id
159 @submissions[s.user_id][:sub][s.problem_id][:sub_ids] << s.id
151 end
160 end
152 @submissions[s.user_id][:count] += 1
161 @submissions[s.user_id][:count] += 1
153 end
162 end
154 end
163 end
155 end
164 end
156
165
157 def problem_hof
166 def problem_hof
158 # gen problem list
167 # gen problem list
159 @user = User.find(session[:user_id])
168 @user = User.find(session[:user_id])
160 @problems = @user.available_problems
169 @problems = @user.available_problems
161
170
162 # get selected problems or the default
171 # get selected problems or the default
163 if params[:id]
172 if params[:id]
164 begin
173 begin
165 @problem = Problem.available.find(params[:id])
174 @problem = Problem.available.find(params[:id])
166 rescue
175 rescue
167 redirect_to action: :problem_hof
176 redirect_to action: :problem_hof
168 flash[:notice] = 'Error: submissions for that problem are not viewable.'
177 flash[:notice] = 'Error: submissions for that problem are not viewable.'
169 return
178 return
170 end
179 end
171 end
180 end
172
181
173 return unless @problem
182 return unless @problem
174
183
175 @by_lang = {} #aggregrate by language
184 @by_lang = {} #aggregrate by language
176
185
177 range =65
186 range =65
178 @histogram = { data: Array.new(range,0), summary: {} }
187 @histogram = { data: Array.new(range,0), summary: {} }
179 @summary = {count: 0, solve: 0, attempt: 0}
188 @summary = {count: 0, solve: 0, attempt: 0}
180 user = Hash.new(0)
189 user = Hash.new(0)
181 Submission.where(problem_id: @problem.id).find_each do |sub|
190 Submission.where(problem_id: @problem.id).find_each do |sub|
182 #histogram
191 #histogram
183 d = (DateTime.now.in_time_zone - sub.submitted_at) / 24 / 60 / 60
192 d = (DateTime.now.in_time_zone - sub.submitted_at) / 24 / 60 / 60
184 @histogram[:data][d.to_i] += 1 if d < range
193 @histogram[:data][d.to_i] += 1 if d < range
185
194
186 next unless sub.points
195 next unless sub.points
187 @summary[:count] += 1
196 @summary[:count] += 1
188 user[sub.user_id] = [user[sub.user_id], (sub.points >= @problem.full_score) ? 1 : 0].max
197 user[sub.user_id] = [user[sub.user_id], (sub.points >= @problem.full_score) ? 1 : 0].max
189
198
190 lang = Language.find_by_id(sub.language_id)
199 lang = Language.find_by_id(sub.language_id)
191 next unless lang
200 next unless lang
192 next unless sub.points >= @problem.full_score
201 next unless sub.points >= @problem.full_score
193
202
194 #initialize
203 #initialize
195 unless @by_lang.has_key?(lang.pretty_name)
204 unless @by_lang.has_key?(lang.pretty_name)
196 @by_lang[lang.pretty_name] = {
205 @by_lang[lang.pretty_name] = {
197 runtime: { avail: false, value: 2**30-1 },
206 runtime: { avail: false, value: 2**30-1 },
198 memory: { avail: false, value: 2**30-1 },
207 memory: { avail: false, value: 2**30-1 },
199 length: { avail: false, value: 2**30-1 },
208 length: { avail: false, value: 2**30-1 },
200 first: { avail: false, value: DateTime.new(3000,1,1) }
209 first: { avail: false, value: DateTime.new(3000,1,1) }
201 }
210 }
202 end
211 end
203
212
204 if sub.max_runtime and sub.max_runtime < @by_lang[lang.pretty_name][:runtime][:value]
213 if sub.max_runtime and sub.max_runtime < @by_lang[lang.pretty_name][:runtime][:value]
205 @by_lang[lang.pretty_name][:runtime] = { avail: true, user_id: sub.user_id, value: sub.max_runtime, sub_id: sub.id }
214 @by_lang[lang.pretty_name][:runtime] = { avail: true, user_id: sub.user_id, value: sub.max_runtime, sub_id: sub.id }
206 end
215 end
207
216
208 if sub.peak_memory and sub.peak_memory < @by_lang[lang.pretty_name][:memory][:value]
217 if sub.peak_memory and sub.peak_memory < @by_lang[lang.pretty_name][:memory][:value]
209 @by_lang[lang.pretty_name][:memory] = { avail: true, user_id: sub.user_id, value: sub.peak_memory, sub_id: sub.id }
218 @by_lang[lang.pretty_name][:memory] = { avail: true, user_id: sub.user_id, value: sub.peak_memory, sub_id: sub.id }
210 end
219 end
211
220
212 if sub.submitted_at and sub.submitted_at < @by_lang[lang.pretty_name][:first][:value] and
221 if sub.submitted_at and sub.submitted_at < @by_lang[lang.pretty_name][:first][:value] and
213 !sub.user.admin?
222 !sub.user.admin?
214 @by_lang[lang.pretty_name][:first] = { avail: true, user_id: sub.user_id, value: sub.submitted_at, sub_id: sub.id }
223 @by_lang[lang.pretty_name][:first] = { avail: true, user_id: sub.user_id, value: sub.submitted_at, sub_id: sub.id }
215 end
224 end
216
225
217 if @by_lang[lang.pretty_name][:length][:value] > sub.effective_code_length
226 if @by_lang[lang.pretty_name][:length][:value] > sub.effective_code_length
218 @by_lang[lang.pretty_name][:length] = { avail: true, user_id: sub.user_id, value: sub.effective_code_length, sub_id: sub.id }
227 @by_lang[lang.pretty_name][:length] = { avail: true, user_id: sub.user_id, value: sub.effective_code_length, sub_id: sub.id }
219 end
228 end
220 end
229 end
221
230
222 #process user_id
231 #process user_id
223 @by_lang.each do |lang,prop|
232 @by_lang.each do |lang,prop|
224 prop.each do |k,v|
233 prop.each do |k,v|
225 v[:user] = User.exists?(v[:user_id]) ? User.find(v[:user_id]).full_name : "(NULL)"
234 v[:user] = User.exists?(v[:user_id]) ? User.find(v[:user_id]).full_name : "(NULL)"
226 end
235 end
227 end
236 end
228
237
229 #sum into best
238 #sum into best
230 if @by_lang and @by_lang.first
239 if @by_lang and @by_lang.first
231 @best = @by_lang.first[1].clone
240 @best = @by_lang.first[1].clone
232 @by_lang.each do |lang,prop|
241 @by_lang.each do |lang,prop|
233 if @best[:runtime][:value] >= prop[:runtime][:value]
242 if @best[:runtime][:value] >= prop[:runtime][:value]
234 @best[:runtime] = prop[:runtime]
243 @best[:runtime] = prop[:runtime]
235 @best[:runtime][:lang] = lang
244 @best[:runtime][:lang] = lang
236 end
245 end
237 if @best[:memory][:value] >= prop[:memory][:value]
246 if @best[:memory][:value] >= prop[:memory][:value]
238 @best[:memory] = prop[:memory]
247 @best[:memory] = prop[:memory]
239 @best[:memory][:lang] = lang
248 @best[:memory][:lang] = lang
240 end
249 end
241 if @best[:length][:value] >= prop[:length][:value]
250 if @best[:length][:value] >= prop[:length][:value]
242 @best[:length] = prop[:length]
251 @best[:length] = prop[:length]
243 @best[:length][:lang] = lang
252 @best[:length][:lang] = lang
244 end
253 end
245 if @best[:first][:value] >= prop[:first][:value]
254 if @best[:first][:value] >= prop[:first][:value]
246 @best[:first] = prop[:first]
255 @best[:first] = prop[:first]
247 @best[:first][:lang] = lang
256 @best[:first][:lang] = lang
248 end
257 end
249 end
258 end
250 end
259 end
251
260
252 @histogram[:summary][:max] = [@histogram[:data].max,1].max
261 @histogram[:summary][:max] = [@histogram[:data].max,1].max
253 @summary[:attempt] = user.count
262 @summary[:attempt] = user.count
254 user.each_value { |v| @summary[:solve] += 1 if v == 1 }
263 user.each_value { |v| @summary[:solve] += 1 if v == 1 }
255 end
264 end
256
265
257 def stuck #report struggling user,problem
266 def stuck #report struggling user,problem
258 # init
267 # init
259 user,problem = nil
268 user,problem = nil
260 solve = true
269 solve = true
261 tries = 0
270 tries = 0
262 @struggle = Array.new
271 @struggle = Array.new
263 record = {}
272 record = {}
264 Submission.includes(:problem,:user).order(:problem_id,:user_id).find_each do |sub|
273 Submission.includes(:problem,:user).order(:problem_id,:user_id).find_each do |sub|
265 next unless sub.problem and sub.user
274 next unless sub.problem and sub.user
266 if user != sub.user_id or problem != sub.problem_id
275 if user != sub.user_id or problem != sub.problem_id
267 @struggle << { user: record[:user], problem: record[:problem], tries: tries } unless solve
276 @struggle << { user: record[:user], problem: record[:problem], tries: tries } unless solve
268 record = {user: sub.user, problem: sub.problem}
277 record = {user: sub.user, problem: sub.problem}
269 user,problem = sub.user_id, sub.problem_id
278 user,problem = sub.user_id, sub.problem_id
270 solve = false
279 solve = false
271 tries = 0
280 tries = 0
272 end
281 end
273 if sub.points >= sub.problem.full_score
282 if sub.points >= sub.problem.full_score
274 solve = true
283 solve = true
275 else
284 else
276 tries += 1
285 tries += 1
277 end
286 end
278 end
287 end
279 @struggle.sort!{|a,b| b[:tries] <=> a[:tries] }
288 @struggle.sort!{|a,b| b[:tries] <=> a[:tries] }
280 @struggle = @struggle[0..50]
289 @struggle = @struggle[0..50]
281 end
290 end
282
291
283
292
284 def multiple_login
293 def multiple_login
285 #user with multiple IP
294 #user with multiple IP
286 raw = Submission.joins(:user).joins(:problem).where("problems.available != 0").group("login,ip_address").order(:login)
295 raw = Submission.joins(:user).joins(:problem).where("problems.available != 0").group("login,ip_address").order(:login)
287 last,count = 0,0
296 last,count = 0,0
288 first = 0
297 first = 0
289 @users = []
298 @users = []
290 raw.each do |r|
299 raw.each do |r|
291 if last != r.user.login
300 if last != r.user.login
292 count = 1
301 count = 1
293 last = r.user.login
302 last = r.user.login
294 first = r
303 first = r
295 else
304 else
296 @users << first if count == 1
305 @users << first if count == 1
297 @users << r
306 @users << r
298 count += 1
307 count += 1
299 end
308 end
300 end
309 end
301
310
302 #IP with multiple user
311 #IP with multiple user
303 raw = Submission.joins(:user).joins(:problem).where("problems.available != 0").group("login,ip_address").order(:ip_address)
312 raw = Submission.joins(:user).joins(:problem).where("problems.available != 0").group("login,ip_address").order(:ip_address)
304 last,count = 0,0
313 last,count = 0,0
305 first = 0
314 first = 0
306 @ip = []
315 @ip = []
307 raw.each do |r|
316 raw.each do |r|
308 if last != r.ip_address
317 if last != r.ip_address
309 count = 1
318 count = 1
310 last = r.ip_address
319 last = r.ip_address
311 first = r
320 first = r
312 else
321 else
313 @ip << first if count == 1
322 @ip << first if count == 1
314 @ip << r
323 @ip << r
315 count += 1
324 count += 1
316 end
325 end
317 end
326 end
318 end
327 end
319
328
320 def cheat_report
329 def cheat_report
321 date_and_time = '%Y-%m-%d %H:%M'
330 date_and_time = '%Y-%m-%d %H:%M'
322 begin
331 begin
323 md = params[:since_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
332 md = params[:since_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
324 @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)
333 @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)
325 rescue
334 rescue
326 @since_time = Time.zone.now.ago( 90.minutes)
335 @since_time = Time.zone.now.ago( 90.minutes)
327 end
336 end
328 begin
337 begin
329 md = params[:until_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
338 md = params[:until_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
330 @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)
339 @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)
331 rescue
340 rescue
332 @until_time = Time.zone.now
341 @until_time = Time.zone.now
333 end
342 end
334
343
335 #multi login
344 #multi login
336 @ml = Login.joins(:user).where("logins.created_at >= ? and logins.created_at <= ?",@since_time,@until_time).select('users.login,count(distinct ip_address) as count,users.full_name').group("users.id").having("count > 1")
345 @ml = Login.joins(:user).where("logins.created_at >= ? and logins.created_at <= ?",@since_time,@until_time).select('users.login,count(distinct ip_address) as count,users.full_name').group("users.id").having("count > 1")
337
346
338 st = <<-SQL
347 st = <<-SQL
339 SELECT l2.*
348 SELECT l2.*
340 FROM logins l2 INNER JOIN
349 FROM logins l2 INNER JOIN
341 (SELECT u.id,COUNT(DISTINCT ip_address) as count,u.login,u.full_name
350 (SELECT u.id,COUNT(DISTINCT ip_address) as count,u.login,u.full_name
342 FROM logins l
351 FROM logins l
343 INNER JOIN users u ON l.user_id = u.id
352 INNER JOIN users u ON l.user_id = u.id
344 WHERE l.created_at >= '#{@since_time.in_time_zone("UTC")}' and l.created_at <= '#{@until_time.in_time_zone("UTC")}'
353 WHERE l.created_at >= '#{@since_time.in_time_zone("UTC")}' and l.created_at <= '#{@until_time.in_time_zone("UTC")}'
345 GROUP BY u.id
354 GROUP BY u.id
346 HAVING count > 1
355 HAVING count > 1
347 ) ml ON l2.user_id = ml.id
356 ) ml ON l2.user_id = ml.id
348 WHERE l2.created_at >= '#{@since_time.in_time_zone("UTC")}' and l2.created_at <= '#{@until_time.in_time_zone("UTC")}'
357 WHERE l2.created_at >= '#{@since_time.in_time_zone("UTC")}' and l2.created_at <= '#{@until_time.in_time_zone("UTC")}'
349 UNION
358 UNION
350 SELECT l2.*
359 SELECT l2.*
351 FROM logins l2 INNER JOIN
360 FROM logins l2 INNER JOIN
352 (SELECT l.ip_address,COUNT(DISTINCT u.id) as count
361 (SELECT l.ip_address,COUNT(DISTINCT u.id) as count
353 FROM logins l
362 FROM logins l
354 INNER JOIN users u ON l.user_id = u.id
363 INNER JOIN users u ON l.user_id = u.id
355 WHERE l.created_at >= '#{@since_time.in_time_zone("UTC")}' and l.created_at <= '#{@until_time.in_time_zone("UTC")}'
364 WHERE l.created_at >= '#{@since_time.in_time_zone("UTC")}' and l.created_at <= '#{@until_time.in_time_zone("UTC")}'
356 GROUP BY l.ip_address
365 GROUP BY l.ip_address
357 HAVING count > 1
366 HAVING count > 1
358 ) ml on ml.ip_address = l2.ip_address
367 ) ml on ml.ip_address = l2.ip_address
359 INNER JOIN users u ON l2.user_id = u.id
368 INNER JOIN users u ON l2.user_id = u.id
360 WHERE l2.created_at >= '#{@since_time.in_time_zone("UTC")}' and l2.created_at <= '#{@until_time.in_time_zone("UTC")}'
369 WHERE l2.created_at >= '#{@since_time.in_time_zone("UTC")}' and l2.created_at <= '#{@until_time.in_time_zone("UTC")}'
361 ORDER BY ip_address,created_at
370 ORDER BY ip_address,created_at
362 SQL
371 SQL
363 @mld = Login.find_by_sql(st)
372 @mld = Login.find_by_sql(st)
364
373
365 st = <<-SQL
374 st = <<-SQL
366 SELECT s.id,s.user_id,s.ip_address,s.submitted_at,s.problem_id
375 SELECT s.id,s.user_id,s.ip_address,s.submitted_at,s.problem_id
367 FROM submissions s INNER JOIN
376 FROM submissions s INNER JOIN
368 (SELECT u.id,COUNT(DISTINCT ip_address) as count,u.login,u.full_name
377 (SELECT u.id,COUNT(DISTINCT ip_address) as count,u.login,u.full_name
369 FROM logins l
378 FROM logins l
370 INNER JOIN users u ON l.user_id = u.id
379 INNER JOIN users u ON l.user_id = u.id
371 WHERE l.created_at >= ? and l.created_at <= ?
380 WHERE l.created_at >= ? and l.created_at <= ?
372 GROUP BY u.id
381 GROUP BY u.id
373 HAVING count > 1
382 HAVING count > 1
374 ) ml ON s.user_id = ml.id
383 ) ml ON s.user_id = ml.id
375 WHERE s.submitted_at >= ? and s.submitted_at <= ?
384 WHERE s.submitted_at >= ? and s.submitted_at <= ?
376 UNION
385 UNION
377 SELECT s.id,s.user_id,s.ip_address,s.submitted_at,s.problem_id
386 SELECT s.id,s.user_id,s.ip_address,s.submitted_at,s.problem_id
378 FROM submissions s INNER JOIN
387 FROM submissions s INNER JOIN
379 (SELECT l.ip_address,COUNT(DISTINCT u.id) as count
388 (SELECT l.ip_address,COUNT(DISTINCT u.id) as count
380 FROM logins l
389 FROM logins l
381 INNER JOIN users u ON l.user_id = u.id
390 INNER JOIN users u ON l.user_id = u.id
382 WHERE l.created_at >= ? and l.created_at <= ?
391 WHERE l.created_at >= ? and l.created_at <= ?
383 GROUP BY l.ip_address
392 GROUP BY l.ip_address
384 HAVING count > 1
393 HAVING count > 1
385 ) ml on ml.ip_address = s.ip_address
394 ) ml on ml.ip_address = s.ip_address
386 WHERE s.submitted_at >= ? and s.submitted_at <= ?
395 WHERE s.submitted_at >= ? and s.submitted_at <= ?
387 ORDER BY ip_address,submitted_at
396 ORDER BY ip_address,submitted_at
388 SQL
397 SQL
389 @subs = Submission.joins(:problem).find_by_sql([st,@since_time,@until_time,
398 @subs = Submission.joins(:problem).find_by_sql([st,@since_time,@until_time,
390 @since_time,@until_time,
399 @since_time,@until_time,
391 @since_time,@until_time,
400 @since_time,@until_time,
392 @since_time,@until_time])
401 @since_time,@until_time])
393
402
394 end
403 end
395
404
396 def cheat_scruntinize
405 def cheat_scruntinize
397 #convert date & time
406 #convert date & time
398 date_and_time = '%Y-%m-%d %H:%M'
407 date_and_time = '%Y-%m-%d %H:%M'
399 begin
408 begin
400 md = params[:since_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
409 md = params[:since_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
401 @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)
410 @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)
402 rescue
411 rescue
403 @since_time = Time.zone.now.ago( 90.minutes)
412 @since_time = Time.zone.now.ago( 90.minutes)
404 end
413 end
405 begin
414 begin
406 md = params[:until_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
415 md = params[:until_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
407 @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)
416 @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)
408 rescue
417 rescue
409 @until_time = Time.zone.now
418 @until_time = Time.zone.now
410 end
419 end
411
420
412 #convert sid
421 #convert sid
413 @sid = params[:SID].split(/[,\s]/) if params[:SID]
422 @sid = params[:SID].split(/[,\s]/) if params[:SID]
414 unless @sid and @sid.size > 0
423 unless @sid and @sid.size > 0
415 return
424 return
416 redirect_to actoin: :cheat_scruntinize
425 redirect_to actoin: :cheat_scruntinize
417 flash[:notice] = 'Please enter at least 1 student id'
426 flash[:notice] = 'Please enter at least 1 student id'
418 end
427 end
419 mark = Array.new(@sid.size,'?')
428 mark = Array.new(@sid.size,'?')
420 condition = "(u.login = " + mark.join(' OR u.login = ') + ')'
429 condition = "(u.login = " + mark.join(' OR u.login = ') + ')'
421
430
422 @st = <<-SQL
431 @st = <<-SQL
423 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
432 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
424 FROM logins l INNER JOIN users u on l.user_id = u.id
433 FROM logins l INNER JOIN users u on l.user_id = u.id
425 WHERE l.created_at >= ? AND l.created_at <= ? AND #{condition}
434 WHERE l.created_at >= ? AND l.created_at <= ? AND #{condition}
426 UNION
435 UNION
427 SELECT s.submitted_at,s.id,u.login,u.full_name,s.ip_address,s.problem_id,s.points,s.user_id
436 SELECT s.submitted_at,s.id,u.login,u.full_name,s.ip_address,s.problem_id,s.points,s.user_id
428 FROM submissions s INNER JOIN users u ON s.user_id = u.id
437 FROM submissions s INNER JOIN users u ON s.user_id = u.id
429 WHERE s.submitted_at >= ? AND s.submitted_at <= ? AND #{condition}
438 WHERE s.submitted_at >= ? AND s.submitted_at <= ? AND #{condition}
430 ORDER BY submitted_at
439 ORDER BY submitted_at
431 SQL
440 SQL
432
441
433 p = [@st,@since_time,@until_time] + @sid + [@since_time,@until_time] + @sid
442 p = [@st,@since_time,@until_time] + @sid + [@since_time,@until_time] + @sid
434 @logs = Submission.joins(:problem).find_by_sql(p)
443 @logs = Submission.joins(:problem).find_by_sql(p)
435
444
436
445
437
446
438
447
439
448
440 end
449 end
441
450
442
451
443 end
452 end
@@ -1,43 +1,85
1 %h1 Maximum score
1 %h1 Maximum score
2
2
3 - = form_tag report_max_score_path
3 + = form_tag report_show_max_score_path
4 .row
4 .row
5 .col-md-4
5 .col-md-4
6 .panel.panel-primary
6 .panel.panel-primary
7 .panel-heading
7 .panel-heading
8 Problems
8 Problems
9 .panel-body
9 .panel-body
10 - = label_tag :problems, "Problems"
10 + %p
11 - = select 'problems', 'problem_id', [[(t 'main.specified_in_header'),'-1']] + Problem.all.collect {|p| ["[#{p.name}] #{p.full_name}", p.id]}, {:selected => '-1'}, { class: 'select2 form-control' }
11 + Select problem(s) that we wish to know the score.
12 + = label_tag :problem_id, "Problems"
13 + = select_tag 'problem_id[]',
14 + options_for_select(Problem.all.collect {|p| ["[#{p.name}] #{p.full_name}", p.id]}),
15 + { class: 'select2 form-control', multiple: "true" }
12 .col-md-4
16 .col-md-4
13 .panel.panel-primary
17 .panel.panel-primary
14 .panel-heading
18 .panel-heading
15 Submission range
19 Submission range
16 .panel-body
20 .panel-body
21 + %p
22 + Input minimum and maximum range of submission ID that should be included. A blank value for min and max means -1 and infinity, respectively.
17 .form-group
23 .form-group
18 - = label_tag :from, "From"
24 + = label_tag :from, "Min"
19 = text_field_tag 'from_id', nil, class: "form-control"
25 = text_field_tag 'from_id', nil, class: "form-control"
20 .form-group
26 .form-group
21 - = label_tag :from, "To"
27 + = label_tag :from, "Max"
22 = text_field_tag 'to_id', nil, class: "form-control"
28 = text_field_tag 'to_id', nil, class: "form-control"
23 .col-md-4
29 .col-md-4
24 .panel.panel-primary
30 .panel.panel-primary
25 .panel-heading
31 .panel-heading
26 Users
32 Users
27 .panel-body
33 .panel-body
28 .radio
34 .radio
29 %label
35 %label
30 = radio_button_tag 'users', 'all', true
36 = radio_button_tag 'users', 'all', true
31 All users
37 All users
32 .radio
38 .radio
33 %label
39 %label
34 = radio_button_tag 'users', 'enabled'
40 = radio_button_tag 'users', 'enabled'
35 Only enabled users
41 Only enabled users
36 .row
42 .row
37 .col-md-12
43 .col-md-12
38 = button_tag 'Show', class: "btn btn-primary btn-large"
44 = button_tag 'Show', class: "btn btn-primary btn-large"
39 = button_tag 'Download CSV', class: "btn btn-primary btn-large"
45 = button_tag 'Download CSV', class: "btn btn-primary btn-large"
46 +
47 + - if @scorearray
48 + %h2 Result
49 + %table.table.sortable.table-striped.table-bordered.table-condensed
50 + %thead
51 + %tr
52 + %th Login
53 + %th Name
54 + %th Activated?
55 + %th Logged_in
56 + %th Contest(s)
57 + %th Remark
58 + - @problems.each do |p|
59 + %th.text-right= p.name
60 + %th.text-right Total
61 + %th.text-right Passed
62 + %tbody
63 + - @scorearray.each do |sc|
64 + %tr
65 + - total,num_passed = 0,0
66 + - sc.each_index do |i|
67 + - if i == 0
68 + %td= link_to sc[i].login, controller: 'users', action: 'profile', id: sc[i]
69 + %td= sc[i].full_name
70 + %td= sc[i].activated
71 + %td= sc[i].try(:contest_stat).try(:started_at) ? 'yes' : 'no'
72 + %td= sc[i].contests.collect {|c| c.name}.join(', ')
73 + %td= sc[i].remark
74 + - else
75 + %td.text-right= sc[i][0]
76 + - total += sc[i][0]
77 + - num_passed += 1 if sc[i][1]
78 + %td.text-right= total
79 + %td.text-right= num_passed
80 + :javascript
81 + $.bootstrapSortable(true,'reversed')
40 /.col-md-4.col-md-offset-1
82 /.col-md-4.col-md-offset-1
41 / = button_tag 'Show', class: "btn btn-primary btn-block"
83 / = button_tag 'Show', class: "btn btn-primary btn-block"
42 /.col-md-4.col-md-offset-2
84 /.col-md-4.col-md-offset-2
43 / = button_tag 'Download CSV', class: "btn btn-primary btn-block"
85 / = button_tag 'Download CSV', class: "btn btn-primary btn-block"
@@ -1,67 +1,68
1 CafeGrader::Application.routes.draw do
1 CafeGrader::Application.routes.draw do
2 get "sources/direct_edit"
2 get "sources/direct_edit"
3
3
4 root :to => 'main#login'
4 root :to => 'main#login'
5
5
6 resources :contests
6 resources :contests
7
7
8 resources :sites
8 resources :sites
9
9
10 resources :announcements do
10 resources :announcements do
11 member do
11 member do
12 get 'toggle','toggle_front'
12 get 'toggle','toggle_front'
13 end
13 end
14 end
14 end
15
15
16 resources :problems do
16 resources :problems do
17 member do
17 member do
18 get 'toggle'
18 get 'toggle'
19 get 'toggle_test'
19 get 'toggle_test'
20 end
20 end
21 collection do
21 collection do
22 get 'turn_all_off'
22 get 'turn_all_off'
23 get 'turn_all_on'
23 get 'turn_all_on'
24 get 'import'
24 get 'import'
25 get 'manage'
25 get 'manage'
26 end
26 end
27 end
27 end
28
28
29 resources :grader_configuration, controller: 'configurations'
29 resources :grader_configuration, controller: 'configurations'
30
30
31 resources :users do
31 resources :users do
32 member do
32 member do
33 get 'toggle_activate', 'toggle_enable'
33 get 'toggle_activate', 'toggle_enable'
34 end
34 end
35 end
35 end
36
36
37 #source code edit
37 #source code edit
38 get 'sources/direct_edit/:pid', to: 'sources#direct_edit', as: 'direct_edit'
38 get 'sources/direct_edit/:pid', to: 'sources#direct_edit', as: 'direct_edit'
39 get 'sources/direct_edit_submission/:sid', to: 'sources#direct_edit_submission', as: 'direct_edit_submission'
39 get 'sources/direct_edit_submission/:sid', to: 'sources#direct_edit_submission', as: 'direct_edit_submission'
40 get 'sources/get_latest_submission_status/:uid/:pid', to: 'sources#get_latest_submission_status', as: 'get_latest_submission_status'
40 get 'sources/get_latest_submission_status/:uid/:pid', to: 'sources#get_latest_submission_status', as: 'get_latest_submission_status'
41
41
42
42
43 match 'tasks/view/:file.:ext' => 'tasks#view'
43 match 'tasks/view/:file.:ext' => 'tasks#view'
44 match 'tasks/download/:id/:file.:ext' => 'tasks#download'
44 match 'tasks/download/:id/:file.:ext' => 'tasks#download'
45 match 'heartbeat/:id/edit' => 'heartbeat#edit'
45 match 'heartbeat/:id/edit' => 'heartbeat#edit'
46
46
47 #main
47 #main
48 get "main/list"
48 get "main/list"
49 get 'main/submission(/:id)', to: 'main#submission', as: 'main_submission'
49 get 'main/submission(/:id)', to: 'main#submission', as: 'main_submission'
50
50
51 #report
51 #report
52 get 'report/problem_hof(/:id)', to: 'report#problem_hof', as: 'report_problem_hof'
52 get 'report/problem_hof(/:id)', to: 'report#problem_hof', as: 'report_problem_hof'
53 get "report/login"
53 get "report/login"
54 get 'report/max_score', to: 'report#max_score', as: 'report_max_score'
54 get 'report/max_score', to: 'report#max_score', as: 'report_max_score'
55 + post 'report/show_max_score', to: 'report#show_max_score', as: 'report_show_max_score'
55
56
56 #grader
57 #grader
57 get 'graders/list', to: 'graders#list', as: 'grader_list'
58 get 'graders/list', to: 'graders#list', as: 'grader_list'
58
59
59
60
60 match 'heartbeat/:id/edit' => 'heartbeat#edit'
61 match 'heartbeat/:id/edit' => 'heartbeat#edit'
61
62
62 # See how all your routes lay out with "rake routes"
63 # See how all your routes lay out with "rake routes"
63
64
64 # This is a legacy wild controller route that's not recommended for RESTful applications.
65 # This is a legacy wild controller route that's not recommended for RESTful applications.
65 # Note: This route will make all actions in every controller accessible via GET requests.
66 # Note: This route will make all actions in every controller accessible via GET requests.
66 match ':controller(/:action(/:id))(.:format)'
67 match ':controller(/:action(/:id))(.:format)'
67 end
68 end
You need to be logged in to leave comments. Login now