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 @@ -12,23 +12,31 @@ admin_authorization } - def show_max_score + def max_score end - def get_max_score - #process list of problems + def show_max_score + #process parameters + #problems + @problems = [] + params[:problem_id].each do |id| + next unless id.strip != "" + @problems << Problem.find(id.to_i) + end - #process submission range - if params[:commit] == 'download csv' - @problems = Problem.all - else - @problems = Problem.find_available_problems - end - @users = User.find(:all, :include => [:contests, :contest_stat]) + #users + @users = if params[:user] == "all" then + User.find(:all, :include => [:contests, :contest_stat]) + else + User.includes(:contests).includes(:contest_stat).where(enabled: true) + end + + #set up range from param + since_id = params.fetch(:min_id, 0).to_i + until_id = params.fetch(:max_id, 0).to_i + + #get data @scorearray = Array.new - #set up range from param - since_id = params.fetch(:since_id, 0).to_i - until_id = params.fetch(:until_id, 0).to_i @users.each do |u| ustat = Array.new ustat[0] = u @@ -46,7 +54,8 @@ csv = gen_csv_from_scorearray(@scorearray,@problems) send_data csv, filename: 'max_score.csv' else - render template: 'user_admin/user_stat' + #render template: 'user_admin/user_stat' + render 'max_score' end end 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 @@ -1,24 +1,30 @@ %h1 Maximum score -= form_tag report_max_score_path += form_tag report_show_max_score_path .row .col-md-4 .panel.panel-primary .panel-heading Problems .panel-body - = label_tag :problems, "Problems" - = select 'problems', 'problem_id', [[(t 'main.specified_in_header'),'-1']] + Problem.all.collect {|p| ["[#{p.name}] #{p.full_name}", p.id]}, {:selected => '-1'}, { class: 'select2 form-control' } + %p + Select problem(s) that we wish to know the score. + = label_tag :problem_id, "Problems" + = select_tag 'problem_id[]', + options_for_select(Problem.all.collect {|p| ["[#{p.name}] #{p.full_name}", p.id]}), + { class: 'select2 form-control', multiple: "true" } .col-md-4 .panel.panel-primary .panel-heading Submission range .panel-body + %p + Input minimum and maximum range of submission ID that should be included. A blank value for min and max means -1 and infinity, respectively. .form-group - = label_tag :from, "From" + = label_tag :from, "Min" = text_field_tag 'from_id', nil, class: "form-control" .form-group - = label_tag :from, "To" + = label_tag :from, "Max" = text_field_tag 'to_id', nil, class: "form-control" .col-md-4 .panel.panel-primary @@ -37,6 +43,42 @@ .col-md-12 = button_tag 'Show', class: "btn btn-primary btn-large" = button_tag 'Download CSV', class: "btn btn-primary btn-large" + +- 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 diff --git a/app/views/report/show_max_score.html.haml b/app/views/report/show_max_score.html.haml new file mode 100644 diff --git a/config/routes.rb b/config/routes.rb --- a/config/routes.rb +++ b/config/routes.rb @@ -52,6 +52,7 @@ 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' + post 'report/show_max_score', to: 'report#show_max_score', as: 'report_show_max_score' #grader get 'graders/list', to: 'graders#list', as: 'grader_list'