fixes #2480: Report for contributors

This commit is contained in:
r888888888
2015-08-07 17:23:11 -07:00
parent 10b2523ac3
commit e37775afc2
8 changed files with 82 additions and 9 deletions

View File

@@ -6,4 +6,8 @@ class ReportsController < ApplicationController
def janitor_trials
@report = Reports::JanitorTrials.new
end
def contributors
@report = Reports::Contributors.new
end
end

View File

@@ -0,0 +1,9 @@
require 'statistics2'
module Reports
class Contributors < User
def users
::User.where("users.level >= ? and users.post_upload_count >= 250", ::User::Levels::CONTRIBUTOR).order("created_at desc").limit(50).map {|x| Reports::UserPromotions::User.new(x)}
end
end
end

View File

@@ -30,16 +30,17 @@ module Reports
def self.confidence_interval_for(user, n)
up_votes = Post.where("created_at >= ?", min_time).where(:is_deleted => false, :uploader_id => user.id).where("score >= ?", n).count
total_votes = Post.where("created_at >= ?", min_time).where(:uploader_id => user.id).count
ci_lower_bound(up_votes, total_votes, 0.95)
ci_lower_bound(up_votes, total_votes)
end
def self.deletion_confidence_interval_for(user)
deletions = Post.where(:uploader_id => user.id, :is_deleted => true).count
total = Post.where(:uploader_id => user.id).count
ci_lower_bound(deletions, total, 0.95)
def self.deletion_confidence_interval_for(user, days = nil)
date = (days || 30).days.ago
deletions = Post.where("created_at >= ?", date).where(:uploader_id => user.id, :is_deleted => true).count
total = Post.where("created_at >= ?", date).where(:uploader_id => user.id).count
ci_lower_bound(deletions, total)
end
def self.ci_lower_bound(pos, n, confidence)
def self.ci_lower_bound(pos, n, confidence = 0.95)
if n == 0
return 0
end

View File

@@ -760,6 +760,12 @@ class User < ActiveRecord::Base
end
end
module StatisticsMethods
def deletion_confidence(days = 30)
Reports::UserPromotion.deletion_confidence_interval_for(self, days)
end
end
include BanMethods
include NameMethods
include PasswordMethods
@@ -774,6 +780,7 @@ class User < ActiveRecord::Base
include ApiMethods
include CountMethods
extend SearchMethods
include StatisticsMethods
def initialize_default_image_size
self.default_image_size = "large"

View File

@@ -0,0 +1,52 @@
<div id="c-reports">
<div id="a-user-promotions">
<h1>Contributor Report</h1>
<p>Binomial proportion confidence interval for how likely a user's uploads will achieve a score of at at least n with 95% confidence within the past 30 days. Most statistics are not significant unless there are at least 300 uploads.</p>
<table width="100%" class="striped" id="sortable">
<thead>
<tr>
<th data-sort="string">User</th>
<th data-sort="int">Level</th>
<th data-sort="int">Uploads</th>
<th data-sort="int">score:3+</th>
<th data-sort="int" title="25% of uploads received this score or less">quartile score</th>
<th data-sort="int" title="50% of uploads received this score or less">median score</th>
<th data-sort="int">deletion</th>
</tr>
</thead>
<tbody>
<% @report.users.each do |user| %>
<% if user.confidence_interval_for(3) > -1 %>
<tr>
<td><%= link_to_user user.user %></td>
<td data-sort-value="<%= user.level %>"><%= user.level_string %></td>
<td><%= link_to user.post_upload_count, posts_path(:tags => "uploader:#{user.name} order:random", :limit => 200) %></td>
<td><%= number_to_percentage user.confidence_interval_for(3), :precision => 0 %></td>
<td><%= user.quartile_score %></td>
<td><%= user.median_score %></td>
<td><%= link_to number_to_percentage(user.deletion_confidence_interval, :precision => 0), posts_path(:tags => "uploader:#{user.name} status:deleted", :limit => 200) %></td>
</tr>
<% end %>
<% end %>
</tbody>
</table>
</div>
</div>
<% content_for(:page_title) do %>
Contributor 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

@@ -1,6 +1,6 @@
<div id="c-reports">
<div id="a-user-promotions">
<h1>User Promotion Confidence Intervals</h1>
<h1>User Promotion Report</h1>
<p>Binomial proportion confidence interval for how likely a user's uploads will achieve a score of at at least n with 95% confidence within the past 30 days. Most statistics are not significant unless there are at least 300 uploads.</p>
@@ -12,7 +12,6 @@
<th data-sort="int">Uploads</th>
<th data-sort="string">Age</th>
<th data-sort="int">score:3+</th>
<th data-sort="int">score:6+</th>
<th data-sort="int" title="25% of uploads received this score or less">quartile score</th>
<th data-sort="int" title="50% of uploads received this score or less">median score</th>
<th data-sort="int">deletion</th>
@@ -27,7 +26,6 @@
<td><%= link_to user.post_upload_count, posts_path(:tags => "uploader:#{user.name} order:random", :limit => 200) %></td>
<td data-sort-value="<%= user.created_at.to_formatted_s(:db) %>"><%= time_ago_in_words user.created_at %></td>
<td><%= number_to_percentage user.confidence_interval_for(3), :precision => 0 %></td>
<td><%= number_to_percentage user.confidence_interval_for(6), :precision => 0 %></td>
<td><%= user.quartile_score %></td>
<td><%= user.median_score %></td>
<td><%= link_to number_to_percentage(user.deletion_confidence_interval, :precision => 0), posts_path(:tags => "uploader:#{user.name} status:deleted", :limit => 200) %></td>

View File

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

View File

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