diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index 9d0df944d..05d020588 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -2,4 +2,8 @@ class ReportsController < ApplicationController def user_promotions @report = Reports::UserPromotions.new end + + def janitor_trials + @report = Reports::JanitorTrials.new + end end diff --git a/app/logical/reports/janitor_trials.rb b/app/logical/reports/janitor_trials.rb new file mode 100644 index 000000000..772f99717 --- /dev/null +++ b/app/logical/reports/janitor_trials.rb @@ -0,0 +1,51 @@ +module Reports + class JanitorTrials + class Janitor + attr_reader :trial + + def initialize(trial) + @trial = trial + end + + def user + trial.user + end + + def since + 3.months.ago + end + + def approval_count + @approval_count ||= Post.where("approver_id = ? and created_at >= ?", user.id, since).count + end + + def deleted_count + Post.where("approver_id = ? and created_at >= ? and is_deleted = true", user.id, since).count + end + + def percentile_25_score + ActiveRecord::Base.select_value_sql("select percentile_cont(0.25) within group (order by score) from posts where created_at >= ? and approver_id = ?", since, user.id).to_i + end + + def percentile_50_score + ActiveRecord::Base.select_value_sql("select percentile_cont(0.50) within group (order by score) from posts where created_at >= ? and approver_id = ?", since, user.id).to_i + end + + def rating_e_percentage + 100 * Post.where("approver_id = ? and created_at >= ? and rating = 'e'", user.id, since).count.to_f / [approval_count, 1].max + end + + def rating_q_percentage + 100 * Post.where("approver_id = ? and created_at >= ? and rating = 'q'", user.id, since).count.to_f / [approval_count, 1].max + end + + def rating_s_percentage + 100 * Post.where("approver_id = ? and created_at >= ? and rating = 's'", user.id, since).count.to_f / [approval_count, 1].max + end + end + + def janitors + JanitorTrial.where(status: "active").to_a.map {|x| Janitor.new(x)} + end + end +end diff --git a/app/models/janitor_trial.rb b/app/models/janitor_trial.rb index c50e8997f..2b1927172 100644 --- a/app/models/janitor_trial.rb +++ b/app/models/janitor_trial.rb @@ -8,6 +8,7 @@ class JanitorTrial < ActiveRecord::Base attr_accessible :user_id, :user_name validates_inclusion_of :status, :in => %w(active inactive) before_validation :initialize_status + validates_uniqueness_of :user_id def self.search(params) q = where("status = ?", "active") diff --git a/app/views/reports/janitor_trials.html.erb b/app/views/reports/janitor_trials.html.erb new file mode 100644 index 000000000..05f228dfb --- /dev/null +++ b/app/views/reports/janitor_trials.html.erb @@ -0,0 +1,61 @@ +
+
+

Janitor Trial Report

+ + + + + + + + + + + + + + + + + <% cache("janitor-trials-report/#{Date.today}") do %> + <% @report.janitors.each do |janitor| %> + + + + + + + + + + + + <% end %> + <% end %> + +
UserApprovalsDeletedQuartile ScoreMedian ScoreExplicit %Questionable %Safe %
<%= link_to_user janitor.user %><%= link_to janitor.approval_count, posts_path(:tags => "approver:#{janitor.user.name}") %><%= link_to janitor.deleted_count, posts_path(:tags => "approver:#{janitor.user.name} status:deleted") %><%= janitor.percentile_25_score %><%= janitor.percentile_50_score %><%= number_to_percentage janitor.rating_e_percentage, :precision => 0 %><%= number_to_percentage janitor.rating_q_percentage, :precision => 0 %><%= number_to_percentage janitor.rating_s_percentage, :precision => 0 %> + <% if CurrentUser.user.is_moderator? %> + <%= link_to "Promote", promote_janitor_trial_path(janitor.trial), :method => :put, :remote => true %> + | <%= link_to "Demote", demote_janitor_trial_path(janitor.trial), :method => :put, :remote => true %> + <% end %> +
+ +

All numbers shown are for the past 3 months.

+
+
+ +<% content_for(:page_title) do %> + Janitor Trial Report - <%= Danbooru.config.app_name %> +<% end %> + +<%= content_for(:html_header) do %> + <%= javascript_include_tag "stupidtable" %> + +<% end %> \ No newline at end of file diff --git a/app/views/static/site_map.html.erb b/app/views/static/site_map.html.erb index 533283c73..48bddfa26 100644 --- a/app/views/static/site_map.html.erb +++ b/app/views/static/site_map.html.erb @@ -58,7 +58,7 @@ +
  • <%= link_to("Janitor Trials", reports_janitor_trials_path) %>