diff --git a/app/controllers/graders_controller.rb b/app/controllers/graders_controller.rb --- a/app/controllers/graders_controller.rb +++ b/app/controllers/graders_controller.rb @@ -32,6 +32,7 @@ :order => 'created_at DESC') @last_test_request = TestRequest.find(:first, :order => 'created_at DESC') + @submission = Submission.order("id desc").limit(20) end def clear diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb --- a/app/controllers/main_controller.rb +++ b/app/controllers/main_controller.rb @@ -63,7 +63,8 @@ @submission.user = user @submission.language_id = 0 if (params['file']) and (params['file']!='') - @submission.source = params['file'].read + @submission.source = File.open(params['file'].path,'r:UTF-8',&:read) + @submission.source.encode!('UTF-8','UTF-8',invalid: :replace, replace: '') @submission.source_filename = params['file'].original_filename end @submission.submitted_at = Time.new.gmtime 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/controllers/users_controller.rb b/app/controllers/users_controller.rb --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -124,6 +124,7 @@ @histogram[:data][d.to_i] += 1 if d < range @summary[:count] += 1 + next unless sub.problem problem[sub.problem] = [problem[sub.problem], (sub.points >= sub.problem.full_score) ? 1 : 0].max end diff --git a/app/views/graders/list.html.haml b/app/views/graders/list.html.haml --- a/app/views/graders/list.html.haml +++ b/app/views/graders/list.html.haml @@ -24,28 +24,49 @@ = submit_tag 'Clear all data' %br{:style => 'clear:both'}/ -- if @last_task - Last task: - = link_to "#{@last_task.id}", :action => 'view', :id => @last_task.id, :type => 'Task' +%div{style: 'width:500px; float: left;'} + - if @last_task + Last task: + = link_to "#{@last_task.id}", :action => 'view', :id => @last_task.id, :type => 'Task' + + %br/ + + - if @last_test_request + Last test_request: + = link_to "#{@last_test_request.id}", :action => 'view', :id => @last_test_request.id, :type => 'TestRequest' + + %h2 Current graders + + = render :partial => 'grader_list', :locals => {:grader_list => @grader_processes} + + %h2 Stalled graders + + = render :partial => 'grader_list', :locals => {:grader_list => @stalled_processes} + + %h2 Terminated graders - %br/ + = form_for :clear, :url => {:action => 'clear_terminated'} do |f| + = submit_tag 'Clear data for terminated graders' -- if @last_test_request - Last test_request: - = link_to "#{@last_test_request.id}", :action => 'view', :id => @last_test_request.id, :type => 'TestRequest' + = render :partial => 'grader_list', :locals => {:grader_list => @terminated_processes} +%div{} + %h2 Last 20 submissions + %table.graders + %thead + %th ID + %th User + %th Problem + %th Submitted + %th Graded + %th Result + %tbody + - @submission.each do |sub| + %tr.inactive + %td= link_to sub.id, controller: 'graders' ,action: 'submission', id: sub.id + %td= sub.try(:user).try(:full_name) + %td= sub.try(:problem).try(:full_name) + %td= "#{time_ago_in_words(sub.submitted_at)} ago" + %td= "#{time_ago_in_words(sub.graded_at)} ago" + %td= sub.grader_comment -%h2 Current graders - -= render :partial => 'grader_list', :locals => {:grader_list => @grader_processes} - -%h2 Stalled graders - -= render :partial => 'grader_list', :locals => {:grader_list => @stalled_processes} - -%h2 Terminated graders - -= form_for :clear, :url => {:action => 'clear_terminated'} do |f| - = submit_tag 'Clear data for terminated graders' - -= render :partial => 'grader_list', :locals => {:grader_list => @terminated_processes} 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]