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

r443:2d5e2b9fa726 - - 1 file changed: 4 inserted, 2 deleted

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