# HG changeset patch # User Nattee Niparnan # Date 2014-09-30 03:50:26 # Node ID ef96a7a29f255a65121d0ecc99597c3528f5fd59 # Parent c960ef68f0b14cf4f73045ee032a1b97d9ba929a add struggle report 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 @@ -188,4 +188,29 @@ user.each_value { |v| @summary[:solve] += 1 if v == 1 } end + def stuck #report struggling user,problem + # init + user,problem = nil + solve = true + tries = 0 + @struggle = Array.new + record = {} + Submission.includes(:problem,:user).order(:problem_id,:user_id).find_each do |sub| + if user != sub.user_id or problem != sub.problem_id + @struggle << { user: record[:user], problem: record[:problem], tries: tries } unless solve + record = {user: sub.user, problem: sub.problem} + user,problem = sub.user_id, sub.problem_id + solve = false + tries = 0 + end + if sub.points >= sub.problem.full_score + solve = true + else + tries += 1 + end + end + @struggle.sort!{|a,b| b[:tries] <=> a[:tries] } + @struggle = @struggle[0..50] + end + end diff --git a/app/views/report/_report_menu.html.haml b/app/views/report/_report_menu.html.haml --- a/app/views/report/_report_menu.html.haml +++ b/app/views/report/_report_menu.html.haml @@ -3,5 +3,5 @@ Reports %br/ = link_to '[Hall of Fame]', :action => 'problem_hof' - = link_to '[Submission]', :action => 'submission_stat' + = link_to '[Struggle]', :action => 'stuck' = link_to '[Login]', :action => 'login_stat' diff --git a/app/views/report/stuck.html.haml b/app/views/report/stuck.html.haml new file mode 100644 --- /dev/null +++ b/app/views/report/stuck.html.haml @@ -0,0 +1,17 @@ +%table.info + %thead + %tr.info-head + %th Problem + %th User + %th tries + %tbody + - @struggle.each do |s| + %tr + %td + = link_to "(#{s[:problem].name})", controller: :problems, action: :stat, id: s[:problem] + = s[:problem].full_name + %td + = link_to "(#{s[:user].login})", controller: :users, action: :profile, id: s[:user] + = s[:user].full_name + %td + = s[:tries]