fixes #1030
This commit is contained in:
1
Gemfile
1
Gemfile
@@ -38,6 +38,7 @@ gem 'diff-lcs', :require => "diff/lcs/array"
|
|||||||
gem 'bcrypt-ruby', :require => "bcrypt"
|
gem 'bcrypt-ruby', :require => "bcrypt"
|
||||||
gem 'aws-s3', :require => "aws/s3"
|
gem 'aws-s3', :require => "aws/s3"
|
||||||
gem 'awesome_print'
|
gem 'awesome_print'
|
||||||
|
gem 'statistics2'
|
||||||
|
|
||||||
group :production do
|
group :production do
|
||||||
gem 'unicorn', :platforms => :ruby
|
gem 'unicorn', :platforms => :ruby
|
||||||
|
|||||||
@@ -179,6 +179,7 @@ GEM
|
|||||||
multi_json (~> 1.0)
|
multi_json (~> 1.0)
|
||||||
rack (~> 1.0)
|
rack (~> 1.0)
|
||||||
tilt (~> 1.1, != 1.3.0)
|
tilt (~> 1.1, != 1.3.0)
|
||||||
|
statistics2 (0.54)
|
||||||
term-ansicolor (1.1.4)
|
term-ansicolor (1.1.4)
|
||||||
therubyracer (0.11.4)
|
therubyracer (0.11.4)
|
||||||
libv8 (~> 3.11.8.12)
|
libv8 (~> 3.11.8.12)
|
||||||
@@ -241,6 +242,7 @@ DEPENDENCIES
|
|||||||
shoulda
|
shoulda
|
||||||
simple_form
|
simple_form
|
||||||
simplecov
|
simplecov
|
||||||
|
statistics2
|
||||||
term-ansicolor
|
term-ansicolor
|
||||||
therubyracer
|
therubyracer
|
||||||
timecop
|
timecop
|
||||||
|
|||||||
7
app/controllers/reports_controller.rb
Normal file
7
app/controllers/reports_controller.rb
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
class ReportsController < ApplicationController
|
||||||
|
before_filter :janitor_only
|
||||||
|
|
||||||
|
def user_promotions
|
||||||
|
@report = Reports::UserPromotions.new
|
||||||
|
end
|
||||||
|
end
|
||||||
29
app/logical/reports/user_promotions.rb
Normal file
29
app/logical/reports/user_promotions.rb
Normal 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
|
||||||
30
app/views/reports/user_promotions.html.erb
Normal file
30
app/views/reports/user_promotions.html.erb
Normal 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>
|
||||||
@@ -55,6 +55,12 @@
|
|||||||
<li><%= link_to("Listing", pools_path) %></li>
|
<li><%= link_to("Listing", pools_path) %></li>
|
||||||
<li><%= link_to("Changes", pool_versions_path) %></li>
|
<li><%= link_to("Changes", pool_versions_path) %></li>
|
||||||
</ul>
|
</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>
|
||||||
<section>
|
<section>
|
||||||
<ul>
|
<ul>
|
||||||
|
|||||||
@@ -14,8 +14,10 @@
|
|||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
<th>Posts</th>
|
<th>Posts</th>
|
||||||
<th>Deleted</th>
|
<th>Deleted</th>
|
||||||
<th>% Pos</th>
|
<% if CurrentUser.user.is_janitor? %>
|
||||||
<th>% Neg</th>
|
<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>Notes</th>
|
||||||
<th>Level</th>
|
<th>Level</th>
|
||||||
<th>Joined</th>
|
<th>Joined</th>
|
||||||
@@ -37,12 +39,9 @@
|
|||||||
</td>
|
</td>
|
||||||
<td><%= link_to user.posts.count, posts_path(:tags => "user:#{user.name}") %></td>
|
<td><%= link_to user.posts.count, posts_path(:tags => "user:#{user.name}") %></td>
|
||||||
<td><%= user.posts.deleted.count %></td>
|
<td><%= user.posts.deleted.count %></td>
|
||||||
<% if user.posts.count > 100 %>
|
<% if CurrentUser.user.is_janitor? %>
|
||||||
<td><%= number_to_percentage(100 * user.posts.positive.count.to_f / user.posts.count, :precision => 0) %></td>
|
<td><%= number_to_percentage Reports::UserPromotions.confidence_interval_for(user, 1), :precision => 0 %></td>
|
||||||
<td><%= number_to_percentage(100 * user.posts.negative.count.to_f / user.posts.count, :precision => 0) %></td>
|
<td><%= number_to_percentage Reports::UserPromotions.confidence_interval_for(user, 5), :precision => 0 %></td>
|
||||||
<% else %>
|
|
||||||
<td></td>
|
|
||||||
<td></td>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
<td><%= link_to user.note_versions.count, note_versions_path(:search => {:updater_id => user.id}) %></td>
|
<td><%= link_to user.note_versions.count, note_versions_path(:search => {:updater_id => user.id}) %></td>
|
||||||
<td><%= user.level_string %></td>
|
<td><%= user.level_string %></td>
|
||||||
|
|||||||
@@ -167,6 +167,7 @@ Danbooru::Application.routes.draw do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
resource :related_tag, :only => [:show]
|
resource :related_tag, :only => [:show]
|
||||||
|
match "reports/user_promotions" => "reports#user_promotions"
|
||||||
resource :session do
|
resource :session do
|
||||||
collection do
|
collection do
|
||||||
get :sign_out
|
get :sign_out
|
||||||
|
|||||||
Reference in New Issue
Block a user