Description:
add more stat
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r458:df535657f72c - - 6 files changed: 76 inserted, 14 deleted
@@ -66,193 +66,192 | |||||
|
66 | flash[:notice] = 'Error saving problem' |
|
66 | flash[:notice] = 'Error saving problem' |
|
67 | redirect_to :action => 'list' |
|
67 | redirect_to :action => 'list' |
|
68 | end |
|
68 | end |
|
69 | end |
|
69 | end |
|
70 |
|
70 | ||
|
71 | def edit |
|
71 | def edit |
|
72 | @problem = Problem.find(params[:id]) |
|
72 | @problem = Problem.find(params[:id]) |
|
73 | @description = @problem.description |
|
73 | @description = @problem.description |
|
74 | end |
|
74 | end |
|
75 |
|
75 | ||
|
76 | def update |
|
76 | def update |
|
77 | @problem = Problem.find(params[:id]) |
|
77 | @problem = Problem.find(params[:id]) |
|
78 | @description = @problem.description |
|
78 | @description = @problem.description |
|
79 | if @description == nil and params[:description][:body]!='' |
|
79 | if @description == nil and params[:description][:body]!='' |
|
80 | @description = Description.new(params[:description]) |
|
80 | @description = Description.new(params[:description]) |
|
81 | if !@description.save |
|
81 | if !@description.save |
|
82 | flash[:notice] = 'Error saving description' |
|
82 | flash[:notice] = 'Error saving description' |
|
83 | render :action => 'edit' and return |
|
83 | render :action => 'edit' and return |
|
84 | end |
|
84 | end |
|
85 | @problem.description = @description |
|
85 | @problem.description = @description |
|
86 | elsif @description!=nil |
|
86 | elsif @description!=nil |
|
87 | if !@description.update_attributes(params[:description]) |
|
87 | if !@description.update_attributes(params[:description]) |
|
88 | flash[:notice] = 'Error saving description' |
|
88 | flash[:notice] = 'Error saving description' |
|
89 | render :action => 'edit' and return |
|
89 | render :action => 'edit' and return |
|
90 | end |
|
90 | end |
|
91 | end |
|
91 | end |
|
92 | if params[:file] and params[:file].content_type != 'application/pdf' |
|
92 | if params[:file] and params[:file].content_type != 'application/pdf' |
|
93 | flash[:notice] = 'Error: Uploaded file is not PDF' |
|
93 | flash[:notice] = 'Error: Uploaded file is not PDF' |
|
94 | render :action => 'edit' and return |
|
94 | render :action => 'edit' and return |
|
95 | end |
|
95 | end |
|
96 | if @problem.update_attributes(params[:problem]) |
|
96 | if @problem.update_attributes(params[:problem]) |
|
97 | flash[:notice] = 'Problem was successfully updated.' |
|
97 | flash[:notice] = 'Problem was successfully updated.' |
|
98 | unless params[:file] == nil or params[:file] == '' |
|
98 | unless params[:file] == nil or params[:file] == '' |
|
99 | flash[:notice] = 'Problem was successfully updated and a new PDF file is uploaded.' |
|
99 | flash[:notice] = 'Problem was successfully updated and a new PDF file is uploaded.' |
|
100 | out_dirname = "#{Problem.download_file_basedir}/#{@problem.id}" |
|
100 | out_dirname = "#{Problem.download_file_basedir}/#{@problem.id}" |
|
101 | if not FileTest.exists? out_dirname |
|
101 | if not FileTest.exists? out_dirname |
|
102 | Dir.mkdir out_dirname |
|
102 | Dir.mkdir out_dirname |
|
103 | end |
|
103 | end |
|
104 |
|
104 | ||
|
105 | out_filename = "#{out_dirname}/#{@problem.name}.pdf" |
|
105 | out_filename = "#{out_dirname}/#{@problem.name}.pdf" |
|
106 | if FileTest.exists? out_filename |
|
106 | if FileTest.exists? out_filename |
|
107 | File.delete out_filename |
|
107 | File.delete out_filename |
|
108 | end |
|
108 | end |
|
109 |
|
109 | ||
|
110 | File.open(out_filename,"wb") do |file| |
|
110 | File.open(out_filename,"wb") do |file| |
|
111 | file.write(params[:file].read) |
|
111 | file.write(params[:file].read) |
|
112 | end |
|
112 | end |
|
113 | @problem.description_filename = "#{@problem.name}.pdf" |
|
113 | @problem.description_filename = "#{@problem.name}.pdf" |
|
114 | @problem.save |
|
114 | @problem.save |
|
115 | end |
|
115 | end |
|
116 | redirect_to :action => 'show', :id => @problem |
|
116 | redirect_to :action => 'show', :id => @problem |
|
117 | else |
|
117 | else |
|
118 | render :action => 'edit' |
|
118 | render :action => 'edit' |
|
119 | end |
|
119 | end |
|
120 | end |
|
120 | end |
|
121 |
|
121 | ||
|
122 | def destroy |
|
122 | def destroy |
|
123 | Problem.find(params[:id]).destroy |
|
123 | Problem.find(params[:id]).destroy |
|
124 | redirect_to :action => 'list' |
|
124 | redirect_to :action => 'list' |
|
125 | end |
|
125 | end |
|
126 |
|
126 | ||
|
127 | def toggle |
|
127 | def toggle |
|
128 | @problem = Problem.find(params[:id]) |
|
128 | @problem = Problem.find(params[:id]) |
|
129 | @problem.available = !(@problem.available) |
|
129 | @problem.available = !(@problem.available) |
|
130 | @problem.save |
|
130 | @problem.save |
|
131 | end |
|
131 | end |
|
132 |
|
132 | ||
|
133 | def turn_all_off |
|
133 | def turn_all_off |
|
134 | Problem.find(:all, |
|
134 | Problem.find(:all, |
|
135 | :conditions => "available = 1").each do |problem| |
|
135 | :conditions => "available = 1").each do |problem| |
|
136 | problem.available = false |
|
136 | problem.available = false |
|
137 | problem.save |
|
137 | problem.save |
|
138 | end |
|
138 | end |
|
139 | redirect_to :action => 'list' |
|
139 | redirect_to :action => 'list' |
|
140 | end |
|
140 | end |
|
141 |
|
141 | ||
|
142 | def turn_all_on |
|
142 | def turn_all_on |
|
143 | Problem.find(:all, |
|
143 | Problem.find(:all, |
|
144 | :conditions => "available = 0").each do |problem| |
|
144 | :conditions => "available = 0").each do |problem| |
|
145 | problem.available = true |
|
145 | problem.available = true |
|
146 | problem.save |
|
146 | problem.save |
|
147 | end |
|
147 | end |
|
148 | redirect_to :action => 'list' |
|
148 | redirect_to :action => 'list' |
|
149 | end |
|
149 | end |
|
150 |
|
150 | ||
|
151 | def stat |
|
151 | def stat |
|
152 | @problem = Problem.find(params[:id]) |
|
152 | @problem = Problem.find(params[:id]) |
|
153 | unless @problem.available or session[:admin] |
|
153 | unless @problem.available or session[:admin] |
|
154 | redirect_to :controller => 'main', :action => 'list' |
|
154 | redirect_to :controller => 'main', :action => 'list' |
|
155 | return |
|
155 | return |
|
156 | end |
|
156 | end |
|
157 | @submissions = Submission.includes(:user).where(problem_id: params[:id]).order(:user_id,:id) |
|
157 | @submissions = Submission.includes(:user).where(problem_id: params[:id]).order(:user_id,:id) |
|
158 |
|
158 | ||
|
159 | #stat summary |
|
159 | #stat summary |
|
160 | range =65 |
|
160 | range =65 |
|
161 | @histogram = { data: Array.new(range,0), summary: {} } |
|
161 | @histogram = { data: Array.new(range,0), summary: {} } |
|
162 | - @histogram[:data] = Array.new(range,0) |
|
||
|
163 | user = Hash.new(0) |
|
162 | user = Hash.new(0) |
|
164 | @submissions.find_each do |sub| |
|
163 | @submissions.find_each do |sub| |
|
165 | d = (DateTime.now.in_time_zone - sub.submitted_at) / 24 / 60 / 60 |
|
164 | d = (DateTime.now.in_time_zone - sub.submitted_at) / 24 / 60 / 60 |
|
166 | @histogram[:data][d.to_i] += 1 if d < range |
|
165 | @histogram[:data][d.to_i] += 1 if d < range |
|
167 | user[sub.user_id] = [user[sub.user_id], (sub.points >= @problem.full_score) ? 1 : 0].max |
|
166 | user[sub.user_id] = [user[sub.user_id], (sub.points >= @problem.full_score) ? 1 : 0].max |
|
168 | end |
|
167 | end |
|
169 | @histogram[:summary][:max] = [@histogram[:data].max,1].max |
|
168 | @histogram[:summary][:max] = [@histogram[:data].max,1].max |
|
170 |
|
169 | ||
|
171 | @summary = { attempt: user.count, solve: 0 } |
|
170 | @summary = { attempt: user.count, solve: 0 } |
|
172 | user.each_value { |v| @summary[:solve] += 1 if v == 1 } |
|
171 | user.each_value { |v| @summary[:solve] += 1 if v == 1 } |
|
173 | end |
|
172 | end |
|
174 |
|
173 | ||
|
175 | def manage |
|
174 | def manage |
|
176 | @problems = Problem.find(:all, :order => 'date_added DESC') |
|
175 | @problems = Problem.find(:all, :order => 'date_added DESC') |
|
177 | end |
|
176 | end |
|
178 |
|
177 | ||
|
179 | def do_manage |
|
178 | def do_manage |
|
180 | if params.has_key? 'change_date_added' |
|
179 | if params.has_key? 'change_date_added' |
|
181 | change_date_added |
|
180 | change_date_added |
|
182 | elsif params.has_key? 'add_to_contest' |
|
181 | elsif params.has_key? 'add_to_contest' |
|
183 | add_to_contest |
|
182 | add_to_contest |
|
184 | elsif params.has_key? 'enable_problem' |
|
183 | elsif params.has_key? 'enable_problem' |
|
185 | set_available(true) |
|
184 | set_available(true) |
|
186 | elsif params.has_key? 'disable_problem' |
|
185 | elsif params.has_key? 'disable_problem' |
|
187 | set_available(false) |
|
186 | set_available(false) |
|
188 | end |
|
187 | end |
|
189 | redirect_to :action => 'manage' |
|
188 | redirect_to :action => 'manage' |
|
190 | end |
|
189 | end |
|
191 |
|
190 | ||
|
192 | def import |
|
191 | def import |
|
193 | @allow_test_pair_import = allow_test_pair_import? |
|
192 | @allow_test_pair_import = allow_test_pair_import? |
|
194 | end |
|
193 | end |
|
195 |
|
194 | ||
|
196 | def do_import |
|
195 | def do_import |
|
197 | old_problem = Problem.find_by_name(params[:name]) |
|
196 | old_problem = Problem.find_by_name(params[:name]) |
|
198 | if !allow_test_pair_import? and params.has_key? :import_to_db |
|
197 | if !allow_test_pair_import? and params.has_key? :import_to_db |
|
199 | params.delete :import_to_db |
|
198 | params.delete :import_to_db |
|
200 | end |
|
199 | end |
|
201 | @problem, import_log = Problem.create_from_import_form_params(params, |
|
200 | @problem, import_log = Problem.create_from_import_form_params(params, |
|
202 | old_problem) |
|
201 | old_problem) |
|
203 |
|
202 | ||
|
204 | if !@problem.errors.empty? |
|
203 | if !@problem.errors.empty? |
|
205 | render :action => 'import' and return |
|
204 | render :action => 'import' and return |
|
206 | end |
|
205 | end |
|
207 |
|
206 | ||
|
208 | if old_problem!=nil |
|
207 | if old_problem!=nil |
|
209 | flash[:notice] = "The test data has been replaced for problem #{@problem.name}" |
|
208 | flash[:notice] = "The test data has been replaced for problem #{@problem.name}" |
|
210 | end |
|
209 | end |
|
211 | @log = import_log |
|
210 | @log = import_log |
|
212 | end |
|
211 | end |
|
213 |
|
212 | ||
|
214 | def remove_contest |
|
213 | def remove_contest |
|
215 | problem = Problem.find(params[:id]) |
|
214 | problem = Problem.find(params[:id]) |
|
216 | contest = Contest.find(params[:contest_id]) |
|
215 | contest = Contest.find(params[:contest_id]) |
|
217 | if problem!=nil and contest!=nil |
|
216 | if problem!=nil and contest!=nil |
|
218 | problem.contests.delete(contest) |
|
217 | problem.contests.delete(contest) |
|
219 | end |
|
218 | end |
|
220 | redirect_to :action => 'manage' |
|
219 | redirect_to :action => 'manage' |
|
221 | end |
|
220 | end |
|
222 |
|
221 | ||
|
223 | ################################## |
|
222 | ################################## |
|
224 | protected |
|
223 | protected |
|
225 |
|
224 | ||
|
226 | def allow_test_pair_import? |
|
225 | def allow_test_pair_import? |
|
227 | if defined? ALLOW_TEST_PAIR_IMPORT |
|
226 | if defined? ALLOW_TEST_PAIR_IMPORT |
|
228 | return ALLOW_TEST_PAIR_IMPORT |
|
227 | return ALLOW_TEST_PAIR_IMPORT |
|
229 | else |
|
228 | else |
|
230 | return false |
|
229 | return false |
|
231 | end |
|
230 | end |
|
232 | end |
|
231 | end |
|
233 |
|
232 | ||
|
234 | def change_date_added |
|
233 | def change_date_added |
|
235 | problems = get_problems_from_params |
|
234 | problems = get_problems_from_params |
|
236 | year = params[:date_added][:year].to_i |
|
235 | year = params[:date_added][:year].to_i |
|
237 | month = params[:date_added][:month].to_i |
|
236 | month = params[:date_added][:month].to_i |
|
238 | day = params[:date_added][:day].to_i |
|
237 | day = params[:date_added][:day].to_i |
|
239 | date = Date.new(year,month,day) |
|
238 | date = Date.new(year,month,day) |
|
240 | problems.each do |p| |
|
239 | problems.each do |p| |
|
241 | p.date_added = date |
|
240 | p.date_added = date |
|
242 | p.save |
|
241 | p.save |
|
243 | end |
|
242 | end |
|
244 | end |
|
243 | end |
|
245 |
|
244 | ||
|
246 | def add_to_contest |
|
245 | def add_to_contest |
|
247 | problems = get_problems_from_params |
|
246 | problems = get_problems_from_params |
|
248 | contest = Contest.find(params[:contest][:id]) |
|
247 | contest = Contest.find(params[:contest][:id]) |
|
249 | if contest!=nil and contest.enabled |
|
248 | if contest!=nil and contest.enabled |
|
250 | problems.each do |p| |
|
249 | problems.each do |p| |
|
251 | p.contests << contest |
|
250 | p.contests << contest |
|
252 | end |
|
251 | end |
|
253 | end |
|
252 | end |
|
254 | end |
|
253 | end |
|
255 |
|
254 | ||
|
256 | def set_available(avail) |
|
255 | def set_available(avail) |
|
257 | problems = get_problems_from_params |
|
256 | problems = get_problems_from_params |
|
258 | problems.each do |p| |
|
257 | problems.each do |p| |
@@ -18,175 +18,174 | |||||
|
18 | begin |
|
18 | begin |
|
19 | md = params[:since_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/) |
|
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 | @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 |
|
21 | rescue |
|
22 | @since_time = DateTime.new(1000,1,1) |
|
22 | @since_time = DateTime.new(1000,1,1) |
|
23 | end |
|
23 | end |
|
24 | begin |
|
24 | begin |
|
25 | md = params[:until_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/) |
|
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) |
|
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 | rescue |
|
27 | rescue |
|
28 | @until_time = DateTime.new(3000,1,1) |
|
28 | @until_time = DateTime.new(3000,1,1) |
|
29 | end |
|
29 | end |
|
30 |
|
30 | ||
|
31 | User.all.each do |user| |
|
31 | User.all.each do |user| |
|
32 | @logins << { id: user.id, |
|
32 | @logins << { id: user.id, |
|
33 | login: user.login, |
|
33 | login: user.login, |
|
34 | full_name: user.full_name, |
|
34 | full_name: user.full_name, |
|
35 | count: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", |
|
35 | count: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", |
|
36 | user.id,@since_time,@until_time) |
|
36 | user.id,@since_time,@until_time) |
|
37 | .count(:id), |
|
37 | .count(:id), |
|
38 | min: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", |
|
38 | min: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", |
|
39 | user.id,@since_time,@until_time) |
|
39 | user.id,@since_time,@until_time) |
|
40 | .minimum(:created_at), |
|
40 | .minimum(:created_at), |
|
41 | max: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", |
|
41 | max: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", |
|
42 | user.id,@since_time,@until_time) |
|
42 | user.id,@since_time,@until_time) |
|
43 | .maximum(:created_at), |
|
43 | .maximum(:created_at), |
|
44 | ip: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", |
|
44 | ip: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", |
|
45 | user.id,@since_time,@until_time) |
|
45 | user.id,@since_time,@until_time) |
|
46 | .select(:ip_address).uniq |
|
46 | .select(:ip_address).uniq |
|
47 |
|
47 | ||
|
48 | } |
|
48 | } |
|
49 | end |
|
49 | end |
|
50 | end |
|
50 | end |
|
51 |
|
51 | ||
|
52 | def submission_stat |
|
52 | def submission_stat |
|
53 |
|
53 | ||
|
54 | date_and_time = '%Y-%m-%d %H:%M' |
|
54 | date_and_time = '%Y-%m-%d %H:%M' |
|
55 | begin |
|
55 | begin |
|
56 | @since_time = DateTime.strptime(params[:since_datetime],date_and_time) |
|
56 | @since_time = DateTime.strptime(params[:since_datetime],date_and_time) |
|
57 | rescue |
|
57 | rescue |
|
58 | @since_time = DateTime.new(1000,1,1) |
|
58 | @since_time = DateTime.new(1000,1,1) |
|
59 | end |
|
59 | end |
|
60 | begin |
|
60 | begin |
|
61 | @until_time = DateTime.strptime(params[:until_datetime],date_and_time) |
|
61 | @until_time = DateTime.strptime(params[:until_datetime],date_and_time) |
|
62 | rescue |
|
62 | rescue |
|
63 | @until_time = DateTime.new(3000,1,1) |
|
63 | @until_time = DateTime.new(3000,1,1) |
|
64 | end |
|
64 | end |
|
65 |
|
65 | ||
|
66 | @submissions = {} |
|
66 | @submissions = {} |
|
67 |
|
67 | ||
|
68 | User.find_each do |user| |
|
68 | User.find_each do |user| |
|
69 | @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: { } } |
|
70 | end |
|
70 | end |
|
71 |
|
71 | ||
|
72 | 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| |
|
73 | if @submissions[s.user_id] |
|
73 | if @submissions[s.user_id] |
|
74 | 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) |
|
75 | a = nil |
|
75 | a = nil |
|
76 | begin |
|
76 | begin |
|
77 | a = Problem.find(s.problem_id) |
|
77 | a = Problem.find(s.problem_id) |
|
78 | rescue |
|
78 | rescue |
|
79 | a = nil |
|
79 | a = nil |
|
80 | end |
|
80 | end |
|
81 | @submissions[s.user_id][:sub][s.problem_id] = |
|
81 | @submissions[s.user_id][:sub][s.problem_id] = |
|
82 | { prob_name: (a ? a.full_name : '(NULL)'), |
|
82 | { prob_name: (a ? a.full_name : '(NULL)'), |
|
83 | sub_ids: [s.id] } |
|
83 | sub_ids: [s.id] } |
|
84 | else |
|
84 | else |
|
85 | @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 |
|
86 | end |
|
86 | end |
|
87 | @submissions[s.user_id][:count] += 1 |
|
87 | @submissions[s.user_id][:count] += 1 |
|
88 | end |
|
88 | end |
|
89 | end |
|
89 | end |
|
90 | end |
|
90 | end |
|
91 |
|
91 | ||
|
92 | def problem_hof |
|
92 | def problem_hof |
|
93 | # gen problem list |
|
93 | # gen problem list |
|
94 | @user = User.find(session[:user_id]) |
|
94 | @user = User.find(session[:user_id]) |
|
95 | @problems = @user.available_problems |
|
95 | @problems = @user.available_problems |
|
96 |
|
96 | ||
|
97 | # get selected problems or the default |
|
97 | # get selected problems or the default |
|
98 | if params[:id] |
|
98 | if params[:id] |
|
99 | begin |
|
99 | begin |
|
100 | @problem = Problem.available.find(params[:id]) |
|
100 | @problem = Problem.available.find(params[:id]) |
|
101 | rescue |
|
101 | rescue |
|
102 | redirect_to action: :problem_hof |
|
102 | redirect_to action: :problem_hof |
|
103 | flash[:notice] = 'Error: submissions for that problem are not viewable.' |
|
103 | flash[:notice] = 'Error: submissions for that problem are not viewable.' |
|
104 | return |
|
104 | return |
|
105 | end |
|
105 | end |
|
106 | end |
|
106 | end |
|
107 |
|
107 | ||
|
108 | return unless @problem |
|
108 | return unless @problem |
|
109 |
|
109 | ||
|
110 | @by_lang = {} #aggregrate by language |
|
110 | @by_lang = {} #aggregrate by language |
|
111 |
|
111 | ||
|
112 | range =65 |
|
112 | range =65 |
|
113 | @histogram = { data: Array.new(range,0), summary: {} } |
|
113 | @histogram = { data: Array.new(range,0), summary: {} } |
|
114 | - @histogram[:data] = Array.new(range,0) |
|
||
|
115 | @summary = {count: 0, solve: 0, attempt: 0} |
|
114 | @summary = {count: 0, solve: 0, attempt: 0} |
|
116 | user = Hash.new(0) |
|
115 | user = Hash.new(0) |
|
117 | Submission.where(problem_id: @problem.id).find_each do |sub| |
|
116 | Submission.where(problem_id: @problem.id).find_each do |sub| |
|
118 | #histogram |
|
117 | #histogram |
|
119 | d = (DateTime.now.in_time_zone - sub.submitted_at) / 24 / 60 / 60 |
|
118 | d = (DateTime.now.in_time_zone - sub.submitted_at) / 24 / 60 / 60 |
|
120 | @histogram[:data][d.to_i] += 1 if d < range |
|
119 | @histogram[:data][d.to_i] += 1 if d < range |
|
121 |
|
120 | ||
|
122 | @summary[:count] += 1 |
|
121 | @summary[:count] += 1 |
|
123 | user[sub.user_id] = [user[sub.user_id], (sub.points >= @problem.full_score) ? 1 : 0].max |
|
122 | user[sub.user_id] = [user[sub.user_id], (sub.points >= @problem.full_score) ? 1 : 0].max |
|
124 |
|
123 | ||
|
125 | lang = Language.find_by_id(sub.language_id) |
|
124 | lang = Language.find_by_id(sub.language_id) |
|
126 | next unless lang |
|
125 | next unless lang |
|
127 | next unless sub.points >= @problem.full_score |
|
126 | next unless sub.points >= @problem.full_score |
|
128 |
|
127 | ||
|
129 | #initialize |
|
128 | #initialize |
|
130 | unless @by_lang.has_key?(lang.pretty_name) |
|
129 | unless @by_lang.has_key?(lang.pretty_name) |
|
131 | @by_lang[lang.pretty_name] = { |
|
130 | @by_lang[lang.pretty_name] = { |
|
132 | runtime: { avail: false, value: 2**30-1 }, |
|
131 | runtime: { avail: false, value: 2**30-1 }, |
|
133 | memory: { avail: false, value: 2**30-1 }, |
|
132 | memory: { avail: false, value: 2**30-1 }, |
|
134 | length: { avail: false, value: 2**30-1 }, |
|
133 | length: { avail: false, value: 2**30-1 }, |
|
135 | first: { avail: false, value: DateTime.new(3000,1,1) } |
|
134 | first: { avail: false, value: DateTime.new(3000,1,1) } |
|
136 | } |
|
135 | } |
|
137 | end |
|
136 | end |
|
138 |
|
137 | ||
|
139 | if sub.max_runtime and sub.max_runtime < @by_lang[lang.pretty_name][:runtime][:value] |
|
138 | if sub.max_runtime and sub.max_runtime < @by_lang[lang.pretty_name][:runtime][:value] |
|
140 | @by_lang[lang.pretty_name][:runtime] = { avail: true, user_id: sub.user_id, value: sub.max_runtime, sub_id: sub.id } |
|
139 | @by_lang[lang.pretty_name][:runtime] = { avail: true, user_id: sub.user_id, value: sub.max_runtime, sub_id: sub.id } |
|
141 | end |
|
140 | end |
|
142 |
|
141 | ||
|
143 | if sub.peak_memory and sub.peak_memory < @by_lang[lang.pretty_name][:memory][:value] |
|
142 | if sub.peak_memory and sub.peak_memory < @by_lang[lang.pretty_name][:memory][:value] |
|
144 | @by_lang[lang.pretty_name][:memory] = { avail: true, user_id: sub.user_id, value: sub.peak_memory, sub_id: sub.id } |
|
143 | @by_lang[lang.pretty_name][:memory] = { avail: true, user_id: sub.user_id, value: sub.peak_memory, sub_id: sub.id } |
|
145 | end |
|
144 | end |
|
146 |
|
145 | ||
|
147 | if sub.submitted_at and sub.submitted_at < @by_lang[lang.pretty_name][:first][:value] and |
|
146 | if sub.submitted_at and sub.submitted_at < @by_lang[lang.pretty_name][:first][:value] and |
|
148 | !sub.user.admin? |
|
147 | !sub.user.admin? |
|
149 | @by_lang[lang.pretty_name][:first] = { avail: true, user_id: sub.user_id, value: sub.submitted_at, sub_id: sub.id } |
|
148 | @by_lang[lang.pretty_name][:first] = { avail: true, user_id: sub.user_id, value: sub.submitted_at, sub_id: sub.id } |
|
150 | end |
|
149 | end |
|
151 |
|
150 | ||
|
152 | if @by_lang[lang.pretty_name][:length][:value] > sub.effective_code_length |
|
151 | if @by_lang[lang.pretty_name][:length][:value] > sub.effective_code_length |
|
153 | @by_lang[lang.pretty_name][:length] = { avail: true, user_id: sub.user_id, value: sub.effective_code_length, sub_id: sub.id } |
|
152 | @by_lang[lang.pretty_name][:length] = { avail: true, user_id: sub.user_id, value: sub.effective_code_length, sub_id: sub.id } |
|
154 | end |
|
153 | end |
|
155 | end |
|
154 | end |
|
156 |
|
155 | ||
|
157 | #process user_id |
|
156 | #process user_id |
|
158 | @by_lang.each do |lang,prop| |
|
157 | @by_lang.each do |lang,prop| |
|
159 | prop.each do |k,v| |
|
158 | prop.each do |k,v| |
|
160 | v[:user] = User.exists?(v[:user_id]) ? User.find(v[:user_id]).full_name : "(NULL)" |
|
159 | v[:user] = User.exists?(v[:user_id]) ? User.find(v[:user_id]).full_name : "(NULL)" |
|
161 | end |
|
160 | end |
|
162 | end |
|
161 | end |
|
163 |
|
162 | ||
|
164 | #sum into best |
|
163 | #sum into best |
|
165 | if @by_lang and @by_lang.first |
|
164 | if @by_lang and @by_lang.first |
|
166 | @best = @by_lang.first[1].clone |
|
165 | @best = @by_lang.first[1].clone |
|
167 | @by_lang.each do |lang,prop| |
|
166 | @by_lang.each do |lang,prop| |
|
168 | if @best[:runtime][:value] >= prop[:runtime][:value] |
|
167 | if @best[:runtime][:value] >= prop[:runtime][:value] |
|
169 | @best[:runtime] = prop[:runtime] |
|
168 | @best[:runtime] = prop[:runtime] |
|
170 | @best[:runtime][:lang] = lang |
|
169 | @best[:runtime][:lang] = lang |
|
171 | end |
|
170 | end |
|
172 | if @best[:memory][:value] >= prop[:memory][:value] |
|
171 | if @best[:memory][:value] >= prop[:memory][:value] |
|
173 | @best[:memory] = prop[:memory] |
|
172 | @best[:memory] = prop[:memory] |
|
174 | @best[:memory][:lang] = lang |
|
173 | @best[:memory][:lang] = lang |
|
175 | end |
|
174 | end |
|
176 | if @best[:length][:value] >= prop[:length][:value] |
|
175 | if @best[:length][:value] >= prop[:length][:value] |
|
177 | @best[:length] = prop[:length] |
|
176 | @best[:length] = prop[:length] |
|
178 | @best[:length][:lang] = lang |
|
177 | @best[:length][:lang] = lang |
|
179 | end |
|
178 | end |
|
180 | if @best[:first][:value] >= prop[:first][:value] |
|
179 | if @best[:first][:value] >= prop[:first][:value] |
|
181 | @best[:first] = prop[:first] |
|
180 | @best[:first] = prop[:first] |
|
182 | @best[:first][:lang] = lang |
|
181 | @best[:first][:lang] = lang |
|
183 | end |
|
182 | end |
|
184 | end |
|
183 | end |
|
185 | end |
|
184 | end |
|
186 |
|
185 | ||
|
187 | @histogram[:summary][:max] = [@histogram[:data].max,1].max |
|
186 | @histogram[:summary][:max] = [@histogram[:data].max,1].max |
|
188 | @summary[:attempt] = user.count |
|
187 | @summary[:attempt] = user.count |
|
189 | user.each_value { |v| @summary[:solve] += 1 if v == 1 } |
|
188 | user.each_value { |v| @summary[:solve] += 1 if v == 1 } |
|
190 | end |
|
189 | end |
|
191 |
|
190 | ||
|
192 | end |
|
191 | end |
@@ -18,159 +18,177 | |||||
|
18 |
|
18 | ||
|
19 | verify :method => :post, :only => [:chg_passwd], |
|
19 | verify :method => :post, :only => [:chg_passwd], |
|
20 | :redirect_to => { :action => :index } |
|
20 | :redirect_to => { :action => :index } |
|
21 |
|
21 | ||
|
22 | #in_place_edit_for :user, :alias_for_editing |
|
22 | #in_place_edit_for :user, :alias_for_editing |
|
23 | #in_place_edit_for :user, :email_for_editing |
|
23 | #in_place_edit_for :user, :email_for_editing |
|
24 |
|
24 | ||
|
25 | def index |
|
25 | def index |
|
26 | if !GraderConfiguration['system.user_setting_enabled'] |
|
26 | if !GraderConfiguration['system.user_setting_enabled'] |
|
27 | redirect_to :controller => 'main', :action => 'list' |
|
27 | redirect_to :controller => 'main', :action => 'list' |
|
28 | else |
|
28 | else |
|
29 | @user = User.find(session[:user_id]) |
|
29 | @user = User.find(session[:user_id]) |
|
30 | end |
|
30 | end |
|
31 | end |
|
31 | end |
|
32 |
|
32 | ||
|
33 | def chg_passwd |
|
33 | def chg_passwd |
|
34 | user = User.find(session[:user_id]) |
|
34 | user = User.find(session[:user_id]) |
|
35 | user.password = params[:passwd] |
|
35 | user.password = params[:passwd] |
|
36 | user.password_confirmation = params[:passwd_verify] |
|
36 | user.password_confirmation = params[:passwd_verify] |
|
37 | if user.save |
|
37 | if user.save |
|
38 | flash[:notice] = 'password changed' |
|
38 | flash[:notice] = 'password changed' |
|
39 | else |
|
39 | else |
|
40 | flash[:notice] = 'Error: password changing failed' |
|
40 | flash[:notice] = 'Error: password changing failed' |
|
41 | end |
|
41 | end |
|
42 | redirect_to :action => 'index' |
|
42 | redirect_to :action => 'index' |
|
43 | end |
|
43 | end |
|
44 |
|
44 | ||
|
45 | def new |
|
45 | def new |
|
46 | @user = User.new |
|
46 | @user = User.new |
|
47 | render :action => 'new', :layout => 'empty' |
|
47 | render :action => 'new', :layout => 'empty' |
|
48 | end |
|
48 | end |
|
49 |
|
49 | ||
|
50 | def register |
|
50 | def register |
|
51 | if(params[:cancel]) |
|
51 | if(params[:cancel]) |
|
52 | redirect_to :controller => 'main', :action => 'login' |
|
52 | redirect_to :controller => 'main', :action => 'login' |
|
53 | return |
|
53 | return |
|
54 | end |
|
54 | end |
|
55 | @user = User.new(params[:user]) |
|
55 | @user = User.new(params[:user]) |
|
56 | @user.password_confirmation = @user.password = User.random_password |
|
56 | @user.password_confirmation = @user.password = User.random_password |
|
57 | @user.activated = false |
|
57 | @user.activated = false |
|
58 | if (@user.valid?) and (@user.save) |
|
58 | if (@user.valid?) and (@user.save) |
|
59 | if send_confirmation_email(@user) |
|
59 | if send_confirmation_email(@user) |
|
60 | render :action => 'new_splash', :layout => 'empty' |
|
60 | render :action => 'new_splash', :layout => 'empty' |
|
61 | else |
|
61 | else |
|
62 | @admin_email = GraderConfiguration['system.admin_email'] |
|
62 | @admin_email = GraderConfiguration['system.admin_email'] |
|
63 | render :action => 'email_error', :layout => 'empty' |
|
63 | render :action => 'email_error', :layout => 'empty' |
|
64 | end |
|
64 | end |
|
65 | else |
|
65 | else |
|
66 | @user.errors.add_to_base("Email cannot be blank") if @user.email=='' |
|
66 | @user.errors.add_to_base("Email cannot be blank") if @user.email=='' |
|
67 | render :action => 'new', :layout => 'empty' |
|
67 | render :action => 'new', :layout => 'empty' |
|
68 | end |
|
68 | end |
|
69 | end |
|
69 | end |
|
70 |
|
70 | ||
|
71 | def confirm |
|
71 | def confirm |
|
72 | login = params[:login] |
|
72 | login = params[:login] |
|
73 | key = params[:activation] |
|
73 | key = params[:activation] |
|
74 | @user = User.find_by_login(login) |
|
74 | @user = User.find_by_login(login) |
|
75 | if (@user) and (@user.verify_activation_key(key)) |
|
75 | if (@user) and (@user.verify_activation_key(key)) |
|
76 | if @user.valid? # check uniquenss of email |
|
76 | if @user.valid? # check uniquenss of email |
|
77 | @user.activated = true |
|
77 | @user.activated = true |
|
78 | @user.save |
|
78 | @user.save |
|
79 | @result = :successful |
|
79 | @result = :successful |
|
80 | else |
|
80 | else |
|
81 | @result = :email_used |
|
81 | @result = :email_used |
|
82 | end |
|
82 | end |
|
83 | else |
|
83 | else |
|
84 | @result = :failed |
|
84 | @result = :failed |
|
85 | end |
|
85 | end |
|
86 | render :action => 'confirm', :layout => 'empty' |
|
86 | render :action => 'confirm', :layout => 'empty' |
|
87 | end |
|
87 | end |
|
88 |
|
88 | ||
|
89 | def forget |
|
89 | def forget |
|
90 | render :action => 'forget', :layout => 'empty' |
|
90 | render :action => 'forget', :layout => 'empty' |
|
91 | end |
|
91 | end |
|
92 |
|
92 | ||
|
93 | def retrieve_password |
|
93 | def retrieve_password |
|
94 | email = params[:email] |
|
94 | email = params[:email] |
|
95 | user = User.find_by_email(email) |
|
95 | user = User.find_by_email(email) |
|
96 | if user |
|
96 | if user |
|
97 | last_updated_time = user.updated_at || user.created_at || (Time.now.gmtime - 1.hour) |
|
97 | last_updated_time = user.updated_at || user.created_at || (Time.now.gmtime - 1.hour) |
|
98 | if last_updated_time > Time.now.gmtime - 5.minutes |
|
98 | if last_updated_time > Time.now.gmtime - 5.minutes |
|
99 | flash[:notice] = 'The account has recently created or new password has recently been requested. Please wait for 5 minutes' |
|
99 | flash[:notice] = 'The account has recently created or new password has recently been requested. Please wait for 5 minutes' |
|
100 | else |
|
100 | else |
|
101 | user.password = user.password_confirmation = User.random_password |
|
101 | user.password = user.password_confirmation = User.random_password |
|
102 | user.save |
|
102 | user.save |
|
103 | send_new_password_email(user) |
|
103 | send_new_password_email(user) |
|
104 | flash[:notice] = 'New password has been mailed to you.' |
|
104 | flash[:notice] = 'New password has been mailed to you.' |
|
105 | end |
|
105 | end |
|
106 | else |
|
106 | else |
|
107 | flash[:notice] = I18n.t 'registration.password_retrieval.no_email' |
|
107 | flash[:notice] = I18n.t 'registration.password_retrieval.no_email' |
|
108 | end |
|
108 | end |
|
109 | redirect_to :action => 'forget' |
|
109 | redirect_to :action => 'forget' |
|
110 | end |
|
110 | end |
|
111 |
|
111 | ||
|
112 | def profile |
|
112 | def profile |
|
113 | @user = User.find(params[:id]) |
|
113 | @user = User.find(params[:id]) |
|
114 |
- @submission = Submission.where(user_id: params[:id]) |
|
114 | + @submission = Submission.includes(:problem).where(user_id: params[:id]) |
|
|
115 | + | ||
|
|
116 | + range = 120 | ||
|
|
117 | + @histogram = { data: Array.new(range,0), summary: {} } | ||
|
|
118 | + @summary = {count: 0, solve: 0, attempt: 0} | ||
|
|
119 | + problem = Hash.new(0) | ||
|
|
120 | + | ||
|
|
121 | + @submission.find_each do |sub| | ||
|
|
122 | + #histogram | ||
|
|
123 | + d = (DateTime.now.in_time_zone - sub.submitted_at) / 24 / 60 / 60 | ||
|
|
124 | + @histogram[:data][d.to_i] += 1 if d < range | ||
|
|
125 | + | ||
|
|
126 | + @summary[:count] += 1 | ||
|
|
127 | + problem[sub.problem] = [problem[sub.problem], (sub.points >= sub.problem.full_score) ? 1 : 0].max | ||
|
|
128 | + end | ||
|
|
129 | + | ||
|
|
130 | + @histogram[:summary][:max] = [@histogram[:data].max,1].max | ||
|
|
131 | + @summary[:attempt] = problem.count | ||
|
|
132 | + problem.each_value { |v| @summary[:solve] += 1 if v == 1 } | ||
|
115 | end |
|
133 | end |
|
116 |
|
134 | ||
|
117 | protected |
|
135 | protected |
|
118 |
|
136 | ||
|
119 | def verify_online_registration |
|
137 | def verify_online_registration |
|
120 | if !GraderConfiguration['system.online_registration'] |
|
138 | if !GraderConfiguration['system.online_registration'] |
|
121 | redirect_to :controller => 'main', :action => 'login' |
|
139 | redirect_to :controller => 'main', :action => 'login' |
|
122 | end |
|
140 | end |
|
123 | end |
|
141 | end |
|
124 |
|
142 | ||
|
125 | def send_confirmation_email(user) |
|
143 | def send_confirmation_email(user) |
|
126 | contest_name = GraderConfiguration['contest.name'] |
|
144 | contest_name = GraderConfiguration['contest.name'] |
|
127 | activation_url = url_for(:action => 'confirm', |
|
145 | activation_url = url_for(:action => 'confirm', |
|
128 | :login => user.login, |
|
146 | :login => user.login, |
|
129 | :activation => user.activation_key) |
|
147 | :activation => user.activation_key) |
|
130 | home_url = url_for(:controller => 'main', :action => 'index') |
|
148 | home_url = url_for(:controller => 'main', :action => 'index') |
|
131 | mail_subject = "[#{contest_name}] Confirmation" |
|
149 | mail_subject = "[#{contest_name}] Confirmation" |
|
132 | mail_body = t('registration.email_body', { |
|
150 | mail_body = t('registration.email_body', { |
|
133 | :full_name => user.full_name, |
|
151 | :full_name => user.full_name, |
|
134 | :contest_name => contest_name, |
|
152 | :contest_name => contest_name, |
|
135 | :login => user.login, |
|
153 | :login => user.login, |
|
136 | :password => user.password, |
|
154 | :password => user.password, |
|
137 | :activation_url => activation_url, |
|
155 | :activation_url => activation_url, |
|
138 | :admin_email => admin_email |
|
156 | :admin_email => admin_email |
|
139 | }) |
|
157 | }) |
|
140 |
|
158 | ||
|
141 | logger.info mail_body |
|
159 | logger.info mail_body |
|
142 |
|
160 | ||
|
143 | send_mail(user.email, mail_subject, mail_body) |
|
161 | send_mail(user.email, mail_subject, mail_body) |
|
144 | end |
|
162 | end |
|
145 |
|
163 | ||
|
146 | def send_new_password_email(user) |
|
164 | def send_new_password_email(user) |
|
147 | contest_name = GraderConfiguration['contest.name'] |
|
165 | contest_name = GraderConfiguration['contest.name'] |
|
148 | mail_subject = "[#{contest_name}] Password recovery" |
|
166 | mail_subject = "[#{contest_name}] Password recovery" |
|
149 | mail_body = t('registration.password_retrieval.email_body', { |
|
167 | mail_body = t('registration.password_retrieval.email_body', { |
|
150 | :full_name => user.full_name, |
|
168 | :full_name => user.full_name, |
|
151 | :contest_name => contest_name, |
|
169 | :contest_name => contest_name, |
|
152 | :login => user.login, |
|
170 | :login => user.login, |
|
153 | :password => user.password, |
|
171 | :password => user.password, |
|
154 | :admin_email => admin_email |
|
172 | :admin_email => admin_email |
|
155 | }) |
|
173 | }) |
|
156 |
|
174 | ||
|
157 | logger.info mail_body |
|
175 | logger.info mail_body |
|
158 |
|
176 | ||
|
159 | send_mail(user.email, mail_subject, mail_body) |
|
177 | send_mail(user.email, mail_subject, mail_body) |
|
160 | end |
|
178 | end |
|
161 |
|
179 | ||
|
162 | # allow viewing of regular user profile only when options allow so |
|
180 | # allow viewing of regular user profile only when options allow so |
|
163 | # only admins can view admins profile |
|
181 | # only admins can view admins profile |
|
164 | def profile_authorization |
|
182 | def profile_authorization |
|
165 | #if view admins' profile, allow only admin |
|
183 | #if view admins' profile, allow only admin |
|
166 | return false unless(params[:id]) |
|
184 | return false unless(params[:id]) |
|
167 | user = User.find(params[:id]) |
|
185 | user = User.find(params[:id]) |
|
168 | return false unless user |
|
186 | return false unless user |
|
169 | return admin_authorization if user.admin? |
|
187 | return admin_authorization if user.admin? |
|
170 | return true if GraderConfiguration["right.user_view_submission"] |
|
188 | return true if GraderConfiguration["right.user_view_submission"] |
|
171 |
|
189 | ||
|
172 | #finally, we allow only admin |
|
190 | #finally, we allow only admin |
|
173 | admin_authorization |
|
191 | admin_authorization |
|
174 | end |
|
192 | end |
|
175 |
|
193 | ||
|
176 | end |
|
194 | end |
@@ -1,44 +1,44 | |||||
|
1 | - param = {} unless param |
|
1 | - param = {} unless param |
|
2 | - graph_height = param[:graph_height] || 100 |
|
2 | - graph_height = param[:graph_height] || 100 |
|
3 | - bar_width = param[:bar_width] || 14 |
|
3 | - bar_width = param[:bar_width] || 14 |
|
4 | - graph_width = (bar_width * histogram[:data].count) + 20 |
|
4 | - graph_width = (bar_width * histogram[:data].count) + 20 |
|
5 | :css |
|
5 | :css |
|
6 | .hist_bar { |
|
6 | .hist_bar { |
|
7 | width: #{bar_width-1}px; |
|
7 | width: #{bar_width-1}px; |
|
8 | position: absolute; |
|
8 | position: absolute; |
|
9 | background-color: lightblue; |
|
9 | background-color: lightblue; |
|
10 | } |
|
10 | } |
|
11 | .hist_fill { |
|
11 | .hist_fill { |
|
12 | width: #{bar_width-1}px; |
|
12 | width: #{bar_width-1}px; |
|
13 | position: absolute; |
|
13 | position: absolute; |
|
14 | background-color: #eee; |
|
14 | background-color: #eee; |
|
15 | } |
|
15 | } |
|
16 | .hist_text { |
|
16 | .hist_text { |
|
17 | position: absolute; |
|
17 | position: absolute; |
|
18 | font-size:5px; |
|
18 | font-size:5px; |
|
19 | } |
|
19 | } |
|
20 |
|
20 | ||
|
21 |
- %div{style: "position: relative; width: #{graph_width}px; height: 15 |
|
21 | + %div{style: "position: relative; width: #{graph_width}px; height: 125px; background-color:#fff;" } |
|
22 | //draw background |
|
22 | //draw background |
|
23 | - histogram[:data].each_index do |i| |
|
23 | - histogram[:data].each_index do |i| |
|
24 | - height = histogram[:data][i] * graph_height / histogram[:summary][:max] |
|
24 | - height = histogram[:data][i] * graph_height / histogram[:summary][:max] |
|
25 | - top = graph_height - height |
|
25 | - top = graph_height - height |
|
26 | - left = graph_width - (i+1)*bar_width |
|
26 | - left = graph_width - (i+1)*bar_width |
|
27 | %div.hist_fill{style: "top: 0px; height: #{graph_height - height}px; left: #{left}px;" } |
|
27 | %div.hist_fill{style: "top: 0px; height: #{graph_height - height}px; left: #{left}px;" } |
|
28 | // draw horizontal line |
|
28 | // draw horizontal line |
|
29 | - line = 3 |
|
29 | - line = 3 |
|
30 | - line.times do |i| |
|
30 | - line.times do |i| |
|
31 | - top = graph_height - graph_height * (i+0.5)/ line |
|
31 | - top = graph_height - graph_height * (i+0.5)/ line |
|
32 | %div{style: "position:absolute;width: #{graph_width-21}px;height: 1px;left: 20px;top:#{top}px;background-color: #333;"} |
|
32 | %div{style: "position:absolute;width: #{graph_width-21}px;height: 1px;left: 20px;top:#{top}px;background-color: #333;"} |
|
33 | %div.hist_text{style: "position:absolute;left: 0px;top:#{top-6}px"} |
|
33 | %div.hist_text{style: "position:absolute;left: 0px;top:#{top-6}px"} |
|
34 | =((i+0.5) * histogram[:summary][:max] / line).to_i |
|
34 | =((i+0.5) * histogram[:summary][:max] / line).to_i |
|
35 | // draw the actual bar and text |
|
35 | // draw the actual bar and text |
|
36 | - @histogram[:data].each_index do |i| |
|
36 | - @histogram[:data].each_index do |i| |
|
37 | - height = histogram[:data][i] * graph_height / histogram[:summary][:max] |
|
37 | - height = histogram[:data][i] * graph_height / histogram[:summary][:max] |
|
38 | - top = graph_height - height |
|
38 | - top = graph_height - height |
|
39 | - left = graph_width - (i+1)*bar_width |
|
39 | - left = graph_width - (i+1)*bar_width |
|
40 | %div.hist_bar{style: "top: #{top}px; height: #{height}px; left: #{left}px; dae: #{histogram[:data][i]}" } |
|
40 | %div.hist_bar{style: "top: #{top}px; height: #{height}px; left: #{left}px; dae: #{histogram[:data][i]}" } |
|
41 | - if i % 7 == 1 |
|
41 | - if i % 7 == 1 |
|
42 | %div.hist_text{style: "top:#{graph_height + 5}px;left: #{left}px;"} #{(Time.zone.today - i.day).strftime('%-d')} |
|
42 | %div.hist_text{style: "top:#{graph_height + 5}px;left: #{left}px;"} #{(Time.zone.today - i.day).strftime('%-d')} |
|
43 | - if (Time.now.in_time_zone - i.day).day == 15 |
|
43 | - if (Time.now.in_time_zone - i.day).day == 15 |
|
44 | %div.hist_text{style: "top:#{graph_height + 15}px;left: #{left}px;"} #{(Time.zone.today - i.day).strftime('%b')} |
|
44 | %div.hist_text{style: "top:#{graph_height + 15}px;left: #{left}px;"} #{(Time.zone.today - i.day).strftime('%b')} |
@@ -1,96 +1,128 | |||||
|
|
1 | + - content_for :header do | ||
|
|
2 | + = javascript_include_tag 'local_jquery' | ||
|
|
3 | + | ||
|
|
4 | + :javascript | ||
|
|
5 | + $(document).ready( function() { | ||
|
|
6 | + $("#mem_remark").hover( function() { | ||
|
|
7 | + $("#mem_remark_box").show(); | ||
|
|
8 | + }, function() { | ||
|
|
9 | + $("#mem_remark_box").hide(); | ||
|
|
10 | + }); | ||
|
|
11 | + }); | ||
|
|
12 | + alert("hahaha"); | ||
|
1 | :css |
|
13 | :css |
|
2 | .hof_user { color: orangered; font-style: italic; } |
|
14 | .hof_user { color: orangered; font-style: italic; } |
|
3 | .hof_language { color: green; font-style: italic; } |
|
15 | .hof_language { color: green; font-style: italic; } |
|
4 | .hof_value { color: deeppink;font-style: italic; } |
|
16 | .hof_value { color: deeppink;font-style: italic; } |
|
5 | .info_param { font-weight: bold;text-align: right; } |
|
17 | .info_param { font-weight: bold;text-align: right; } |
|
|
18 | + .tooltip { | ||
|
|
19 | + font-family: Verdana,sans-serif; | ||
|
|
20 | + font-weight: normal; | ||
|
|
21 | + text-align: left; | ||
|
|
22 | + font-size: 1.0em; | ||
|
|
23 | + color: black; | ||
|
|
24 | + line-height: 1.1; | ||
|
|
25 | + display: none; | ||
|
|
26 | + min-width: 20em; | ||
|
|
27 | + position: absolute; | ||
|
|
28 | + left: 25px; | ||
|
|
29 | + bottom: 5px; | ||
|
|
30 | + border: 1px solid; | ||
|
|
31 | + padding: 5px; | ||
|
|
32 | + background-color: #FFF; | ||
|
|
33 | + word-wrap: break-word; | ||
|
|
34 | + z-index: 9999; | ||
|
|
35 | + overflow: auto; | ||
|
|
36 | + } | ||
|
6 |
|
37 | ||
|
7 | %h1 (#{Problem.find(params[:id]).name}) #{Problem.find(params[:id]).full_name} |
|
38 | %h1 (#{Problem.find(params[:id]).name}) #{Problem.find(params[:id]).full_name} |
|
8 |
|
39 | ||
|
9 | %h2 Problem Stat |
|
40 | %h2 Problem Stat |
|
10 | %table.info |
|
41 | %table.info |
|
11 | %thead |
|
42 | %thead |
|
12 | %tr.info-head |
|
43 | %tr.info-head |
|
13 | %th Stat |
|
44 | %th Stat |
|
14 | %th Value |
|
45 | %th Value |
|
15 | %tbody |
|
46 | %tbody |
|
16 | %tr{class: cycle('info-even','info-odd')} |
|
47 | %tr{class: cycle('info-even','info-odd')} |
|
17 | %td.info_param Submissions |
|
48 | %td.info_param Submissions |
|
18 | %td= @summary[:count] |
|
49 | %td= @summary[:count] |
|
19 | %tr{class: cycle('info-even','info-odd')} |
|
50 | %tr{class: cycle('info-even','info-odd')} |
|
20 | %td.info_param Solved/Attempted User |
|
51 | %td.info_param Solved/Attempted User |
|
21 | %td #{@summary[:solve]}/#{@summary[:attempt]} (#{(@summary[:solve]*100.0/@summary[:attempt]).round(1)}%) |
|
52 | %td #{@summary[:solve]}/#{@summary[:attempt]} (#{(@summary[:solve]*100.0/@summary[:attempt]).round(1)}%) |
|
22 | - if @best |
|
53 | - if @best |
|
23 | %tr{class: cycle('info-even','info-odd')} |
|
54 | %tr{class: cycle('info-even','info-odd')} |
|
24 | %td.info_param Best Runtime |
|
55 | %td.info_param Best Runtime |
|
25 | %td |
|
56 | %td |
|
26 | by #{link_to @best[:runtime][:user], controller:'users', action:'profile', id:@best[:memory][:user_id]} |
|
57 | by #{link_to @best[:runtime][:user], controller:'users', action:'profile', id:@best[:memory][:user_id]} |
|
27 | using <span class="hof_language">#{@best[:runtime][:lang]}</span> |
|
58 | using <span class="hof_language">#{@best[:runtime][:lang]}</span> |
|
28 | with <span class="hof_value">#{@best[:runtime][:value] * 1000} milliseconds</span> |
|
59 | with <span class="hof_value">#{@best[:runtime][:value] * 1000} milliseconds</span> |
|
29 | at submission |
|
60 | at submission |
|
30 | = link_to("#" + @best[:runtime][:sub_id].to_s, controller: 'graders', action: 'submission', id:@best[:runtime][:sub_id]) |
|
61 | = link_to("#" + @best[:runtime][:sub_id].to_s, controller: 'graders', action: 'submission', id:@best[:runtime][:sub_id]) |
|
31 |
|
62 | ||
|
32 | %tr{class: cycle('info-even','info-odd')} |
|
63 | %tr{class: cycle('info-even','info-odd')} |
|
33 |
- %td.info_param |
|
64 | + %td.info_param |
|
|
65 | + Best Memory Usage | ||
|
|
66 | + %sup{ id: "mem_remark", style: "position:relative; color: blue;"} | ||
|
|
67 | + [?] | ||
|
|
68 | + %span.tooltip#mem_remark_box | ||
|
|
69 | + This counts only for submission with 100% score. | ||
|
|
70 | + Right now, java is excluded from memory usage competition. (Because it always uses 2GB memory...) | ||
|
34 | %td |
|
71 | %td |
|
35 | by #{link_to @best[:memory][:user], controller:'users', action:'profile', id:@best[:memory][:user_id]} |
|
72 | by #{link_to @best[:memory][:user], controller:'users', action:'profile', id:@best[:memory][:user_id]} |
|
36 | using <span class="hof_language">#{@best[:memory][:lang]}</span> |
|
73 | using <span class="hof_language">#{@best[:memory][:lang]}</span> |
|
37 | with <span class="hof_value">#{number_with_delimiter(@best[:memory][:value])} kbytes </span> |
|
74 | with <span class="hof_value">#{number_with_delimiter(@best[:memory][:value])} kbytes </span> |
|
38 | at submission |
|
75 | at submission |
|
39 | = link_to("#" + @best[:memory][:sub_id].to_s, controller: 'graders' , action: 'submission', id:@best[:memory][:sub_id]) |
|
76 | = link_to("#" + @best[:memory][:sub_id].to_s, controller: 'graders' , action: 'submission', id:@best[:memory][:sub_id]) |
|
40 |
|
77 | ||
|
41 | %tr{class: cycle('info-even','info-odd')} |
|
78 | %tr{class: cycle('info-even','info-odd')} |
|
42 | %td.info_param Shortest Code |
|
79 | %td.info_param Shortest Code |
|
43 | %td |
|
80 | %td |
|
44 | by #{link_to @best[:length][:user], controller:'users', action:'profile', id:@best[:length][:user_id]} |
|
81 | by #{link_to @best[:length][:user], controller:'users', action:'profile', id:@best[:length][:user_id]} |
|
45 | using <span class="hof_language">#{@best[:length][:lang]}</span> |
|
82 | using <span class="hof_language">#{@best[:length][:lang]}</span> |
|
46 | with <span class="hof_value">#{@best[:length][:value]} bytes</span> |
|
83 | with <span class="hof_value">#{@best[:length][:value]} bytes</span> |
|
47 | at submission |
|
84 | at submission |
|
48 | = link_to("#" + @best[:length][:sub_id].to_s, controller: 'graders' , action: 'submission', id: @best[:length][:sub_id]) |
|
85 | = link_to("#" + @best[:length][:sub_id].to_s, controller: 'graders' , action: 'submission', id: @best[:length][:sub_id]) |
|
49 |
|
86 | ||
|
50 | %tr{class: cycle('info-even','info-odd')} |
|
87 | %tr{class: cycle('info-even','info-odd')} |
|
51 | %td.info_param First solver |
|
88 | %td.info_param First solver |
|
52 | %td |
|
89 | %td |
|
53 | #{link_to @best[:first][:user], controller:'users', action:'profile', id:@best[:first][:user_id]} is the first solver |
|
90 | #{link_to @best[:first][:user], controller:'users', action:'profile', id:@best[:first][:user_id]} is the first solver |
|
54 | using <span class="hof_language">#{@best[:first][:lang]}</span> |
|
91 | using <span class="hof_language">#{@best[:first][:lang]}</span> |
|
55 | on <span class="hof_value">#{@best[:first][:value]}</span> |
|
92 | on <span class="hof_value">#{@best[:first][:value]}</span> |
|
56 | at submission |
|
93 | at submission |
|
57 | = link_to("#" + @best[:first][:sub_id].to_s, controller: 'graders' , action: 'submission', id: @best[:first][:sub_id]) |
|
94 | = link_to("#" + @best[:first][:sub_id].to_s, controller: 'graders' , action: 'submission', id: @best[:first][:sub_id]) |
|
58 |
|
95 | ||
|
59 | - |
|
||
|
60 | - %p |
|
||
|
61 | - This counts only for submission with 100% score <br/> |
|
||
|
62 | - Right now, java is excluded from memory usage competition. (Because it always uses 2GB memory...) |
|
||
|
63 | - |
|
||
|
64 | - if @best |
|
96 | - if @best |
|
65 | %h2 By language |
|
97 | %h2 By language |
|
66 |
|
98 | ||
|
67 | %table.info |
|
99 | %table.info |
|
68 | %thead |
|
100 | %thead |
|
69 | %tr.info-head |
|
101 | %tr.info-head |
|
70 | %th Language |
|
102 | %th Language |
|
71 | %th Best runtime (ms) |
|
103 | %th Best runtime (ms) |
|
72 | %th Best memory (kbytes) |
|
104 | %th Best memory (kbytes) |
|
73 | %th Shortest Code (bytes) |
|
105 | %th Shortest Code (bytes) |
|
74 | %th First solver |
|
106 | %th First solver |
|
75 | %tbody |
|
107 | %tbody |
|
76 | - @by_lang.each do |lang,value| |
|
108 | - @by_lang.each do |lang,value| |
|
77 | %tr{class: cycle('info-even','info-odd')} |
|
109 | %tr{class: cycle('info-even','info-odd')} |
|
78 | %td= lang |
|
110 | %td= lang |
|
79 | %td |
|
111 | %td |
|
80 | = link_to value[:runtime][:user], controller: 'users', action: 'profile', id: value[:runtime][:user_id] |
|
112 | = link_to value[:runtime][:user], controller: 'users', action: 'profile', id: value[:runtime][:user_id] |
|
81 | = "(#{(value[:runtime][:value] * 1000).to_i} @" |
|
113 | = "(#{(value[:runtime][:value] * 1000).to_i} @" |
|
82 | = "#{link_to("#" + value[:runtime][:sub_id].to_s, controller: 'graders' , action: 'submission', id: value[:runtime][:sub_id])} )".html_safe |
|
114 | = "#{link_to("#" + value[:runtime][:sub_id].to_s, controller: 'graders' , action: 'submission', id: value[:runtime][:sub_id])} )".html_safe |
|
83 | %td |
|
115 | %td |
|
84 | = link_to value[:memory][:user], controller: 'users', action: 'profile', id: value[:memory][:user_id] |
|
116 | = link_to value[:memory][:user], controller: 'users', action: 'profile', id: value[:memory][:user_id] |
|
85 | = "(#{number_with_delimiter(value[:memory][:value])} @" |
|
117 | = "(#{number_with_delimiter(value[:memory][:value])} @" |
|
86 | = "#{link_to("#" + value[:memory][:sub_id].to_s, controller: 'graders' , action: 'submission', id: value[:memory][:sub_id])} )".html_safe |
|
118 | = "#{link_to("#" + value[:memory][:sub_id].to_s, controller: 'graders' , action: 'submission', id: value[:memory][:sub_id])} )".html_safe |
|
87 | %td |
|
119 | %td |
|
88 | = link_to value[:length][:user], controller: 'users', action: 'profile', id: value[:length][:user_id] |
|
120 | = link_to value[:length][:user], controller: 'users', action: 'profile', id: value[:length][:user_id] |
|
89 | = "(#{value[:length][:value]} @" |
|
121 | = "(#{value[:length][:value]} @" |
|
90 | = "#{link_to("#" + value[:length][:sub_id].to_s, controller: 'graders' , action: 'submission', id: value[:length][:sub_id])} )".html_safe |
|
122 | = "#{link_to("#" + value[:length][:sub_id].to_s, controller: 'graders' , action: 'submission', id: value[:length][:sub_id])} )".html_safe |
|
91 | %td |
|
123 | %td |
|
92 | - if value[:first][:user] != '(NULL)' #TODO: i know... this is wrong... |
|
124 | - if value[:first][:user] != '(NULL)' #TODO: i know... this is wrong... |
|
93 | = link_to value[:first][:user], controller: 'users', action: 'profile', id: value[:first][:user_id] |
|
125 | = link_to value[:first][:user], controller: 'users', action: 'profile', id: value[:first][:user_id] |
|
94 | = "(#{value[:first][:value]} @" |
|
126 | = "(#{value[:first][:value]} @" |
|
95 | = "#{link_to("#" + value[:first][:sub_id].to_s, controller: 'graders' , action: 'submission', id: value[:first][:sub_id])} )".html_safe |
|
127 | = "#{link_to("#" + value[:first][:sub_id].to_s, controller: 'graders' , action: 'submission', id: value[:first][:sub_id])} )".html_safe |
|
96 |
|
128 |
@@ -1,52 +1,66 | |||||
|
1 | - content_for :header do |
|
1 | - content_for :header do |
|
2 | = javascript_include_tag 'local_jquery' |
|
2 | = javascript_include_tag 'local_jquery' |
|
3 |
|
3 | ||
|
4 | - %script{:type=>"text/javascript"} |
|
4 | + :javascript |
|
5 | $(function () { |
|
5 | $(function () { |
|
6 | $('#submission_table').tablesorter({widgets: ['zebra']}); |
|
6 | $('#submission_table').tablesorter({widgets: ['zebra']}); |
|
7 | }); |
|
7 | }); |
|
8 |
|
8 | ||
|
9 | :css |
|
9 | :css |
|
10 | .fix-width { |
|
10 | .fix-width { |
|
11 | font-family: Droid Sans Mono,Consolas, monospace, mono, Courier New, Courier; |
|
11 | font-family: Droid Sans Mono,Consolas, monospace, mono, Courier New, Courier; |
|
12 | } |
|
12 | } |
|
13 |
|
13 | ||
|
14 |
- %h1= @user.full_name |
|
14 | + %h1= @user.full_name |
|
15 |
|
15 | ||
|
16 | - %h2 Basic info |
|
||
|
17 | <b>Login:</b> #{@user.login} <br/> |
|
16 | <b>Login:</b> #{@user.login} <br/> |
|
18 | <b>Full name:</b> #{@user.full_name} <br /> |
|
17 | <b>Full name:</b> #{@user.full_name} <br /> |
|
19 |
|
18 | ||
|
20 |
|
19 | ||
|
21 | %h2 Problem Stat |
|
20 | %h2 Problem Stat |
|
|
21 | + %table.info | ||
|
|
22 | + %thead | ||
|
|
23 | + %tr.info-head | ||
|
|
24 | + %th Stat | ||
|
|
25 | + %th Value | ||
|
|
26 | + %tbody | ||
|
|
27 | + %tr{class: cycle('info-even','info-odd')} | ||
|
|
28 | + %td.info_param Submissions | ||
|
|
29 | + %td= @summary[:count] | ||
|
|
30 | + %tr{class: cycle('info-even','info-odd')} | ||
|
|
31 | + %td.info_param Solved/Attempted Problem | ||
|
|
32 | + %td #{@summary[:solve]}/#{@summary[:attempt]} (#{(@summary[:solve]*100.0/@summary[:attempt]).round(1)}%) | ||
|
22 |
|
33 | ||
|
23 | - %h2 Submissions |
|
34 | + %h2 Submission History |
|
|
35 | + | ||
|
|
36 | + =render partial: 'application/bar_graph', locals: {histogram: @histogram, param: {bar_width: 7}} | ||
|
|
37 | + | ||
|
24 |
|
38 | ||
|
25 | %table.tablesorter-cafe#submission_table |
|
39 | %table.tablesorter-cafe#submission_table |
|
26 | %thead |
|
40 | %thead |
|
27 | %tr |
|
41 | %tr |
|
28 | %th ID |
|
42 | %th ID |
|
29 | %th Problem code |
|
43 | %th Problem code |
|
30 | %th Problem full name |
|
44 | %th Problem full name |
|
31 | %th Language |
|
45 | %th Language |
|
32 | %th Submitted at |
|
46 | %th Submitted at |
|
33 | %th Result |
|
47 | %th Result |
|
34 | %th Score |
|
48 | %th Score |
|
35 | - if session[:admin] |
|
49 | - if session[:admin] |
|
36 | %th IP |
|
50 | %th IP |
|
37 | %tbody |
|
51 | %tbody |
|
38 | - @submission.each do |s| |
|
52 | - @submission.each do |s| |
|
39 | - next unless s.problem |
|
53 | - next unless s.problem |
|
40 | %tr |
|
54 | %tr |
|
41 | %td= link_to "#{s.id}", controller: "graders", action: "submission", id: s.id |
|
55 | %td= link_to "#{s.id}", controller: "graders", action: "submission", id: s.id |
|
42 | %td= s.problem.name |
|
56 | %td= s.problem.name |
|
43 | %td= s.problem.full_name |
|
57 | %td= s.problem.full_name |
|
44 | %td= s.language.pretty_name |
|
58 | %td= s.language.pretty_name |
|
45 | %td #{s.submitted_at.strftime('%Y-%m-%d %H:%M')} (#{time_ago_in_words(s.submitted_at)} ago) |
|
59 | %td #{s.submitted_at.strftime('%Y-%m-%d %H:%M')} (#{time_ago_in_words(s.submitted_at)} ago) |
|
46 | %td.fix-width= s.grader_comment |
|
60 | %td.fix-width= s.grader_comment |
|
47 | %td= (s.points*100)/s.problem.full_score |
|
61 | %td= (s.points*100)/s.problem.full_score |
|
48 | - if session[:admin] |
|
62 | - if session[:admin] |
|
49 | %td= s.ip_address |
|
63 | %td= s.ip_address |
|
50 |
|
64 | ||
|
51 |
|
65 | ||
|
52 |
|
66 |
You need to be logged in to leave comments.
Login now