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