Description:
- fix syntax error
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r599:14a14eb28fed - - 1 file changed: 1 inserted, 0 deleted
@@ -287,198 +287,199 | |||
|
287 | 287 | solve = true |
|
288 | 288 | else |
|
289 | 289 | tries += 1 |
|
290 | 290 | end |
|
291 | 291 | end |
|
292 | 292 | @struggle.sort!{|a,b| b[:tries] <=> a[:tries] } |
|
293 | 293 | @struggle = @struggle[0..50] |
|
294 | 294 | end |
|
295 | 295 | |
|
296 | 296 | |
|
297 | 297 | def multiple_login |
|
298 | 298 | #user with multiple IP |
|
299 | 299 | raw = Submission.joins(:user).joins(:problem).where("problems.available != 0").group("login,ip_address").order(:login) |
|
300 | 300 | last,count = 0,0 |
|
301 | 301 | first = 0 |
|
302 | 302 | @users = [] |
|
303 | 303 | raw.each do |r| |
|
304 | 304 | if last != r.user.login |
|
305 | 305 | count = 1 |
|
306 | 306 | last = r.user.login |
|
307 | 307 | first = r |
|
308 | 308 | else |
|
309 | 309 | @users << first if count == 1 |
|
310 | 310 | @users << r |
|
311 | 311 | count += 1 |
|
312 | 312 | end |
|
313 | 313 | end |
|
314 | 314 | |
|
315 | 315 | #IP with multiple user |
|
316 | 316 | raw = Submission.joins(:user).joins(:problem).where("problems.available != 0").group("login,ip_address").order(:ip_address) |
|
317 | 317 | last,count = 0,0 |
|
318 | 318 | first = 0 |
|
319 | 319 | @ip = [] |
|
320 | 320 | raw.each do |r| |
|
321 | 321 | if last != r.ip_address |
|
322 | 322 | count = 1 |
|
323 | 323 | last = r.ip_address |
|
324 | 324 | first = r |
|
325 | 325 | else |
|
326 | 326 | @ip << first if count == 1 |
|
327 | 327 | @ip << r |
|
328 | 328 | count += 1 |
|
329 | 329 | end |
|
330 | 330 | end |
|
331 | 331 | end |
|
332 | 332 | |
|
333 | 333 | def cheat_report |
|
334 | 334 | date_and_time = '%Y-%m-%d %H:%M' |
|
335 | 335 | begin |
|
336 | 336 | md = params[:since_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/) |
|
337 | 337 | @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) |
|
338 | 338 | rescue |
|
339 | 339 | @since_time = Time.zone.now.ago( 90.minutes) |
|
340 | 340 | end |
|
341 | 341 | begin |
|
342 | 342 | md = params[:until_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/) |
|
343 | 343 | @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) |
|
344 | 344 | rescue |
|
345 | 345 | @until_time = Time.zone.now |
|
346 | 346 | end |
|
347 | 347 | |
|
348 | 348 | #multi login |
|
349 | 349 | @ml = Login.joins(:user).where("logins.created_at >= ? and logins.created_at <= ?",@since_time,@until_time).select('users.login,count(distinct ip_address) as count,users.full_name').group("users.id").having("count > 1") |
|
350 | 350 | |
|
351 | 351 | st = <<-SQL |
|
352 | 352 | SELECT l2.* |
|
353 | 353 | FROM logins l2 INNER JOIN |
|
354 | 354 | (SELECT u.id,COUNT(DISTINCT ip_address) as count,u.login,u.full_name |
|
355 | 355 | FROM logins l |
|
356 | 356 | INNER JOIN users u ON l.user_id = u.id |
|
357 | 357 | WHERE l.created_at >= '#{@since_time.in_time_zone("UTC")}' and l.created_at <= '#{@until_time.in_time_zone("UTC")}' |
|
358 | 358 | GROUP BY u.id |
|
359 | 359 | HAVING count > 1 |
|
360 | 360 | ) ml ON l2.user_id = ml.id |
|
361 | 361 | WHERE l2.created_at >= '#{@since_time.in_time_zone("UTC")}' and l2.created_at <= '#{@until_time.in_time_zone("UTC")}' |
|
362 | 362 | UNION |
|
363 | 363 | SELECT l2.* |
|
364 | 364 | FROM logins l2 INNER JOIN |
|
365 | 365 | (SELECT l.ip_address,COUNT(DISTINCT u.id) as count |
|
366 | 366 | FROM logins l |
|
367 | 367 | INNER JOIN users u ON l.user_id = u.id |
|
368 | 368 | WHERE l.created_at >= '#{@since_time.in_time_zone("UTC")}' and l.created_at <= '#{@until_time.in_time_zone("UTC")}' |
|
369 | 369 | GROUP BY l.ip_address |
|
370 | 370 | HAVING count > 1 |
|
371 | 371 | ) ml on ml.ip_address = l2.ip_address |
|
372 | 372 | INNER JOIN users u ON l2.user_id = u.id |
|
373 | 373 | WHERE l2.created_at >= '#{@since_time.in_time_zone("UTC")}' and l2.created_at <= '#{@until_time.in_time_zone("UTC")}' |
|
374 | 374 | ORDER BY ip_address,created_at |
|
375 | 375 | SQL |
|
376 | 376 | @mld = Login.find_by_sql(st) |
|
377 | 377 | |
|
378 | 378 | st = <<-SQL |
|
379 | 379 | SELECT s.id,s.user_id,s.ip_address,s.submitted_at,s.problem_id |
|
380 | 380 | FROM submissions s INNER JOIN |
|
381 | 381 | (SELECT u.id,COUNT(DISTINCT ip_address) as count,u.login,u.full_name |
|
382 | 382 | FROM logins l |
|
383 | 383 | INNER JOIN users u ON l.user_id = u.id |
|
384 | 384 | WHERE l.created_at >= ? and l.created_at <= ? |
|
385 | 385 | GROUP BY u.id |
|
386 | 386 | HAVING count > 1 |
|
387 | 387 | ) ml ON s.user_id = ml.id |
|
388 | 388 | WHERE s.submitted_at >= ? and s.submitted_at <= ? |
|
389 | 389 | UNION |
|
390 | 390 | SELECT s.id,s.user_id,s.ip_address,s.submitted_at,s.problem_id |
|
391 | 391 | FROM submissions s INNER JOIN |
|
392 | 392 | (SELECT l.ip_address,COUNT(DISTINCT u.id) as count |
|
393 | 393 | FROM logins l |
|
394 | 394 | INNER JOIN users u ON l.user_id = u.id |
|
395 | 395 | WHERE l.created_at >= ? and l.created_at <= ? |
|
396 | 396 | GROUP BY l.ip_address |
|
397 | 397 | HAVING count > 1 |
|
398 | 398 | ) ml on ml.ip_address = s.ip_address |
|
399 | 399 | WHERE s.submitted_at >= ? and s.submitted_at <= ? |
|
400 | 400 | ORDER BY ip_address,submitted_at |
|
401 | 401 | SQL |
|
402 | 402 | @subs = Submission.joins(:problem).find_by_sql([st,@since_time,@until_time, |
|
403 | 403 | @since_time,@until_time, |
|
404 | 404 | @since_time,@until_time, |
|
405 | 405 | @since_time,@until_time]) |
|
406 | 406 | |
|
407 | 407 | end |
|
408 | 408 | |
|
409 | 409 | def cheat_scruntinize |
|
410 | 410 | #convert date & time |
|
411 | 411 | date_and_time = '%Y-%m-%d %H:%M' |
|
412 | 412 | begin |
|
413 | 413 | md = params[:since_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/) |
|
414 | 414 | @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) |
|
415 | 415 | rescue |
|
416 | 416 | @since_time = Time.zone.now.ago( 90.minutes) |
|
417 | 417 | end |
|
418 | 418 | begin |
|
419 | 419 | md = params[:until_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/) |
|
420 | 420 | @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) |
|
421 | 421 | rescue |
|
422 | 422 | @until_time = Time.zone.now |
|
423 | 423 | end |
|
424 | 424 | |
|
425 | 425 | #convert sid |
|
426 | 426 | @sid = params[:SID].split(/[,\s]/) if params[:SID] |
|
427 | 427 | unless @sid and @sid.size > 0 |
|
428 | 428 | return |
|
429 | 429 | redirect_to actoin: :cheat_scruntinize |
|
430 | 430 | flash[:notice] = 'Please enter at least 1 student id' |
|
431 | 431 | end |
|
432 | 432 | mark = Array.new(@sid.size,'?') |
|
433 | 433 | condition = "(u.login = " + mark.join(' OR u.login = ') + ')' |
|
434 | 434 | |
|
435 | 435 | @st = <<-SQL |
|
436 | 436 | SELECT l.created_at as submitted_at ,-1 as id,u.login,u.full_name,l.ip_address,"" as problem_id,"" as points,l.user_id |
|
437 | 437 | FROM logins l INNER JOIN users u on l.user_id = u.id |
|
438 | 438 | WHERE l.created_at >= ? AND l.created_at <= ? AND #{condition} |
|
439 | 439 | UNION |
|
440 | 440 | SELECT s.submitted_at,s.id,u.login,u.full_name,s.ip_address,s.problem_id,s.points,s.user_id |
|
441 | 441 | FROM submissions s INNER JOIN users u ON s.user_id = u.id |
|
442 | 442 | WHERE s.submitted_at >= ? AND s.submitted_at <= ? AND #{condition} |
|
443 | 443 | ORDER BY submitted_at |
|
444 | 444 | SQL |
|
445 | 445 | |
|
446 | 446 | p = [@st,@since_time,@until_time] + @sid + [@since_time,@until_time] + @sid |
|
447 | 447 | @logs = Submission.joins(:problem).find_by_sql(p) |
|
448 | 448 | |
|
449 | 449 | |
|
450 | 450 | |
|
451 | 451 | |
|
452 | 452 | |
|
453 | 453 | end |
|
454 | 454 | |
|
455 | 455 | protected |
|
456 | 456 | |
|
457 | 457 | def calculate_max_score(problems, users,since_id,until_id, get_last_score = false) |
|
458 | 458 | scorearray = Array.new |
|
459 | 459 | users.each do |u| |
|
460 | 460 | ustat = Array.new |
|
461 | 461 | ustat[0] = u |
|
462 | 462 | problems.each do |p| |
|
463 | 463 | unless get_last_score |
|
464 | 464 | #get max score |
|
465 | 465 | max_points = 0 |
|
466 | 466 | Submission.find_in_range_by_user_and_problem(u.id,p.id,since_id,until_id).each do |sub| |
|
467 | 467 | max_points = sub.points if sub and sub.points and (sub.points > max_points) |
|
468 | 468 | end |
|
469 | 469 | ustat << [(max_points.to_f*100/p.full_score).round, (max_points>=p.full_score)] |
|
470 | 470 | else |
|
471 | 471 | #get latest score |
|
472 | 472 | sub = Submission.find_last_by_user_and_problem(u.id,p.id) |
|
473 | 473 | if (sub!=nil) and (sub.points!=nil) and p and p.full_score |
|
474 | 474 | ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)] |
|
475 | 475 | else |
|
476 | 476 | ustat << [0,false] |
|
477 | 477 | end |
|
478 | 478 | end |
|
479 | + end | |
|
479 | 480 | scorearray << ustat |
|
480 | 481 | end |
|
481 | 482 | return scorearray |
|
482 | 483 | end |
|
483 | 484 | |
|
484 | 485 | end |
You need to be logged in to leave comments.
Login now