This commit is contained in:
r888888888 2013-06-11 13:24:16 -07:00
parent 05ee1077cd
commit f0b6dc9206
8 changed files with 83 additions and 8 deletions

View File

@ -38,6 +38,7 @@ gem 'diff-lcs', :require => "diff/lcs/array"
gem 'bcrypt-ruby', :require => "bcrypt"
gem 'aws-s3', :require => "aws/s3"
gem 'awesome_print'
gem 'statistics2'
group :production do
gem 'unicorn', :platforms => :ruby

View File

@ -179,6 +179,7 @@ GEM
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
statistics2 (0.54)
term-ansicolor (1.1.4)
therubyracer (0.11.4)
libv8 (~> 3.11.8.12)
@ -241,6 +242,7 @@ DEPENDENCIES
shoulda
simple_form
simplecov
statistics2
term-ansicolor
therubyracer
timecop

View File

@ -0,0 +1,7 @@
class ReportsController < ApplicationController
before_filter :janitor_only
def user_promotions
@report = Reports::UserPromotions.new
end
end

View File

@ -0,0 +1,29 @@
require 'statistics2'
module Reports
class UserPromotions
def self.confidence_interval_for(user, n)
up_votes = Post.where("created_at >= ?", min_time).where(:uploader_id => user.id).where("fav_count >= ?", 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)
end
def self.ci_lower_bound(pos, n, confidence)
if n == 0
return 0
end
z = Statistics2.pnormaldist(1-(1-confidence)/2)
phat = 1.0*pos/n
100 * (phat + z*z/(2*n) - z * Math.sqrt((phat*(1-phat)+z*z/(4*n))/n))/(1+z*z/n)
end
def self.min_time
30.days.ago
end
def users
User.joins(:posts).where("users.level < ?", User::Levels::CONTRIBUTOR).where("posts.created_at >= ? and posts.fav_count >= 1", self.class.min_time).order("users.name")
end
end
end

View File

@ -0,0 +1,30 @@
<div id="c-reports">
<div id="a-user-promotions">
<h1>User Promotion Confidence Intervals</h1>
<p>Binomial proportion confidence interval for how likely a user's uploads will achieve a fav count of at at least n with 95% confidence within the past 30 days.</p>
<table width="100%" class="striped">
<thead>
<tr>
<th>User</th>
<th>Level</th>
<th>score:1+</th>
<th>score:5+</th>
<th>score:10+</th>
</tr>
</thead>
<tbody>
<% @report.users.each do |user| %>
<tr>
<td><%= link_to user.name, user_path(user) %></td>
<td><%= user.level_string %></td>
<td><%= number_to_percentage Reports::UserPromotions.confidence_interval_for(user, 1), :precision => 0 %></td>
<td><%= number_to_percentage Reports::UserPromotions.confidence_interval_for(user, 5), :precision => 0 %></td>
<td><%= number_to_percentage Reports::UserPromotions.confidence_interval_for(user, 10), :precision => 0 %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>

View File

@ -55,6 +55,12 @@
<li><%= link_to("Listing", pools_path) %></li>
<li><%= link_to("Changes", pool_versions_path) %></li>
</ul>
<% if CurrentUser.user.is_janitor? %>
<ul>
<li><h1>Reports</h1></li>
<li><%= link_to("User Promotions", reports_user_promotions_path) %></li>
</ul>
<% end %>
</section>
<section>
<ul>

View File

@ -14,8 +14,10 @@
<th>Name</th>
<th>Posts</th>
<th>Deleted</th>
<th>% Pos</th>
<th>% Neg</th>
<% if CurrentUser.user.is_janitor? %>
<th><abbr title="1+ Favorite(s) Binonimial Confidence Interval">1+ FBCI</abbr></th>
<th><abbr title="5+ Favorites Binonimial Confidence Interval">5+ FBCI</abbr></th>
<% end %>
<th>Notes</th>
<th>Level</th>
<th>Joined</th>
@ -37,12 +39,9 @@
</td>
<td><%= link_to user.posts.count, posts_path(:tags => "user:#{user.name}") %></td>
<td><%= user.posts.deleted.count %></td>
<% if user.posts.count > 100 %>
<td><%= number_to_percentage(100 * user.posts.positive.count.to_f / user.posts.count, :precision => 0) %></td>
<td><%= number_to_percentage(100 * user.posts.negative.count.to_f / user.posts.count, :precision => 0) %></td>
<% else %>
<td></td>
<td></td>
<% if CurrentUser.user.is_janitor? %>
<td><%= number_to_percentage Reports::UserPromotions.confidence_interval_for(user, 1), :precision => 0 %></td>
<td><%= number_to_percentage Reports::UserPromotions.confidence_interval_for(user, 5), :precision => 0 %></td>
<% end %>
<td><%= link_to user.note_versions.count, note_versions_path(:search => {:updater_id => user.id}) %></td>
<td><%= user.level_string %></td>

View File

@ -167,6 +167,7 @@ Danbooru::Application.routes.draw do
end
end
resource :related_tag, :only => [:show]
match "reports/user_promotions" => "reports#user_promotions"
resource :session do
collection do
get :sign_out