# HG changeset patch # User Nattee Niparnan # Date 2016-10-05 08:26:00 # Node ID db36298d10ca5bbc61bdf1a36fecace0186bca66 # Parent 03908adb0b2415dca1dd028461703008e0caafe9 - remove inplace editor from view - add link to edit announcement directly - modify submission_short display button 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 @@ -15,6 +15,21 @@ def max_score end + 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}) + + #rencer accordingly + if params[:commit] == 'download csv' then + csv = gen_csv_from_scorearray(@scorearray,@problems) + send_data csv, filename: 'max_score.csv' + else + #render template: 'user_admin/user_stat' + render 'current_score' + end + end + def show_max_score #process parameters #problems @@ -35,21 +50,10 @@ since_id = params.fetch(:min_id, 0).to_i until_id = params.fetch(:max_id, 0).to_i - #get data - @scorearray = Array.new - @users.each do |u| - ustat = Array.new - ustat[0] = u - @problems.each do |p| - max_points = 0 - Submission.find_in_range_by_user_and_problem(u.id,p.id,since_id,until_id).each do |sub| - max_points = sub.points if sub and sub.points and (sub.points > max_points) - end - ustat << [(max_points.to_f*100/p.full_score).round, (max_points>=p.full_score)] - end - @scorearray << ustat - end + #calculate the routine + @scorearray = calculate_max_score(problems, users,since_id,until_id) + #rencer accordingly if params[:commit] == 'download csv' then csv = gen_csv_from_scorearray(@scorearray,@problems) send_data csv, filename: 'max_score.csv' @@ -448,5 +452,33 @@ end + protected + + def calculate_max_score(problems, users,since_id,until_id, get_last_score = false) + scorearray = Array.new + users.each do |u| + ustat = Array.new + ustat[0] = u + problems.each do |p| + unless get_last_score + #get max score + max_points = 0 + Submission.find_in_range_by_user_and_problem(u.id,p.id,since_id,until_id).each do |sub| + max_points = sub.points if sub and sub.points and (sub.points > max_points) + end + ustat << [(max_points.to_f*100/p.full_score).round, (max_points>=p.full_score)] + else + #get latest score + sub = Submission.find_last_by_user_and_problem(u.id,p.id) + if (sub!=nil) and (sub.points!=nil) and p and p.full_score + ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)] + else + ustat << [0,false] + end + end + scorearray << ustat + end + return scorearray + end end diff --git a/app/views/main/_announcement.html.haml b/app/views/main/_announcement.html.haml --- a/app/views/main/_announcement.html.haml +++ b/app/views/main/_announcement.html.haml @@ -1,6 +1,8 @@ %li.list-group-item %strong = announcement.title + - if @current_user.admin? + = link_to 'Edit', edit_announcement_path(announcement), class: 'btn btn-xs btn-default' %small= "(updated #{time_ago_in_words(announcement.updated_at)} ago on #{announcement.updated_at})" %br diff --git a/app/views/main/_submission_short.html.haml b/app/views/main/_submission_short.html.haml --- a/app/views/main/_submission_short.html.haml +++ b/app/views/main/_submission_short.html.haml @@ -20,8 +20,7 @@ %strong View: - if GraderConfiguration.show_grading_result = link_to '[detailed result]', :action => 'result', :id => submission.id - = link_to("[#{t 'main.cmp_msg'}]", {:action => 'compiler_msg', :id => submission.id}, {:popup => true}) - = " | " - = link_to("[#{t 'main.src_link'}]",{:action => 'source', :id => submission.id}) - = " | " - = link_to "[#{t 'main.submissions_link'}]", problem_submissions_path(problem_id) + = link_to "#{t 'main.cmp_msg'}", {:action => 'compiler_msg', :id => submission.id}, {popup: true,class: 'btn btn-xs btn-info'} + = link_to "#{t 'main.src_link'}",{:action => 'source', :id => submission.id}, class: 'btn btn-xs btn-info' + = link_to "#{t 'main.submissions_link'}", problem_submissions_path(problem_id), class: 'btn btn-xs btn-info' + diff --git a/app/views/problems/index.html.haml b/app/views/problems/index.html.haml --- a/app/views/problems/index.html.haml +++ b/app/views/problems/index.html.haml @@ -33,9 +33,9 @@ - for problem in @problems %tr{:class => "#{(problem.available) ? "success" : "danger"}", :id => "prob-#{problem.id}", :name => "prob-#{problem.id}"} - @problem=problem - %td= in_place_editor_field :problem, :name, {}, :rows=>1 - %td= in_place_editor_field :problem, :full_name, {}, :rows=>1 - %td.text-right= in_place_editor_field :problem, :full_score, {}, :rows=>1 + %td= problem.name #in_place_editor_field :problem, :name, {}, :rows=>1 + %td= problem.full_name #in_place_editor_field :problem, :full_name, {}, :rows=>1 + %td.text-right= problem.full_score #in_place_editor_field :problem, :full_score, {}, :rows=>1 %td= problem.date_added %td= toggle_button(@problem.available?, toggle_problem_url(@problem), "problem-avail-#{@problem.id}") %td= toggle_button(@problem.test_allowed?, toggle_test_problem_url(@problem), "problem-test-#{@problem.id}")