Description:
fix exclude admin in report
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r428:06bd0f1beeb4 - - 1 file changed: 2 inserted, 2 deleted
@@ -1,188 +1,188 | |||
|
1 | 1 | class ReportController < ApplicationController |
|
2 | 2 | |
|
3 | 3 | before_filter :admin_authorization, only: [:login_stat,:submission_stat] |
|
4 | 4 | before_filter(only: [:problem_hof]) { |c| |
|
5 | 5 | return false unless authenticate |
|
6 | 6 | |
|
7 | 7 | if GraderConfiguration["right.user_view_submission"] |
|
8 | 8 | return true; |
|
9 | 9 | end |
|
10 | 10 | |
|
11 | 11 | admin_authorization |
|
12 | 12 | } |
|
13 | 13 | |
|
14 | 14 | def login_stat |
|
15 | 15 | @logins = Array.new |
|
16 | 16 | |
|
17 | 17 | date_and_time = '%Y-%m-%d %H:%M' |
|
18 | 18 | begin |
|
19 | 19 | @since_time = DateTime.strptime(params[:since_datetime],date_and_time) |
|
20 | 20 | rescue |
|
21 | 21 | @since_time = DateTime.new(1000,1,1) |
|
22 | 22 | end |
|
23 | 23 | begin |
|
24 | 24 | @until_time = DateTime.strptime(params[:until_datetime],date_and_time) |
|
25 | 25 | rescue |
|
26 | 26 | @until_time = DateTime.new(3000,1,1) |
|
27 | 27 | end |
|
28 | 28 | |
|
29 | 29 | User.all.each do |user| |
|
30 | 30 | @logins << { login: user.login, |
|
31 | 31 | full_name: user.full_name, |
|
32 | 32 | count: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", |
|
33 | 33 | user.id,@since_time,@until_time) |
|
34 | 34 | .count(:id), |
|
35 | 35 | min: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", |
|
36 | 36 | user.id,@since_time,@until_time) |
|
37 | 37 | .minimum(:created_at), |
|
38 | 38 | max: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", |
|
39 | 39 | user.id,@since_time,@until_time) |
|
40 | 40 | .maximum(:created_at) |
|
41 | 41 | } |
|
42 | 42 | end |
|
43 | 43 | end |
|
44 | 44 | |
|
45 | 45 | def submission_stat |
|
46 | 46 | |
|
47 | 47 | date_and_time = '%Y-%m-%d %H:%M' |
|
48 | 48 | begin |
|
49 | 49 | @since_time = DateTime.strptime(params[:since_datetime],date_and_time) |
|
50 | 50 | rescue |
|
51 | 51 | @since_time = DateTime.new(1000,1,1) |
|
52 | 52 | end |
|
53 | 53 | begin |
|
54 | 54 | @until_time = DateTime.strptime(params[:until_datetime],date_and_time) |
|
55 | 55 | rescue |
|
56 | 56 | @until_time = DateTime.new(3000,1,1) |
|
57 | 57 | end |
|
58 | 58 | |
|
59 | 59 | @submissions = {} |
|
60 | 60 | |
|
61 | 61 | User.find_each do |user| |
|
62 | 62 | @submissions[user.id] = { login: user.login, full_name: user.full_name, count: 0, sub: { } } |
|
63 | 63 | end |
|
64 | 64 | |
|
65 | 65 | Submission.where("submitted_at >= ? AND submitted_at <= ?",@since_time,@until_time).find_each do |s| |
|
66 | 66 | if @submissions[s.user_id] |
|
67 | 67 | if not @submissions[s.user_id][:sub].has_key?(s.problem_id) |
|
68 | 68 | a = nil |
|
69 | 69 | begin |
|
70 | 70 | a = Problem.find(s.problem_id) |
|
71 | 71 | rescue |
|
72 | 72 | a = nil |
|
73 | 73 | end |
|
74 | 74 | @submissions[s.user_id][:sub][s.problem_id] = |
|
75 | 75 | { prob_name: (a ? a.full_name : '(NULL)'), |
|
76 | 76 | sub_ids: [s.id] } |
|
77 | 77 | else |
|
78 | 78 | @submissions[s.user_id][:sub][s.problem_id][:sub_ids] << s.id |
|
79 | 79 | end |
|
80 | 80 | @submissions[s.user_id][:count] += 1 |
|
81 | 81 | end |
|
82 | 82 | end |
|
83 | 83 | end |
|
84 | 84 | |
|
85 | 85 | def problem_hof |
|
86 | 86 | # gen problem list |
|
87 | 87 | @user = User.find(session[:user_id]) |
|
88 | 88 | @problems = @user.available_problems |
|
89 | 89 | |
|
90 | 90 | # get selected problems or the default |
|
91 | 91 | if params[:id] |
|
92 | 92 | begin |
|
93 | 93 | @problem = Problem.available.find(params[:id]) |
|
94 | 94 | rescue |
|
95 | 95 | redirect_to action: :problem_hof |
|
96 | 96 | flash[:notice] = 'Error: submissions for that problem are not viewable.' |
|
97 | 97 | return |
|
98 | 98 | end |
|
99 | 99 | end |
|
100 | 100 | |
|
101 | 101 | if @problem |
|
102 | 102 | #aggregrate by language |
|
103 | 103 | @by_lang = {} |
|
104 | 104 | Submission.where(problem_id: @problem.id).find_each do |sub| |
|
105 | 105 | lang = Language.find_by_id(sub.language_id) |
|
106 | 106 | next unless lang |
|
107 | 107 | next unless sub.points >= @problem.full_score |
|
108 | 108 | |
|
109 | 109 | #initialize |
|
110 | 110 | unless @by_lang.has_key?(lang.pretty_name) |
|
111 | 111 | @by_lang[lang.pretty_name] = { |
|
112 | 112 | runtime: { avail: false, value: 2**30-1 }, |
|
113 | 113 | memory: { avail: false, value: 2**30-1 }, |
|
114 | 114 | length: { avail: false, value: 2**30-1 }, |
|
115 | 115 | first: { avail: false, value: DateTime.new(3000,1,1) } |
|
116 | 116 | } |
|
117 | 117 | end |
|
118 | 118 | |
|
119 | 119 | if sub.max_runtime and sub.max_runtime < @by_lang[lang.pretty_name][:runtime][:value] |
|
120 | 120 | @by_lang[lang.pretty_name][:runtime] = { |
|
121 | 121 | avail: true, |
|
122 | 122 | user_id: sub.user_id, |
|
123 | 123 | value: sub.max_runtime, |
|
124 | 124 | sub_id: sub.id |
|
125 | 125 | } |
|
126 | 126 | end |
|
127 | 127 | |
|
128 | 128 | if sub.peak_memory and sub.peak_memory < @by_lang[lang.pretty_name][:memory][:value] |
|
129 | 129 | @by_lang[lang.pretty_name][:memory] = { |
|
130 | 130 | avail: true, |
|
131 | 131 | user_id: sub.user_id, |
|
132 | 132 | value: sub.peak_memory, |
|
133 | 133 | sub_id: sub.id |
|
134 | 134 | } |
|
135 | 135 | end |
|
136 | 136 | |
|
137 | - if sub.user.admin? == false and | |
|
138 | - sub.submitted_at and sub.submitted_at < @by_lang[lang.pretty_name][:first][:value] | |
|
137 | + if sub.submitted_at and sub.submitted_at < @by_lang[lang.pretty_name][:first][:value] and | |
|
138 | + !sub.user.admin? | |
|
139 | 139 | @by_lang[lang.pretty_name][:first] = { |
|
140 | 140 | avail: true, |
|
141 | 141 | user_id: sub.user_id, |
|
142 | 142 | value: sub.submitted_at, |
|
143 | 143 | sub_id: sub.id |
|
144 | 144 | } |
|
145 | 145 | end |
|
146 | 146 | |
|
147 | 147 | if @by_lang[lang.pretty_name][:length][:value] > sub.effective_code_length |
|
148 | 148 | @by_lang[lang.pretty_name][:length] = { |
|
149 | 149 | avail: true, |
|
150 | 150 | user_id: sub.user_id, |
|
151 | 151 | value: sub.effective_code_length, |
|
152 | 152 | sub_id: sub.id |
|
153 | 153 | } |
|
154 | 154 | end |
|
155 | 155 | end |
|
156 | 156 | |
|
157 | 157 | #process user_id |
|
158 | 158 | @by_lang.each do |lang,prop| |
|
159 | 159 | prop.each do |k,v| |
|
160 | 160 | v[:user] = User.exists?(v[:user_id]) ? User.find(v[:user_id]).full_name : "(NULL)" |
|
161 | 161 | end |
|
162 | 162 | end |
|
163 | 163 | |
|
164 | 164 | #sum into best |
|
165 | 165 | if @by_lang and @by_lang.first |
|
166 | 166 | @best = @by_lang.first[1] |
|
167 | 167 | @by_lang.each do |lang,prop| |
|
168 | 168 | if @best[:runtime][:value] >= prop[:runtime][:value] |
|
169 | 169 | @best[:runtime] = prop[:runtime] |
|
170 | 170 | @best[:runtime][:lang] = lang |
|
171 | 171 | end |
|
172 | 172 | if @best[:memory][:value] >= prop[:memory][:value] |
|
173 | 173 | @best[:memory] = prop[:memory] |
|
174 | 174 | @best[:memory][:lang] = lang |
|
175 | 175 | end |
|
176 | 176 | if @best[:length][:value] >= prop[:length][:value] |
|
177 | 177 | @best[:length] = prop[:length] |
|
178 | 178 | @best[:length][:lang] = lang |
|
179 | 179 | end |
|
180 | 180 | if @best[:first][:value] >= prop[:first][:value] |
|
181 | 181 | @best[:first] = prop[:first] |
|
182 | 182 | @best[:first][:lang] = lang |
|
183 | 183 | end |
|
184 | 184 | end |
|
185 | 185 | end |
|
186 | 186 | end |
|
187 | 187 | end |
|
188 | 188 | end |
You need to be logged in to leave comments.
Login now