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

r423:abd08161c89d - - 1 file changed: 13 inserted, 0 deleted

@@ -1,99 +1,112
1 class ReportController < ApplicationController
1 class ReportController < ApplicationController
2
2
3 before_filter :admin_authorization, only: [:login_stat,:submission_stat]
3 before_filter :admin_authorization, only: [:login_stat,:submission_stat]
4 + before_filter(only: :problem_hof) { |c|
5 + user = User.find(session[:user_id]) if session[:user_id]
6 + if user==nil
7 + flash[:notice] = 'You have to login first'
8 + redirect_to :controller => 'main', :action => 'login'
9 + return false
10 + end
11 +
12 + unless GraderConfiguration["hall_of_fame_available"]
13 + flash[:notice] = 'You are not authorized to view the page you requested'
14 + redirect_to :controller => 'main', :action => 'login' unless GraderConfiguration[ "hall_of_fame_available" ]
15 + end
16 + }
4
17
5 def login_stat
18 def login_stat
6 @logins = Array.new
19 @logins = Array.new
7
20
8 date_and_time = '%Y-%m-%d %H:%M'
21 date_and_time = '%Y-%m-%d %H:%M'
9 begin
22 begin
10 @since_time = DateTime.strptime(params[:since_datetime],date_and_time)
23 @since_time = DateTime.strptime(params[:since_datetime],date_and_time)
11 rescue
24 rescue
12 @since_time = DateTime.new(1000,1,1)
25 @since_time = DateTime.new(1000,1,1)
13 end
26 end
14 begin
27 begin
15 @until_time = DateTime.strptime(params[:until_datetime],date_and_time)
28 @until_time = DateTime.strptime(params[:until_datetime],date_and_time)
16 rescue
29 rescue
17 @until_time = DateTime.new(3000,1,1)
30 @until_time = DateTime.new(3000,1,1)
18 end
31 end
19
32
20 User.all.each do |user|
33 User.all.each do |user|
21 @logins << { login: user.login,
34 @logins << { login: user.login,
22 full_name: user.full_name,
35 full_name: user.full_name,
23 count: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?",
36 count: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?",
24 user.id,@since_time,@until_time)
37 user.id,@since_time,@until_time)
25 .count(:id),
38 .count(:id),
26 min: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?",
39 min: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?",
27 user.id,@since_time,@until_time)
40 user.id,@since_time,@until_time)
28 .minimum(:created_at),
41 .minimum(:created_at),
29 max: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?",
42 max: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?",
30 user.id,@since_time,@until_time)
43 user.id,@since_time,@until_time)
31 .maximum(:created_at)
44 .maximum(:created_at)
32 }
45 }
33 end
46 end
34 end
47 end
35
48
36 def submission_stat
49 def submission_stat
37
50
38 date_and_time = '%Y-%m-%d %H:%M'
51 date_and_time = '%Y-%m-%d %H:%M'
39 begin
52 begin
40 @since_time = DateTime.strptime(params[:since_datetime],date_and_time)
53 @since_time = DateTime.strptime(params[:since_datetime],date_and_time)
41 rescue
54 rescue
42 @since_time = DateTime.new(1000,1,1)
55 @since_time = DateTime.new(1000,1,1)
43 end
56 end
44 begin
57 begin
45 @until_time = DateTime.strptime(params[:until_datetime],date_and_time)
58 @until_time = DateTime.strptime(params[:until_datetime],date_and_time)
46 rescue
59 rescue
47 @until_time = DateTime.new(3000,1,1)
60 @until_time = DateTime.new(3000,1,1)
48 end
61 end
49
62
50 @submissions = {}
63 @submissions = {}
51
64
52 User.find_each do |user|
65 User.find_each do |user|
53 @submissions[user.id] = { login: user.login, full_name: user.full_name, count: 0, sub: { } }
66 @submissions[user.id] = { login: user.login, full_name: user.full_name, count: 0, sub: { } }
54 end
67 end
55
68
56 Submission.where("submitted_at >= ? AND submitted_at <= ?",@since_time,@until_time).find_each do |s|
69 Submission.where("submitted_at >= ? AND submitted_at <= ?",@since_time,@until_time).find_each do |s|
57 if @submissions[s.user_id]
70 if @submissions[s.user_id]
58 if not @submissions[s.user_id][:sub].has_key?(s.problem_id)
71 if not @submissions[s.user_id][:sub].has_key?(s.problem_id)
59 a = nil
72 a = nil
60 begin
73 begin
61 a = Problem.find(s.problem_id)
74 a = Problem.find(s.problem_id)
62 rescue
75 rescue
63 a = nil
76 a = nil
64 end
77 end
65 @submissions[s.user_id][:sub][s.problem_id] =
78 @submissions[s.user_id][:sub][s.problem_id] =
66 { prob_name: (a ? a.full_name : '(NULL)'),
79 { prob_name: (a ? a.full_name : '(NULL)'),
67 sub_ids: [s.id] }
80 sub_ids: [s.id] }
68 else
81 else
69 @submissions[s.user_id][:sub][s.problem_id][:sub_ids] << s.id
82 @submissions[s.user_id][:sub][s.problem_id][:sub_ids] << s.id
70 end
83 end
71 @submissions[s.user_id][:count] += 1
84 @submissions[s.user_id][:count] += 1
72 end
85 end
73 end
86 end
74 end
87 end
75
88
76 def problem_hof
89 def problem_hof
77 # gen problem list
90 # gen problem list
78 @user = User.find(session[:user_id])
91 @user = User.find(session[:user_id])
79 @problems = @user.available_problems
92 @problems = @user.available_problems
80
93
81 # get selected problems or the default
94 # get selected problems or the default
82 if params[:id]
95 if params[:id]
83 begin
96 begin
84 @problem = Problem.available.find(params[:id])
97 @problem = Problem.available.find(params[:id])
85 rescue
98 rescue
86 redirect_to action: :problem_hof
99 redirect_to action: :problem_hof
87 flash[:notice] = 'Error: submissions for that problem are not viewable.'
100 flash[:notice] = 'Error: submissions for that problem are not viewable.'
88 return
101 return
89 end
102 end
90 end
103 end
91
104
92 if @problem
105 if @problem
93 #aggregrate by language
106 #aggregrate by language
94 @by_lang = {}
107 @by_lang = {}
95 Submission.where(problem_id: @problem.id).find_each do |sub|
108 Submission.where(problem_id: @problem.id).find_each do |sub|
96 lang = Language.find_by_id(sub.language_id)
109 lang = Language.find_by_id(sub.language_id)
97 next unless lang
110 next unless lang
98 next unless sub.points >= @problem.full_score
111 next unless sub.points >= @problem.full_score
99
112
You need to be logged in to leave comments. Login now