Description:
add cheat detail
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r507:5af12f2a9a30 - - 2 files changed: 52 inserted, 20 deleted

@@ -1,27 +1,28
1 class ReportController < ApplicationController
1 class ReportController < ApplicationController
2
2
3 - before_filter :admin_authorization, only: [:login_stat,:submission_stat, :stuck]
3 + before_filter :admin_authorization, only: [:login_stat,:submission_stat, :stuck, :cheat_report, :cheat_scruntinize]
4 +
4 before_filter(only: [:problem_hof]) { |c|
5 before_filter(only: [:problem_hof]) { |c|
5 return false unless authenticate
6 return false unless authenticate
6
7
7 if GraderConfiguration["right.user_view_submission"]
8 if GraderConfiguration["right.user_view_submission"]
8 return true;
9 return true;
9 end
10 end
10
11
11 admin_authorization
12 admin_authorization
12 }
13 }
13
14
14 def login_stat
15 def login_stat
15 @logins = Array.new
16 @logins = Array.new
16
17
17 date_and_time = '%Y-%m-%d %H:%M'
18 date_and_time = '%Y-%m-%d %H:%M'
18 begin
19 begin
19 md = params[:since_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
20 md = params[:since_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
20 @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)
21 @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)
21 rescue
22 rescue
22 @since_time = DateTime.new(1000,1,1)
23 @since_time = DateTime.new(1000,1,1)
23 end
24 end
24 begin
25 begin
25 md = params[:until_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
26 md = params[:until_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
26 @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)
27 @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)
27 rescue
28 rescue
@@ -237,55 +238,55
237 #IP with multiple user
238 #IP with multiple user
238 raw = Submission.joins(:user).joins(:problem).where("problems.available != 0").group("login,ip_address").order(:ip_address)
239 raw = Submission.joins(:user).joins(:problem).where("problems.available != 0").group("login,ip_address").order(:ip_address)
239 last,count = 0,0
240 last,count = 0,0
240 first = 0
241 first = 0
241 @ip = []
242 @ip = []
242 raw.each do |r|
243 raw.each do |r|
243 if last != r.ip_address
244 if last != r.ip_address
244 count = 1
245 count = 1
245 last = r.ip_address
246 last = r.ip_address
246 first = r
247 first = r
247 else
248 else
248 @ip << first if count == 1
249 @ip << first if count == 1
249 @ip << r
250 @ip << r
250 count += 1
251 count += 1
251 end
252 end
252 end
253 end
253 end
254 end
254
255
255 def cheat_report
256 def cheat_report
256 date_and_time = '%Y-%m-%d %H:%M'
257 date_and_time = '%Y-%m-%d %H:%M'
257 begin
258 begin
258 md = params[:since_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
259 md = params[:since_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
259 @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)
260 @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)
260 rescue
261 rescue
261 - @since_time = Time.zone.now
262 + @since_time = Time.zone.now.ago( 90.minutes)
262 end
263 end
263 begin
264 begin
264 md = params[:until_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
265 md = params[:until_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
265 @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)
266 @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)
266 rescue
267 rescue
267 - @until_time = Time.zone.now.ago( 90.minutes)
268 + @until_time = Time.zone.now
268 end
269 end
269
270
270 #multi login
271 #multi login
271 @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")
272 @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")
272
273
273 st = <<-SQL
274 st = <<-SQL
274 SELECT l2.*
275 SELECT l2.*
275 FROM logins l2 INNER JOIN
276 FROM logins l2 INNER JOIN
276 (SELECT u.id,COUNT(DISTINCT ip_address) as count,u.login,u.full_name
277 (SELECT u.id,COUNT(DISTINCT ip_address) as count,u.login,u.full_name
277 FROM logins l
278 FROM logins l
278 INNER JOIN users u ON l.user_id = u.id
279 INNER JOIN users u ON l.user_id = u.id
279 WHERE l.created_at >= '#{@since_time.in_time_zone("UTC")}' and l.created_at <= '#{@until_time.in_time_zone("UTC")}'
280 WHERE l.created_at >= '#{@since_time.in_time_zone("UTC")}' and l.created_at <= '#{@until_time.in_time_zone("UTC")}'
280 GROUP BY u.id
281 GROUP BY u.id
281 HAVING count > 1
282 HAVING count > 1
282 ) ml ON l2.user_id = ml.id
283 ) ml ON l2.user_id = ml.id
283 WHERE l2.created_at >= '#{@since_time.in_time_zone("UTC")}' and l2.created_at <= '#{@until_time.in_time_zone("UTC")}'
284 WHERE l2.created_at >= '#{@since_time.in_time_zone("UTC")}' and l2.created_at <= '#{@until_time.in_time_zone("UTC")}'
284 UNION
285 UNION
285 SELECT l2.*
286 SELECT l2.*
286 FROM logins l2 INNER JOIN
287 FROM logins l2 INNER JOIN
287 (SELECT l.ip_address,COUNT(DISTINCT u.id) as count
288 (SELECT l.ip_address,COUNT(DISTINCT u.id) as count
288 FROM logins l
289 FROM logins l
289 INNER JOIN users u ON l.user_id = u.id
290 INNER JOIN users u ON l.user_id = u.id
290 WHERE l.created_at >= '#{@since_time.in_time_zone("UTC")}' and l.created_at <= '#{@until_time.in_time_zone("UTC")}'
291 WHERE l.created_at >= '#{@since_time.in_time_zone("UTC")}' and l.created_at <= '#{@until_time.in_time_zone("UTC")}'
291 GROUP BY l.ip_address
292 GROUP BY l.ip_address
@@ -305,44 +306,74
305 INNER JOIN users u ON l.user_id = u.id
306 INNER JOIN users u ON l.user_id = u.id
306 WHERE l.created_at >= ? and l.created_at <= ?
307 WHERE l.created_at >= ? and l.created_at <= ?
307 GROUP BY u.id
308 GROUP BY u.id
308 HAVING count > 1
309 HAVING count > 1
309 ) ml ON s.user_id = ml.id
310 ) ml ON s.user_id = ml.id
310 WHERE s.submitted_at >= ? and s.submitted_at <= ?
311 WHERE s.submitted_at >= ? and s.submitted_at <= ?
311 UNION
312 UNION
312 SELECT s.id,s.user_id,s.ip_address,s.submitted_at,s.problem_id
313 SELECT s.id,s.user_id,s.ip_address,s.submitted_at,s.problem_id
313 FROM submissions s INNER JOIN
314 FROM submissions s INNER JOIN
314 (SELECT l.ip_address,COUNT(DISTINCT u.id) as count
315 (SELECT l.ip_address,COUNT(DISTINCT u.id) as count
315 FROM logins l
316 FROM logins l
316 INNER JOIN users u ON l.user_id = u.id
317 INNER JOIN users u ON l.user_id = u.id
317 WHERE l.created_at >= ? and l.created_at <= ?
318 WHERE l.created_at >= ? and l.created_at <= ?
318 GROUP BY l.ip_address
319 GROUP BY l.ip_address
319 HAVING count > 1
320 HAVING count > 1
320 ) ml on ml.ip_address = s.ip_address
321 ) ml on ml.ip_address = s.ip_address
321 WHERE s.submitted_at >= ? and s.submitted_at <= ?
322 WHERE s.submitted_at >= ? and s.submitted_at <= ?
322 ORDER BY ip_address,submitted_at
323 ORDER BY ip_address,submitted_at
323 SQL
324 SQL
324 @subs = Submission.joins(:problem).find_by_sql([st,@since_time,@until_time,
325 @subs = Submission.joins(:problem).find_by_sql([st,@since_time,@until_time,
325 @since_time,@until_time,
326 @since_time,@until_time,
326 @since_time,@until_time,
327 @since_time,@until_time,
327 @since_time,@until_time])
328 @since_time,@until_time])
328
329
329 - # st =
330 + end
330 - # " INNER JOIN" +
331 +
331 - # "(SELECT u.id,l.ip_address,COUNT(DISTINCT ip_address) as count " +
332 + def cheat_scruntinize
332 - # " FROM logins l INNER JOIN users u ON l.user_id = u.id "+
333 + #convert date & time
333 - # " WHERE l.created_at >= '#{@since_time.in_time_zone("UTC")}' and l.created_at <= '#{@until_time.in_time_zone("UTC")}' " +
334 + date_and_time = '%Y-%m-%d %H:%M'
334 - # " GROUP BY u.id" +
335 + begin
335 - # " HAVING count > 1) ml "
336 + md = params[:since_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
336 - # #ml detail
337 + @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)
337 - # @mld = Login.joins(st + "ON logins.user_id = ml.id").
338 + rescue
338 - # where("logins.created_at >= ? and logins.created_at <= ?",@since_time,@until_time).
339 + @since_time = Time.zone.now.ago( 90.minutes)
339 - # order("ip_address")
340 + end
340 - #
341 + begin
341 - # #submissions
342 + md = params[:until_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
342 - # @subs = Submission.joins(:problem).joins(st + "ON submissions.user_id = ml.id").
343 + @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)
343 - # where("submissions.submitted_at >= ? and submissions.submitted_at <= ?",@since_time,@until_time).
344 + rescue
344 - # order("submissions.ip_address")
345 + @until_time = Time.zone.now
346 + end
347 +
348 + #convert sid
349 + @sid = params[:SID].split(/[,\s]/) if params[:SID]
350 + unless @sid and @sid.size > 0
351 + return
352 + redirect_to actoin: :cheat_scruntinize
353 + flash[:notice] = 'Please enter at least 1 student id'
354 + end
355 + mark = Array.new(@sid.size,'?')
356 + condition = "(u.login = " + mark.join(' OR u.login = ') + ')'
357 +
358 + @st = <<-SQL
359 + 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
360 + FROM logins l INNER JOIN users u on l.user_id = u.id
361 + WHERE l.created_at >= ? AND l.created_at <= ? AND #{condition}
362 + UNION
363 + SELECT s.submitted_at,s.id,u.login,u.full_name,s.ip_address,s.problem_id,s.points,s.user_id
364 + FROM submissions s INNER JOIN users u ON s.user_id = u.id
365 + WHERE s.submitted_at >= ? AND s.submitted_at <= ? AND #{condition}
366 + ORDER BY submitted_at
367 + SQL
368 +
369 + p = [@st,@since_time,@until_time] + @sid + [@since_time,@until_time] + @sid
370 + @logs = Submission.joins(:problem).find_by_sql(p)
371 +
372 +
373 +
374 +
375 +
345 end
376 end
346
377
347
378
348 end
379 end
@@ -1,8 +1,9
1
1
2 .task-menu
2 .task-menu
3 Reports
3 Reports
4 %br/
4 %br/
5 = link_to '[Hall of Fame]', :action => 'problem_hof'
5 = link_to '[Hall of Fame]', :action => 'problem_hof'
6 = link_to '[Struggle]', :action => 'stuck'
6 = link_to '[Struggle]', :action => 'stuck'
7 - = link_to '[Login]', :action => 'login_stat'
7 + = link_to '[Cheat Detection]', :action => 'cheat_report'
8 + = link_to '[Cheat Detail]', :action => 'cheat_scruntinize'
8 = link_to '[Multiple Login]', :action => 'multiple_login'
9 = link_to '[Multiple Login]', :action => 'multiple_login'
You need to be logged in to leave comments. Login now