implement report

This commit is contained in:
r888888888
2015-06-16 16:37:57 -07:00
parent 01189017c8
commit b769f996be
6 changed files with 119 additions and 1 deletions

View File

@@ -2,4 +2,8 @@ class ReportsController < ApplicationController
def user_promotions
@report = Reports::UserPromotions.new
end
def janitor_trials
@report = Reports::JanitorTrials.new
end
end

View File

@@ -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

View File

@@ -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")

View File

@@ -0,0 +1,61 @@
<div id="c-reports">
<div id="a-user-promotions">
<h1>Janitor Trial Report</h1>
<table width="100%" class="striped" id="sortable" style="margin-bottom: 1em;">
<thead>
<tr>
<th data-sort="string">User</th>
<th data-sort="int">Approvals</th>
<th data-sort="int">Deleted</th>
<th data-sort="int" title="25% of approvals received this score or less">Quartile Score</th>
<th data-sort="int" title="50% of approvals received this score or less">Median Score</th>
<th>Explicit %</th>
<th>Questionable %</th>
<th>Safe %</th>
<th></th>
</tr>
</thead>
<tbody>
<% cache("janitor-trials-report/#{Date.today}") do %>
<% @report.janitors.each do |janitor| %>
<tr>
<td><%= link_to_user janitor.user %></td>
<td><%= link_to janitor.approval_count, posts_path(:tags => "approver:#{janitor.user.name}") %></td>
<td><%= link_to janitor.deleted_count, posts_path(:tags => "approver:#{janitor.user.name} status:deleted") %></td>
<td><%= janitor.percentile_25_score %></td>
<td><%= janitor.percentile_50_score %></td>
<td><%= number_to_percentage janitor.rating_e_percentage, :precision => 0 %></td>
<td><%= number_to_percentage janitor.rating_q_percentage, :precision => 0 %></td>
<td><%= number_to_percentage janitor.rating_s_percentage, :precision => 0 %></td>
<td>
<% 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 %>
</td>
</tr>
<% end %>
<% end %>
</tbody>
</table>
<p>All numbers shown are for the past 3 months.</p>
</div>
</div>
<% content_for(:page_title) do %>
Janitor Trial Report - <%= Danbooru.config.app_name %>
<% end %>
<%= content_for(:html_header) do %>
<%= javascript_include_tag "stupidtable" %>
<script type="text/javascript">
$(function() {
$("#sortable").stupidtable().on("aftertablesort", function() {
$("#sortable tbody tr:even").removeClass("odd").addClass("even");
$("#sortable tbody tr:odd").removeClass("even").addClass("odd");
});
});
</script>
<% end %>

View File

@@ -58,7 +58,7 @@
<ul>
<li><h1>Reports</h1></li>
<li><%= link_to("User Promotions", reports_user_promotions_path) %></li>
</ul>
<li><%= link_to("Janitor Trials", reports_janitor_trials_path) %></ul>
</section>
<section>
<ul>

View File

@@ -207,6 +207,7 @@ Rails.application.routes.draw do
resources :artist_commentary_versions, :only => [:index]
resource :related_tag, :only => [:show]
get "reports/user_promotions" => "reports#user_promotions"
get "reports/janitor_trials" => "reports#janitor_trials"
resources :saved_searches
resource :session do
collection do