diff --git a/app/controllers/report_controller.rb b/app/controllers/report_controller.rb --- a/app/controllers/report_controller.rb +++ b/app/controllers/report_controller.rb @@ -1,5 +1,7 @@ class ReportController < ApplicationController + before_filter :authenticate + before_filter :admin_authorization, only: [:login_stat,:submission_stat, :stuck, :cheat_report, :cheat_scruntinize, :show_max_score] before_filter(only: [:problem_hof]) { |c| @@ -18,7 +20,7 @@ def current_score @problems = Problem.find_available_problems @users = User.includes(:contests).includes(:contest_stat).where(enabled: true) - @scorearray = calculate_max_score(problems, users,0,0,{max: true}) + @scorearray = calculate_max_score(@problems, @users,0,0,true) #rencer accordingly if params[:commit] == 'download csv' then @@ -36,7 +38,8 @@ @problems = [] params[:problem_id].each do |id| next unless id.strip != "" - @problems << Problem.find(id.to_i) + pid = Problem.find_by_id(id.to_i) + @problems << pid if pid end #users @@ -51,7 +54,7 @@ until_id = params.fetch(:max_id, 0).to_i #calculate the routine - @scorearray = calculate_max_score(problems, users,since_id,until_id) + @scorearray = calculate_max_score(@problems, @users,since_id,until_id) #rencer accordingly if params[:commit] == 'download csv' then diff --git a/app/views/layouts/_header.html.haml b/app/views/layouts/_header.html.haml --- a/app/views/layouts/_header.html.haml +++ b/app/views/layouts/_header.html.haml @@ -52,7 +52,7 @@ Report %span.caret %ul.dropdown-menu - = add_menu( 'Results', 'user_admin', 'user_stat') + = add_menu( 'Results', 'report', 'current_score') = add_menu( 'Report', 'report', 'multiple_login') - if (ungraded = Submission.where('graded_at is null').where('submitted_at < ?', 1.minutes.ago).count) > 0 =link_to "#{ungraded} backlogs!", diff --git a/app/views/report/_score_table.html.haml b/app/views/report/_score_table.html.haml new file mode 100644 --- /dev/null +++ b/app/views/report/_score_table.html.haml @@ -0,0 +1,34 @@ +%table.table.sortable.table-striped.table-bordered.table-condensed + %thead + %tr + %th Login + %th Name + %th Activated? + %th Logged_in + %th Contest(s) + %th Remark + - @problems.each do |p| + %th.text-right= p.name + %th.text-right Total + %th.text-right Passed + %tbody + - @scorearray.each do |sc| + %tr + - total,num_passed = 0,0 + - sc.each_index do |i| + - if i == 0 + %td= link_to sc[i].login, controller: 'users', action: 'profile', id: sc[i] + %td= sc[i].full_name + %td= sc[i].activated + %td= sc[i].try(:contest_stat).try(:started_at) ? 'yes' : 'no' + %td= sc[i].contests.collect {|c| c.name}.join(', ') + %td= sc[i].remark + - else + %td.text-right= sc[i][0] + - total += sc[i][0] + - num_passed += 1 if sc[i][1] + %td.text-right= total + %td.text-right= num_passed + +:javascript + $.bootstrapSortable(true,'reversed') diff --git a/app/views/report/current_score.html.haml b/app/views/report/current_score.html.haml new file mode 100644 --- /dev/null +++ b/app/views/report/current_score.html.haml @@ -0,0 +1,3 @@ +%h1 Current Score + += render "score_table" diff --git a/app/views/report/max_score.html.haml b/app/views/report/max_score.html.haml --- a/app/views/report/max_score.html.haml +++ b/app/views/report/max_score.html.haml @@ -46,40 +46,4 @@ - if @scorearray %h2 Result - %table.table.sortable.table-striped.table-bordered.table-condensed - %thead - %tr - %th Login - %th Name - %th Activated? - %th Logged_in - %th Contest(s) - %th Remark - - @problems.each do |p| - %th.text-right= p.name - %th.text-right Total - %th.text-right Passed - %tbody - - @scorearray.each do |sc| - %tr - - total,num_passed = 0,0 - - sc.each_index do |i| - - if i == 0 - %td= link_to sc[i].login, controller: 'users', action: 'profile', id: sc[i] - %td= sc[i].full_name - %td= sc[i].activated - %td= sc[i].try(:contest_stat).try(:started_at) ? 'yes' : 'no' - %td= sc[i].contests.collect {|c| c.name}.join(', ') - %td= sc[i].remark - - else - %td.text-right= sc[i][0] - - total += sc[i][0] - - num_passed += 1 if sc[i][1] - %td.text-right= total - %td.text-right= num_passed - :javascript - $.bootstrapSortable(true,'reversed') - /.col-md-4.col-md-offset-1 - / = button_tag 'Show', class: "btn btn-primary btn-block" - /.col-md-4.col-md-offset-2 - / = button_tag 'Download CSV', class: "btn btn-primary btn-block" + =render "score_table" diff --git a/config/routes.rb b/config/routes.rb --- a/config/routes.rb +++ b/config/routes.rb @@ -51,6 +51,7 @@ get 'main/submission(/:id)', to: 'main#submission', as: 'main_submission' #report + get 'report/current_score', to: 'report#current_score', as: 'report_current_score' get 'report/problem_hof(/:id)', to: 'report#problem_hof', as: 'report_problem_hof' get "report/login" get 'report/max_score', to: 'report#max_score', as: 'report_max_score'