Description:
shows scores only for submitted problems
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r386:aef66acd0ee0 - - 2 files changed: 9 inserted, 5 deleted

@@ -1,476 +1,476
1 class UserAdminController < ApplicationController
1 class UserAdminController < ApplicationController
2
2
3 include MailHelperMethods
3 include MailHelperMethods
4
4
5 before_filter :admin_authorization
5 before_filter :admin_authorization
6
6
7 # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
7 # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
8 verify :method => :post, :only => [ :destroy,
8 verify :method => :post, :only => [ :destroy,
9 :create, :create_from_list,
9 :create, :create_from_list,
10 :update,
10 :update,
11 :manage_contest,
11 :manage_contest,
12 :bulk_mail
12 :bulk_mail
13 ],
13 ],
14 :redirect_to => { :action => :list }
14 :redirect_to => { :action => :list }
15
15
16 def index
16 def index
17 list
17 list
18 render :action => 'list'
18 render :action => 'list'
19 end
19 end
20
20
21 def list
21 def list
22 @user_count = User.count
22 @user_count = User.count
23 if params[:page] == 'all'
23 if params[:page] == 'all'
24 @users = User.all
24 @users = User.all
25 @paginated = false
25 @paginated = false
26 else
26 else
27 @users = User.paginate :page => params[:page]
27 @users = User.paginate :page => params[:page]
28 @paginated = true
28 @paginated = true
29 end
29 end
30 @hidden_columns = ['hashed_password', 'salt', 'created_at', 'updated_at']
30 @hidden_columns = ['hashed_password', 'salt', 'created_at', 'updated_at']
31 @contests = Contest.enabled
31 @contests = Contest.enabled
32 end
32 end
33
33
34 def active
34 def active
35 sessions = ActiveRecord::SessionStore::Session.find(:all, :conditions => ["updated_at >= ?", 60.minutes.ago])
35 sessions = ActiveRecord::SessionStore::Session.find(:all, :conditions => ["updated_at >= ?", 60.minutes.ago])
36 @users = []
36 @users = []
37 sessions.each do |session|
37 sessions.each do |session|
38 if session.data[:user_id]
38 if session.data[:user_id]
39 @users << User.find(session.data[:user_id])
39 @users << User.find(session.data[:user_id])
40 end
40 end
41 end
41 end
42 end
42 end
43
43
44 def show
44 def show
45 @user = User.find(params[:id])
45 @user = User.find(params[:id])
46 end
46 end
47
47
48 def new
48 def new
49 @user = User.new
49 @user = User.new
50 end
50 end
51
51
52 def create
52 def create
53 @user = User.new(params[:user])
53 @user = User.new(params[:user])
54 @user.activated = true
54 @user.activated = true
55 if @user.save
55 if @user.save
56 flash[:notice] = 'User was successfully created.'
56 flash[:notice] = 'User was successfully created.'
57 redirect_to :action => 'list'
57 redirect_to :action => 'list'
58 else
58 else
59 render :action => 'new'
59 render :action => 'new'
60 end
60 end
61 end
61 end
62
62
63 def create_from_list
63 def create_from_list
64 lines = params[:user_list]
64 lines = params[:user_list]
65
65
66 note = []
66 note = []
67
67
68 lines.split("\n").each do |line|
68 lines.split("\n").each do |line|
69 items = line.chomp.split(',')
69 items = line.chomp.split(',')
70 if items.length>=2
70 if items.length>=2
71 login = items[0]
71 login = items[0]
72 full_name = items[1]
72 full_name = items[1]
73
73
74 added_random_password = false
74 added_random_password = false
75 if items.length>=3
75 if items.length>=3
76 password = items[2].chomp(" ")
76 password = items[2].chomp(" ")
77 user_alias = (items.length>=4) ? items[3] : login
77 user_alias = (items.length>=4) ? items[3] : login
78 else
78 else
79 password = random_password
79 password = random_password
80 user_alias = (items.length>=4) ? items[3] : login
80 user_alias = (items.length>=4) ? items[3] : login
81 added_random_password = true
81 added_random_password = true
82 end
82 end
83
83
84 user = User.new({:login => login,
84 user = User.new({:login => login,
85 :full_name => full_name,
85 :full_name => full_name,
86 :password => password,
86 :password => password,
87 :password_confirmation => password,
87 :password_confirmation => password,
88 :alias => user_alias})
88 :alias => user_alias})
89 user.activated = true
89 user.activated = true
90 user.save
90 user.save
91
91
92 if added_random_password
92 if added_random_password
93 note << "'#{login}' (+)"
93 note << "'#{login}' (+)"
94 else
94 else
95 note << login
95 note << login
96 end
96 end
97 end
97 end
98 end
98 end
99 flash[:notice] = 'User(s) ' + note.join(', ') +
99 flash[:notice] = 'User(s) ' + note.join(', ') +
100 ' were successfully created. ' +
100 ' were successfully created. ' +
101 '( (+) - created with random passwords.)'
101 '( (+) - created with random passwords.)'
102 redirect_to :action => 'list'
102 redirect_to :action => 'list'
103 end
103 end
104
104
105 def edit
105 def edit
106 @user = User.find(params[:id])
106 @user = User.find(params[:id])
107 end
107 end
108
108
109 def update
109 def update
110 @user = User.find(params[:id])
110 @user = User.find(params[:id])
111 if @user.update_attributes(params[:user])
111 if @user.update_attributes(params[:user])
112 flash[:notice] = 'User was successfully updated.'
112 flash[:notice] = 'User was successfully updated.'
113 redirect_to :action => 'show', :id => @user
113 redirect_to :action => 'show', :id => @user
114 else
114 else
115 render :action => 'edit'
115 render :action => 'edit'
116 end
116 end
117 end
117 end
118
118
119 def destroy
119 def destroy
120 User.find(params[:id]).destroy
120 User.find(params[:id]).destroy
121 redirect_to :action => 'list'
121 redirect_to :action => 'list'
122 end
122 end
123
123
124 def user_stat
124 def user_stat
125 @problems = Problem.find_available_problems
125 @problems = Problem.find_available_problems
126 @users = User.find(:all, :include => [:contests, :contest_stat])
126 @users = User.find(:all, :include => [:contests, :contest_stat])
127 @scorearray = Array.new
127 @scorearray = Array.new
128 @users.each do |u|
128 @users.each do |u|
129 ustat = Array.new
129 ustat = Array.new
130 ustat[0] = u
130 ustat[0] = u
131 @problems.each do |p|
131 @problems.each do |p|
132 sub = Submission.find_last_by_user_and_problem(u.id,p.id)
132 sub = Submission.find_last_by_user_and_problem(u.id,p.id)
133 if (sub!=nil) and (sub.points!=nil)
133 if (sub!=nil) and (sub.points!=nil)
134 ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)]
134 ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)]
135 else
135 else
136 - ustat << [0,false]
136 + ustat << [nil,false]
137 end
137 end
138 end
138 end
139 @scorearray << ustat
139 @scorearray << ustat
140 end
140 end
141 end
141 end
142
142
143 def user_stat_max
143 def user_stat_max
144 @problems = Problem.find_available_problems
144 @problems = Problem.find_available_problems
145 @users = User.find(:all, :include => [:contests, :contest_stat])
145 @users = User.find(:all, :include => [:contests, :contest_stat])
146 @scorearray = Array.new
146 @scorearray = Array.new
147 #set up range from param
147 #set up range from param
148 since_id = params.fetch(:since_id, 0).to_i
148 since_id = params.fetch(:since_id, 0).to_i
149 until_id = params.fetch(:until_id, 0).to_i
149 until_id = params.fetch(:until_id, 0).to_i
150 @users.each do |u|
150 @users.each do |u|
151 ustat = Array.new
151 ustat = Array.new
152 ustat[0] = u
152 ustat[0] = u
153 @problems.each do |p|
153 @problems.each do |p|
154 max_points = 0
154 max_points = 0
155 Submission.find_in_range_by_user_and_problem(u.id,p.id,since_id,until_id).each do |sub|
155 Submission.find_in_range_by_user_and_problem(u.id,p.id,since_id,until_id).each do |sub|
156 max_points = sub.points if sub and sub.points and (sub.points > max_points)
156 max_points = sub.points if sub and sub.points and (sub.points > max_points)
157 end
157 end
158 ustat << [(max_points.to_f*100/p.full_score).round, (max_points>=p.full_score)]
158 ustat << [(max_points.to_f*100/p.full_score).round, (max_points>=p.full_score)]
159 end
159 end
160 @scorearray << ustat
160 @scorearray << ustat
161 end
161 end
162 end
162 end
163
163
164 def import
164 def import
165 if params[:file]==''
165 if params[:file]==''
166 flash[:notice] = 'Error importing no file'
166 flash[:notice] = 'Error importing no file'
167 redirect_to :action => 'list' and return
167 redirect_to :action => 'list' and return
168 end
168 end
169 import_from_file(params[:file])
169 import_from_file(params[:file])
170 end
170 end
171
171
172 def random_all_passwords
172 def random_all_passwords
173 users = User.find(:all)
173 users = User.find(:all)
174 @prefix = params[:prefix] || ''
174 @prefix = params[:prefix] || ''
175 @non_admin_users = User.find_non_admin_with_prefix(@prefix)
175 @non_admin_users = User.find_non_admin_with_prefix(@prefix)
176 @changed = false
176 @changed = false
177 if request.request_method == 'POST'
177 if request.request_method == 'POST'
178 @non_admin_users.each do |user|
178 @non_admin_users.each do |user|
179 password = random_password
179 password = random_password
180 user.password = password
180 user.password = password
181 user.password_confirmation = password
181 user.password_confirmation = password
182 user.save
182 user.save
183 end
183 end
184 @changed = true
184 @changed = true
185 end
185 end
186 end
186 end
187
187
188 # contest management
188 # contest management
189
189
190 def contests
190 def contests
191 @contest, @users = find_contest_and_user_from_contest_id(params[:id])
191 @contest, @users = find_contest_and_user_from_contest_id(params[:id])
192 @contests = Contest.enabled
192 @contests = Contest.enabled
193 end
193 end
194
194
195 def assign_from_list
195 def assign_from_list
196 contest_id = params[:users_contest_id]
196 contest_id = params[:users_contest_id]
197 org_contest, users = find_contest_and_user_from_contest_id(contest_id)
197 org_contest, users = find_contest_and_user_from_contest_id(contest_id)
198 contest = Contest.find(params[:new_contest][:id])
198 contest = Contest.find(params[:new_contest][:id])
199 if !contest
199 if !contest
200 flash[:notice] = 'Error: no contest'
200 flash[:notice] = 'Error: no contest'
201 redirect_to :action => 'contests', :id =>contest_id
201 redirect_to :action => 'contests', :id =>contest_id
202 end
202 end
203
203
204 note = []
204 note = []
205 users.each do |u|
205 users.each do |u|
206 u.contests = [contest]
206 u.contests = [contest]
207 note << u.login
207 note << u.login
208 end
208 end
209 flash[:notice] = 'User(s) ' + note.join(', ') +
209 flash[:notice] = 'User(s) ' + note.join(', ') +
210 " were successfully reassigned to #{contest.title}."
210 " were successfully reassigned to #{contest.title}."
211 redirect_to :action => 'contests', :id =>contest.id
211 redirect_to :action => 'contests', :id =>contest.id
212 end
212 end
213
213
214 def add_to_contest
214 def add_to_contest
215 user = User.find(params[:id])
215 user = User.find(params[:id])
216 contest = Contest.find(params[:contest_id])
216 contest = Contest.find(params[:contest_id])
217 if user and contest
217 if user and contest
218 user.contests << contest
218 user.contests << contest
219 end
219 end
220 redirect_to :action => 'list'
220 redirect_to :action => 'list'
221 end
221 end
222
222
223 def remove_from_contest
223 def remove_from_contest
224 user = User.find(params[:id])
224 user = User.find(params[:id])
225 contest = Contest.find(params[:contest_id])
225 contest = Contest.find(params[:contest_id])
226 if user and contest
226 if user and contest
227 user.contests.delete(contest)
227 user.contests.delete(contest)
228 end
228 end
229 redirect_to :action => 'list'
229 redirect_to :action => 'list'
230 end
230 end
231
231
232 def contest_management
232 def contest_management
233 end
233 end
234
234
235 def manage_contest
235 def manage_contest
236 contest = Contest.find(params[:contest][:id])
236 contest = Contest.find(params[:contest][:id])
237 if !contest
237 if !contest
238 flash[:notice] = 'You did not choose the contest.'
238 flash[:notice] = 'You did not choose the contest.'
239 redirect_to :action => 'contest_management' and return
239 redirect_to :action => 'contest_management' and return
240 end
240 end
241
241
242 operation = params[:operation]
242 operation = params[:operation]
243
243
244 if not ['add','remove','assign'].include? operation
244 if not ['add','remove','assign'].include? operation
245 flash[:notice] = 'You did not choose the operation to perform.'
245 flash[:notice] = 'You did not choose the operation to perform.'
246 redirect_to :action => 'contest_management' and return
246 redirect_to :action => 'contest_management' and return
247 end
247 end
248
248
249 lines = params[:login_list]
249 lines = params[:login_list]
250 if !lines or lines.blank?
250 if !lines or lines.blank?
251 flash[:notice] = 'You entered an empty list.'
251 flash[:notice] = 'You entered an empty list.'
252 redirect_to :action => 'contest_management' and return
252 redirect_to :action => 'contest_management' and return
253 end
253 end
254
254
255 note = []
255 note = []
256 users = []
256 users = []
257 lines.split("\n").each do |line|
257 lines.split("\n").each do |line|
258 user = User.find_by_login(line.chomp)
258 user = User.find_by_login(line.chomp)
259 if user
259 if user
260 if operation=='add'
260 if operation=='add'
261 if ! user.contests.include? contest
261 if ! user.contests.include? contest
262 user.contests << contest
262 user.contests << contest
263 end
263 end
264 elsif operation=='remove'
264 elsif operation=='remove'
265 user.contests.delete(contest)
265 user.contests.delete(contest)
266 else
266 else
267 user.contests = [contest]
267 user.contests = [contest]
268 end
268 end
269
269
270 if params[:reset_timer]
270 if params[:reset_timer]
271 user.contest_stat.forced_logout = true
271 user.contest_stat.forced_logout = true
272 user.contest_stat.reset_timer_and_save
272 user.contest_stat.reset_timer_and_save
273 end
273 end
274
274
275 if params[:notification_emails]
275 if params[:notification_emails]
276 send_contest_update_notification_email(user, contest)
276 send_contest_update_notification_email(user, contest)
277 end
277 end
278
278
279 note << user.login
279 note << user.login
280 users << user
280 users << user
281 end
281 end
282 end
282 end
283
283
284 if params[:reset_timer]
284 if params[:reset_timer]
285 logout_users(users)
285 logout_users(users)
286 end
286 end
287
287
288 flash[:notice] = 'User(s) ' + note.join(', ') +
288 flash[:notice] = 'User(s) ' + note.join(', ') +
289 ' were successfully modified. '
289 ' were successfully modified. '
290 redirect_to :action => 'contest_management'
290 redirect_to :action => 'contest_management'
291 end
291 end
292
292
293 # admin management
293 # admin management
294
294
295 def admin
295 def admin
296 @admins = User.find(:all).find_all {|user| user.admin? }
296 @admins = User.find(:all).find_all {|user| user.admin? }
297 end
297 end
298
298
299 def grant_admin
299 def grant_admin
300 login = params[:login]
300 login = params[:login]
301 user = User.find_by_login(login)
301 user = User.find_by_login(login)
302 if user!=nil
302 if user!=nil
303 admin_role = Role.find_by_name('admin')
303 admin_role = Role.find_by_name('admin')
304 user.roles << admin_role
304 user.roles << admin_role
305 else
305 else
306 flash[:notice] = 'Unknown user'
306 flash[:notice] = 'Unknown user'
307 end
307 end
308 flash[:notice] = 'User added as admins'
308 flash[:notice] = 'User added as admins'
309 redirect_to :action => 'admin'
309 redirect_to :action => 'admin'
310 end
310 end
311
311
312 def revoke_admin
312 def revoke_admin
313 user = User.find(params[:id])
313 user = User.find(params[:id])
314 if user==nil
314 if user==nil
315 flash[:notice] = 'Unknown user'
315 flash[:notice] = 'Unknown user'
316 redirect_to :action => 'admin' and return
316 redirect_to :action => 'admin' and return
317 elsif user.login == 'root'
317 elsif user.login == 'root'
318 flash[:notice] = 'You cannot revoke admisnistrator permission from root.'
318 flash[:notice] = 'You cannot revoke admisnistrator permission from root.'
319 redirect_to :action => 'admin' and return
319 redirect_to :action => 'admin' and return
320 end
320 end
321
321
322 admin_role = Role.find_by_name('admin')
322 admin_role = Role.find_by_name('admin')
323 user.roles.delete(admin_role)
323 user.roles.delete(admin_role)
324 flash[:notice] = 'User permission revoked'
324 flash[:notice] = 'User permission revoked'
325 redirect_to :action => 'admin'
325 redirect_to :action => 'admin'
326 end
326 end
327
327
328 # mass mailing
328 # mass mailing
329
329
330 def mass_mailing
330 def mass_mailing
331 end
331 end
332
332
333 def bulk_mail
333 def bulk_mail
334 lines = params[:login_list]
334 lines = params[:login_list]
335 if !lines or lines.blank?
335 if !lines or lines.blank?
336 flash[:notice] = 'You entered an empty list.'
336 flash[:notice] = 'You entered an empty list.'
337 redirect_to :action => 'mass_mailing' and return
337 redirect_to :action => 'mass_mailing' and return
338 end
338 end
339
339
340 mail_subject = params[:subject]
340 mail_subject = params[:subject]
341 if !mail_subject or mail_subject.blank?
341 if !mail_subject or mail_subject.blank?
342 flash[:notice] = 'You entered an empty mail subject.'
342 flash[:notice] = 'You entered an empty mail subject.'
343 redirect_to :action => 'mass_mailing' and return
343 redirect_to :action => 'mass_mailing' and return
344 end
344 end
345
345
346 mail_body = params[:email_body]
346 mail_body = params[:email_body]
347 if !mail_body or mail_body.blank?
347 if !mail_body or mail_body.blank?
348 flash[:notice] = 'You entered an empty mail body.'
348 flash[:notice] = 'You entered an empty mail body.'
349 redirect_to :action => 'mass_mailing' and return
349 redirect_to :action => 'mass_mailing' and return
350 end
350 end
351
351
352 note = []
352 note = []
353 users = []
353 users = []
354 lines.split("\n").each do |line|
354 lines.split("\n").each do |line|
355 user = User.find_by_login(line.chomp)
355 user = User.find_by_login(line.chomp)
356 if user
356 if user
357 send_mail(user.email, mail_subject, mail_body)
357 send_mail(user.email, mail_subject, mail_body)
358 note << user.login
358 note << user.login
359 end
359 end
360 end
360 end
361
361
362 flash[:notice] = 'User(s) ' + note.join(', ') +
362 flash[:notice] = 'User(s) ' + note.join(', ') +
363 ' were successfully modified. '
363 ' were successfully modified. '
364 redirect_to :action => 'mass_mailing'
364 redirect_to :action => 'mass_mailing'
365 end
365 end
366
366
367 protected
367 protected
368
368
369 def random_password(length=5)
369 def random_password(length=5)
370 chars = 'abcdefghijkmnopqrstuvwxyz23456789'
370 chars = 'abcdefghijkmnopqrstuvwxyz23456789'
371 newpass = ""
371 newpass = ""
372 length.times { newpass << chars[rand(chars.size-1)] }
372 length.times { newpass << chars[rand(chars.size-1)] }
373 return newpass
373 return newpass
374 end
374 end
375
375
376 def import_from_file(f)
376 def import_from_file(f)
377 data_hash = YAML.load(f)
377 data_hash = YAML.load(f)
378 @import_log = ""
378 @import_log = ""
379
379
380 country_data = data_hash[:countries]
380 country_data = data_hash[:countries]
381 site_data = data_hash[:sites]
381 site_data = data_hash[:sites]
382 user_data = data_hash[:users]
382 user_data = data_hash[:users]
383
383
384 # import country
384 # import country
385 countries = {}
385 countries = {}
386 country_data.each_pair do |id,country|
386 country_data.each_pair do |id,country|
387 c = Country.find_by_name(country[:name])
387 c = Country.find_by_name(country[:name])
388 if c!=nil
388 if c!=nil
389 countries[id] = c
389 countries[id] = c
390 @import_log << "Found #{country[:name]}\n"
390 @import_log << "Found #{country[:name]}\n"
391 else
391 else
392 countries[id] = Country.new(:name => country[:name])
392 countries[id] = Country.new(:name => country[:name])
393 countries[id].save
393 countries[id].save
394 @import_log << "Created #{country[:name]}\n"
394 @import_log << "Created #{country[:name]}\n"
395 end
395 end
396 end
396 end
397
397
398 # import sites
398 # import sites
399 sites = {}
399 sites = {}
400 site_data.each_pair do |id,site|
400 site_data.each_pair do |id,site|
401 s = Site.find_by_name(site[:name])
401 s = Site.find_by_name(site[:name])
402 if s!=nil
402 if s!=nil
403 @import_log << "Found #{site[:name]}\n"
403 @import_log << "Found #{site[:name]}\n"
404 else
404 else
405 s = Site.new(:name => site[:name])
405 s = Site.new(:name => site[:name])
406 @import_log << "Created #{site[:name]}\n"
406 @import_log << "Created #{site[:name]}\n"
407 end
407 end
408 s.password = site[:password]
408 s.password = site[:password]
409 s.country = countries[site[:country_id]]
409 s.country = countries[site[:country_id]]
410 s.save
410 s.save
411 sites[id] = s
411 sites[id] = s
412 end
412 end
413
413
414 # import users
414 # import users
415 user_data.each_pair do |id,user|
415 user_data.each_pair do |id,user|
416 u = User.find_by_login(user[:login])
416 u = User.find_by_login(user[:login])
417 if u!=nil
417 if u!=nil
418 @import_log << "Found #{user[:login]}\n"
418 @import_log << "Found #{user[:login]}\n"
419 else
419 else
420 u = User.new(:login => user[:login])
420 u = User.new(:login => user[:login])
421 @import_log << "Created #{user[:login]}\n"
421 @import_log << "Created #{user[:login]}\n"
422 end
422 end
423 u.full_name = user[:name]
423 u.full_name = user[:name]
424 u.password = user[:password]
424 u.password = user[:password]
425 u.country = countries[user[:country_id]]
425 u.country = countries[user[:country_id]]
426 u.site = sites[user[:site_id]]
426 u.site = sites[user[:site_id]]
427 u.activated = true
427 u.activated = true
428 u.email = "empty-#{u.login}@none.com"
428 u.email = "empty-#{u.login}@none.com"
429 if not u.save
429 if not u.save
430 @import_log << "Errors\n"
430 @import_log << "Errors\n"
431 u.errors.each { |attr,msg| @import_log << "#{attr} - #{msg}\n" }
431 u.errors.each { |attr,msg| @import_log << "#{attr} - #{msg}\n" }
432 end
432 end
433 end
433 end
434
434
435 end
435 end
436
436
437 def logout_users(users)
437 def logout_users(users)
438 users.each do |user|
438 users.each do |user|
439 contest_stat = user.contest_stat(true)
439 contest_stat = user.contest_stat(true)
440 if contest_stat and !contest_stat.forced_logout
440 if contest_stat and !contest_stat.forced_logout
441 contest_stat.forced_logout = true
441 contest_stat.forced_logout = true
442 contest_stat.save
442 contest_stat.save
443 end
443 end
444 end
444 end
445 end
445 end
446
446
447 def send_contest_update_notification_email(user, contest)
447 def send_contest_update_notification_email(user, contest)
448 contest_title_name = GraderConfiguration['contest.name']
448 contest_title_name = GraderConfiguration['contest.name']
449 contest_name = contest.name
449 contest_name = contest.name
450 mail_subject = t('contest.notification.email_subject', {
450 mail_subject = t('contest.notification.email_subject', {
451 :contest_title_name => contest_title_name,
451 :contest_title_name => contest_title_name,
452 :contest_name => contest_name })
452 :contest_name => contest_name })
453 mail_body = t('contest.notification.email_body', {
453 mail_body = t('contest.notification.email_body', {
454 :full_name => user.full_name,
454 :full_name => user.full_name,
455 :contest_title_name => contest_title_name,
455 :contest_title_name => contest_title_name,
456 :contest_name => contest.name,
456 :contest_name => contest.name,
457 })
457 })
458
458
459 logger.info mail_body
459 logger.info mail_body
460 send_mail(user.email, mail_subject, mail_body)
460 send_mail(user.email, mail_subject, mail_body)
461 end
461 end
462
462
463 def find_contest_and_user_from_contest_id(id)
463 def find_contest_and_user_from_contest_id(id)
464 if id!='none'
464 if id!='none'
465 @contest = Contest.find(id)
465 @contest = Contest.find(id)
466 else
466 else
467 @contest = nil
467 @contest = nil
468 end
468 end
469 if @contest
469 if @contest
470 @users = @contest.users
470 @users = @contest.users
471 else
471 else
472 @users = User.find_users_with_no_contest
472 @users = User.find_users_with_no_contest
473 end
473 end
474 return [@contest, @users]
474 return [@contest, @users]
475 end
475 end
476 end
476 end
@@ -1,48 +1,52
1 <h1>User grading results</h1>
1 <h1>User grading results</h1>
2 <h2>Show scores from latest submission</h2>
2 <h2>Show scores from latest submission</h2>
3
3
4 <%= render 'submission_range' %>
4 <%= render 'submission_range' %>
5
5
6 <p>Latest scores</p>
6 <p>Latest scores</p>
7
7
8 <table class="info">
8 <table class="info">
9 <tr class="info-head">
9 <tr class="info-head">
10 <th>User</th>
10 <th>User</th>
11 <th>Name</th>
11 <th>Name</th>
12 <th>Activated?</th>
12 <th>Activated?</th>
13 <th>Logged in</th>
13 <th>Logged in</th>
14 <th>Contest(s)</th>
14 <th>Contest(s)</th>
15 <% @problems.each do |p| %>
15 <% @problems.each do |p| %>
16 <th><%= p.name %></th>
16 <th><%= p.name %></th>
17 <% end %>
17 <% end %>
18 <th>Total</th>
18 <th>Total</th>
19 <th>Passed</th>
19 <th>Passed</th>
20 </tr>
20 </tr>
21 <% counter = 0 %>
21 <% counter = 0 %>
22 <% @scorearray.each do |sc| %>
22 <% @scorearray.each do |sc| %>
23 <tr class="<%= (counter %2 ==0) ? "info-even" : "info-odd" %>">
23 <tr class="<%= (counter %2 ==0) ? "info-even" : "info-odd" %>">
24 <% total = 0 %>
24 <% total = 0 %>
25 <% num_passed = 0 %>
25 <% num_passed = 0 %>
26 <% sc.each_index do |i| %>
26 <% sc.each_index do |i| %>
27 <% if i==0 %>
27 <% if i==0 %>
28 <td><%= sc[i].login %></td>
28 <td><%= sc[i].login %></td>
29 <td><%= sc[i].full_name %></td>
29 <td><%= sc[i].full_name %></td>
30 <td><%= sc[i].activated %></td>
30 <td><%= sc[i].activated %></td>
31 <td>
31 <td>
32 <%= sc[i].try(:contest_stat).try(:started_at)!=nil ? 'yes' : 'no' %>
32 <%= sc[i].try(:contest_stat).try(:started_at)!=nil ? 'yes' : 'no' %>
33 </td>
33 </td>
34 <td>
34 <td>
35 <%= sc[i].contests.collect {|c| c.name}.join(', ') %>
35 <%= sc[i].contests.collect {|c| c.name}.join(', ') %>
36 </td>
36 </td>
37 - <% else %>
37 + <% else %>
38 - <td><%= sc[i][0] %></td>
38 + <% if sc[i][0] != nil %>
39 - <% total += sc[i][0] %>
39 + <td><%= sc[i][0] %></td>
40 - <% num_passed += 1 if sc[i][1] %>
40 + <% total += sc[i][0] %>
41 + <% num_passed += 1 if sc[i][1] %>
42 + <% else %>
43 + <td>-</td>
44 + <% end %>
41 <% end %>
45 <% end %>
42 <% end %>
46 <% end %>
43 <td><%= total %></td>
47 <td><%= total %></td>
44 <td><%= num_passed %></td>
48 <td><%= num_passed %></td>
45 </tr>
49 </tr>
46 <% counter += 1 %>
50 <% counter += 1 %>
47 <% end %>
51 <% end %>
48 </table>
52 </table>
You need to be logged in to leave comments. Login now